mirror of
https://github.com/photonstorm/phaser
synced 2024-11-27 07:01:20 +00:00
SVG rezise preload. svgConfig object
svgConfig, contains the width and height. Change zise.
This commit is contained in:
parent
081f4188df
commit
b8371eba7b
1 changed files with 12 additions and 10 deletions
|
@ -25,7 +25,7 @@ var IsPlainObject = require('../../utils/object/IsPlainObject');
|
|||
* A single SVG File suitable for loading by the Loader.
|
||||
*
|
||||
* These are created when you use the Phaser.Loader.LoaderPlugin#svg method and are not typically created directly.
|
||||
*
|
||||
*
|
||||
* For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#svg.
|
||||
*
|
||||
* @class SVGFile
|
||||
|
@ -45,7 +45,7 @@ var SVGFile = new Class({
|
|||
|
||||
initialize:
|
||||
|
||||
function SVGFile (loader, key, url, xhrSettings)
|
||||
function SVGFile (loader, key, url, svgConfig, xhrSettings)
|
||||
{
|
||||
var extension = 'svg';
|
||||
|
||||
|
@ -55,6 +55,7 @@ var SVGFile = new Class({
|
|||
|
||||
key = GetFastValue(config, 'key');
|
||||
url = GetFastValue(config, 'url');
|
||||
svgConfig = GetFastValue(config, 'svgConfig');
|
||||
xhrSettings = GetFastValue(config, 'xhrSettings');
|
||||
extension = GetFastValue(config, 'extension', extension);
|
||||
}
|
||||
|
@ -66,6 +67,7 @@ var SVGFile = new Class({
|
|||
responseType: 'text',
|
||||
key: key,
|
||||
url: url,
|
||||
svgConfig: svgConfig,
|
||||
xhrSettings: xhrSettings
|
||||
};
|
||||
|
||||
|
@ -85,17 +87,16 @@ var SVGFile = new Class({
|
|||
|
||||
var text = this.xhrLoader.responseText;
|
||||
var svg = [ text ];
|
||||
var width = this.xhrSettings.width;
|
||||
var height = this.xhrSettings.height;
|
||||
var width = this.svgConfig.width;
|
||||
var height = this.svgConfig.height;
|
||||
|
||||
if (width && height)
|
||||
{
|
||||
var xml = null;
|
||||
var parser = new DOMParser();
|
||||
xml = parser.parseFromString(text , 'text/xml');
|
||||
xml = parser.parseFromString(text, 'text/xml');
|
||||
var svgXML = xml.getElementsByTagName('svg')[0];
|
||||
|
||||
// Si no tiene el atributo viewBox, le asigna el valor del alto y ancho predefinidos, para no tener problemas en el escalado.
|
||||
|
||||
if (svgXML.getAttribute('viewBox'))
|
||||
{
|
||||
svgXML.setAttribute('viewBox', '0 0 ' + svgXML.getAttribute('width') + ' ' + svgXML.getAttribute('height'));
|
||||
|
@ -173,7 +174,7 @@ var SVGFile = new Class({
|
|||
* Adds an SVG File, or array of SVG Files, to the current load queue.
|
||||
*
|
||||
* You can call this method from within your Scene's `preload`, along with any other files you wish to load:
|
||||
*
|
||||
*
|
||||
* ```javascript
|
||||
* function preload ()
|
||||
* {
|
||||
|
@ -195,7 +196,7 @@ var SVGFile = new Class({
|
|||
* then remove it from the Texture Manager first, before loading a new one.
|
||||
*
|
||||
* Instead of passing arguments you can pass a configuration object, such as:
|
||||
*
|
||||
*
|
||||
* ```javascript
|
||||
* this.load.svg({
|
||||
* key: 'morty',
|
||||
|
@ -206,7 +207,7 @@ var SVGFile = new Class({
|
|||
* See the documentation for `Phaser.Loader.FileTypes.SVGFileConfig` for more details.
|
||||
*
|
||||
* Once the file has finished loading you can use it as a texture for a Game Object by referencing its key:
|
||||
*
|
||||
*
|
||||
* ```javascript
|
||||
* this.load.svg('morty', 'images/Morty.svg');
|
||||
* // and later in your game ...
|
||||
|
@ -255,3 +256,4 @@ FileTypesManager.register('svg', function (key, url, xhrSettings)
|
|||
});
|
||||
|
||||
module.exports = SVGFile;
|
||||
|
||||
|
|
Loading…
Reference in a new issue