From b8371eba7bc0e29b9e4f3553150492bb0109417c Mon Sep 17 00:00:00 2001 From: YsraelJMM <39609316+ysraelJMM@users.noreply.github.com> Date: Tue, 21 Aug 2018 20:01:38 -0500 Subject: [PATCH] SVG rezise preload. svgConfig object svgConfig, contains the width and height. Change zise. --- src/loader/filetypes/SVGFile.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/loader/filetypes/SVGFile.js b/src/loader/filetypes/SVGFile.js index 605ff5a78..cc6627e03 100644 --- a/src/loader/filetypes/SVGFile.js +++ b/src/loader/filetypes/SVGFile.js @@ -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; +