forked from robterrell/cocos2d-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAtlasNode.js
77 lines (61 loc) · 1.77 KB
/
AtlasNode.js
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
'use strict'
var SpriteBatchNode = require('./BatchNode').SpriteBatchNode,
TextureAtlas = require('../TextureAtlas').TextureAtlas,
geo = require('geometry')
/**
* @class
* It knows how to render a TextureAtlas object. If you are going to
* render a TextureAtlas consider subclassing cocos.nodes.AtlasNode (or a
* subclass of cocos.nodes.AtlasNode)
*
* @memberOf cocos.nodes
* @extends cocos.nodes.SpriteBatchNode
*
* @opt {String} file Path to Atals image
* @opt {Integer} itemWidth Character width
* @opt {Integer} itemHeight Character height
* @opt {Integer} itemsToRender Quantity of items to render
*/
function AtlasNode (opts) {
AtlasNode.superclass.constructor.call(this, opts)
this.itemWidth = opts.itemWidth
this.itemHeight = opts.itemHeight
this.textureAtlas = new TextureAtlas({file: opts.file, capacity: opts.itemsToRender})
this._calculateMaxItems()
}
AtlasNode.inherit(SpriteBatchNode, /** @lends cocos.nodes.AtlasNode# */ {
/**
* Characters per row
* @type Integer
*/
itemsPerRow: 0,
/**
* Characters per column
* @type Integer
*/
itemsPerColumn: 0,
/**
* Width of a character
* @type Integer
*/
itemWidth: 0,
/**
* Height of a character
* @type Integer
*/
itemHeight: 0,
/**
* @type cocos.TextureAtlas
*/
textureAtlas: null,
updateAtlasValues: function () {
throw "cocos.nodes.AtlasNode:Abstract - updateAtlasValue not overriden"
},
_calculateMaxItems: function () {
var s = this.textureAtlas.texture.contentSize
this.itemsPerColumn = s.height / this.itemHeight
this.itemsPerRow = s.width / this.itemWidth
}
})
exports.AtlasNode = AtlasNode
// vim:et:st=4:fdm=marker:fdl=0:fdc=1