1+ /**
2+ * @author Richard Davey <rich@photonstorm.com>
3+ * @copyright 2015 Photon Storm Ltd.
4+ * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License }
5+ */
6+
7+ /**
8+ * An Image Collection is a special tileset containing mulitple images, with no slicing into each image.
9+ *
10+ * Image Collections are normally created automatically when Tiled data is loaded.
11+ *
12+ * @class Phaser.ImageCollection
13+ * @constructor
14+ * @param {string } name - The name of the image collection in the map data.
15+ * @param {integer } firstgid - The first image index this image collection contains.
16+ * @param {integer } [width=32] - Width of widest image (in pixels).
17+ * @param {integer } [height=32] - Height of tallest image (in pixels).
18+ * @param {integer } [margin=0] - The margin around all images in the collection (in pixels).
19+ * @param {integer } [spacing=0] - The spacing between each image in the collection (in pixels).
20+ * @param {object } [properties={}] - Custom Image Collection properties.
21+ */
22+ Phaser . ImageCollection = function ( name , firstgid , width , height , margin , spacing , properties ) {
23+
24+ if ( typeof width === 'undefined' || width <= 0 ) { width = 32 ; }
25+ if ( typeof height === 'undefined' || height <= 0 ) { height = 32 ; }
26+ if ( typeof margin === 'undefined' ) { margin = 0 ; }
27+ if ( typeof spacing === 'undefined' ) { spacing = 0 ; }
28+
29+ /**
30+ * The name of the Image Collection.
31+ * @property {string } name
32+ */
33+ this . name = name ;
34+
35+ /**
36+ * The Tiled firstgid value.
37+ * This is the starting index of the first image index this Image Collection contains.
38+ * @property {integer } firstgid
39+ */
40+ this . firstgid = firstgid | 0 ;
41+
42+ /**
43+ * The width of the widest image (in pixels).
44+ * @property {integer } imageWidth
45+ * @readonly
46+ */
47+ this . imageWidth = width | 0 ;
48+
49+ /**
50+ * The height of the tallest image (in pixels).
51+ * @property {integer } imageHeight
52+ * @readonly
53+ */
54+ this . imageHeight = height | 0 ;
55+
56+ /**
57+ * The margin around the images in the collection (in pixels).
58+ * Use `setSpacing` to change.
59+ * @property {integer } imageMarge
60+ * @readonly
61+ */
62+ // Modified internally
63+ this . imageMargin = margin | 0 ;
64+
65+ /**
66+ * The spacing between each image in the collection (in pixels).
67+ * Use `setSpacing` to change.
68+ * @property {integer } imageSpacing
69+ * @readonly
70+ */
71+ this . imageSpacing = spacing | 0 ;
72+
73+ /**
74+ * Image Collection-specific properties that are typically defined in the Tiled editor.
75+ * @property {object } properties
76+ */
77+ this . properties = properties || { } ;
78+
79+ /**
80+ * The cached images that are a part of this collection.
81+ * @property {?object } images
82+ * @readonly
83+ */
84+ // Modified internally
85+ this . images = [ ] ;
86+
87+ /**
88+ * The total number of images in the image collection.
89+ * @property {integer } total
90+ * @readonly
91+ */
92+ // Modified internally
93+ this . total = 0 ;
94+ } ;
95+
96+ Phaser . ImageCollection . prototype = {
97+ /**
98+ * Returns true if and only if this image collection contains the given image index.
99+ *
100+ * @method Phaser.ImageCollection#containsImageIndex
101+ * @public
102+ * @return {boolean } True if this Image Collection contains the given index.
103+ */
104+ containsImageIndex : function ( imageIndex ) {
105+
106+ return (
107+ imageIndex >= this . firstgid &&
108+ imageIndex < ( this . firstgid + this . total )
109+ ) ;
110+
111+ } ,
112+
113+ /**
114+ * Add an image to this Image Collection.
115+ *
116+ * @method Phaser.ImageCollection#addImage
117+ * @public
118+ * @param {string } image - The the key of the image in the Image Collection and in the cache.
119+ * @param {integer } gid - The gid of the image in the Image Collection.
120+ */
121+ addImage : function ( gid , image ) {
122+ var newImage = {
123+ gid : gid ,
124+ image : image
125+ } ;
126+
127+ this . images . push ( newImage ) ;
128+ this . total ++ ;
129+ }
130+ } ;
131+
132+
133+ Phaser . ImageCollection . prototype . constructor = Phaser . ImageCollection ;
0 commit comments