Skip to content

Commit 4263b42

Browse files
committed
improving handling of images by allowing setting extension instead of defaulting each time to png
1 parent 848550d commit 4263b42

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

parallax/ParallaxSprite.hx

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,51 @@
11
package parallax;
2+
23
import haxe.xml.Access;
4+
35
using kadabra.utils.XMLUtils;
46

57
/**
68
* ...
79
* @author Ludovic Bas - www.lugludum.com
810
*/
9-
class ParallaxSprite
10-
{
11-
//internal
12-
11+
class ParallaxSprite {
12+
// internal
13+
1314
/**
1415
* Name of the sprite
1516
*/
1617
public var id:String;
18+
1719
/**
1820
* PNG
1921
*/
2022
public var img:String;
21-
23+
2224
public var originX:Int;
2325
public var originY:Int;
24-
26+
2527
public var x:Int;
2628
public var y:Int;
27-
28-
//external: not used by parallax engine
29-
29+
30+
// external: not used by parallax engine
3031
public var width:Int;
3132
public var height:Int;
32-
33+
3334
public var offsetX:Float;
3435
public var offsetY:Float;
35-
36+
3637
public var scaleX:Float;
3738
public var scaleY:Float;
38-
39+
3940
public var rotation:Int;
40-
41+
4142
/**
4243
* An anim should use a prefix in image attribute.
4344
*/
4445
public var isAnim:Bool;
45-
4646

47-
public function new(id:String, img:String, x:Int, y:Int, scaleX:Float = 1, scaleY:Float = 1, width:Int = 0, height:Int = 0, offsetX:Int = 0, offsetY:Int = 0, isAnim:Bool = false)
48-
{
47+
public function new(id:String, img:String, x:Int, y:Int, scaleX:Float = 1, scaleY:Float = 1, width:Int = 0, height:Int = 0, offsetX:Int = 0,
48+
offsetY:Int = 0, isAnim:Bool = false) {
4949
this.id = id;
5050
this.img = img;
5151
this.originX = x;
@@ -61,10 +61,15 @@ class ParallaxSprite
6161
this.offsetY = offsetY;
6262
this.rotation = 0;
6363
}
64-
65-
public static function parse(xml:Access):ParallaxSprite
66-
{
67-
return new ParallaxSprite(xml.has.id ? xml.att.id : xml.att.img, xml.has.img ? xml.att.img + ".png" : "", xml.getInt("x"), xml.getInt("y"), xml.getFloat("scaleX", 1), xml.getFloat("scaleY", 1), xml.getInt("width"), xml.getInt("height"), xml.getInt("offsetX"), xml.getInt("offsetY"), xml.getBool("isAnim", false));
64+
65+
public static function parse(xml:Access):ParallaxSprite {
66+
var img:String = "";
67+
if (xml.has.img && xml.att.img != "") {
68+
img = xml.att.img;
69+
if (img.lastIndexOf('.') != img.length - 4)
70+
img += ".png";
71+
}
72+
return new ParallaxSprite(xml.has.id ? xml.att.id : xml.att.img, img, xml.getInt("x"), xml.getInt("y"), xml.getFloat("scaleX", 1),
73+
xml.getFloat("scaleY", 1), xml.getInt("width"), xml.getInt("height"), xml.getInt("offsetX"), xml.getInt("offsetY"), xml.getBool("isAnim", false));
6874
}
69-
70-
}
75+
}

0 commit comments

Comments
 (0)