1
1
package parallax ;
2
+
2
3
import haxe .xml .Access ;
4
+
3
5
using kadabra .utils .XMLUtils ;
4
6
5
7
/**
6
8
* ...
7
9
* @author Ludovic Bas - www.lugludum.com
8
10
*/
9
- class ParallaxSprite
10
- {
11
- // internal
12
-
11
+ class ParallaxSprite {
12
+ // internal
13
+
13
14
/**
14
15
* Name of the sprite
15
16
*/
16
17
public var id : String ;
18
+
17
19
/**
18
20
* PNG
19
21
*/
20
22
public var img : String ;
21
-
23
+
22
24
public var originX : Int ;
23
25
public var originY : Int ;
24
-
26
+
25
27
public var x : Int ;
26
28
public var y : Int ;
27
-
28
- // external: not used by parallax engine
29
-
29
+
30
+ // external: not used by parallax engine
30
31
public var width : Int ;
31
32
public var height : Int ;
32
-
33
+
33
34
public var offsetX : Float ;
34
35
public var offsetY : Float ;
35
-
36
+
36
37
public var scaleX : Float ;
37
38
public var scaleY : Float ;
38
-
39
+
39
40
public var rotation : Int ;
40
-
41
+
41
42
/**
42
43
* An anim should use a prefix in image attribute.
43
44
*/
44
45
public var isAnim : Bool ;
45
-
46
46
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 ) {
49
49
this .id = id ;
50
50
this .img = img ;
51
51
this .originX = x ;
@@ -61,10 +61,15 @@ class ParallaxSprite
61
61
this .offsetY = offsetY ;
62
62
this .rotation = 0 ;
63
63
}
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 ));
68
74
}
69
-
70
- }
75
+ }
0 commit comments