forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageCollection.js
More file actions
128 lines (110 loc) · 3.91 KB
/
Copy pathImageCollection.js
File metadata and controls
128 lines (110 loc) · 3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Note: direct port from v2
/**
* An Image Collection is a special tileset containing mulitple images, with no slicing into each image.
*
* Image Collections are normally created automatically when Tiled data is loaded.
*
* @class Phaser.ImageCollection
* @constructor
* @param {string} name - The name of the image collection in the map data.
* @param {integer} firstgid - The first image index this image collection contains.
* @param {integer} [width=32] - Width of widest image (in pixels).
* @param {integer} [height=32] - Height of tallest image (in pixels).
* @param {integer} [margin=0] - The margin around all images in the collection (in pixels).
* @param {integer} [spacing=0] - The spacing between each image in the collection (in pixels).
* @param {object} [properties={}] - Custom Image Collection properties.
*/
var Class = require('../../utils/Class');
var ImageCollection = new Class({
initialize:
function ImageCollection (name, firstgid, width, height, margin, spacing, properties)
{
if (width === undefined || width <= 0) { width = 32; }
if (height === undefined || height <= 0) { height = 32; }
if (margin === undefined) { margin = 0; }
if (spacing === undefined) { spacing = 0; }
/**
* The name of the Image Collection.
* @property {string} name
*/
this.name = name;
/**
* The Tiled firstgid value.
* This is the starting index of the first image index this Image Collection contains.
* @property {integer} firstgid
*/
this.firstgid = firstgid | 0;
/**
* The width of the widest image (in pixels).
* @property {integer} imageWidth
* @readonly
*/
this.imageWidth = width | 0;
/**
* The height of the tallest image (in pixels).
* @property {integer} imageHeight
* @readonly
*/
this.imageHeight = height | 0;
/**
* The margin around the images in the collection (in pixels).
* Use `setSpacing` to change.
* @property {integer} imageMarge
* @readonly
*/
// Modified internally
this.imageMargin = margin | 0;
/**
* The spacing between each image in the collection (in pixels).
* Use `setSpacing` to change.
* @property {integer} imageSpacing
* @readonly
*/
this.imageSpacing = spacing | 0;
/**
* Image Collection-specific properties that are typically defined in the Tiled editor.
* @property {object} properties
*/
this.properties = properties || {};
/**
* The cached images that are a part of this collection.
* @property {array} images
* @readonly
*/
// Modified internally
this.images = [];
/**
* The total number of images in the image collection.
* @property {integer} total
* @readonly
*/
// Modified internally
this.total = 0;
},
/**
* Returns true if and only if this image collection contains the given image index.
*
* @method Phaser.ImageCollection#containsImageIndex
* @param {integer} imageIndex - The image index to search for.
* @return {boolean} True if this Image Collection contains the given index.
*/
containsImageIndex: function (imageIndex)
{
return (
imageIndex >= this.firstgid && imageIndex < (this.firstgid + this.total)
);
},
/**
* Add an image to this Image Collection.
*
* @method Phaser.ImageCollection#addImage
* @param {integer} gid - The gid of the image in the Image Collection.
* @param {string} image - The the key of the image in the Image Collection and in the cache.
*/
addImage: function (gid, image)
{
this.images.push({ gid: gid, image: image });
this.total++;
}
});
module.exports = ImageCollection;