74 lines
1.5 KiB
Plaintext
74 lines
1.5 KiB
Plaintext
var film2d = use('film2d')
|
|
|
|
var sprite_proto = {
|
|
type: 'sprite',
|
|
|
|
set_pos: function(x, y) {
|
|
this.pos.x = x
|
|
this.pos.y = y
|
|
return this
|
|
},
|
|
|
|
set_groups: function(groups) {
|
|
var old_groups = this.groups
|
|
this.groups = groups
|
|
film2d.reindex(this._id, old_groups, groups)
|
|
return this
|
|
},
|
|
|
|
add_group: function(group) {
|
|
if (this.groups.indexOf(group) < 0) {
|
|
this.groups.push(group)
|
|
film2d.index_group(this._id, group)
|
|
}
|
|
return this
|
|
},
|
|
|
|
remove_group: function(group) {
|
|
var idx = this.groups.indexOf(group)
|
|
if (idx >= 0) {
|
|
this.groups.splice(idx, 1)
|
|
film2d.unindex_group(this._id, group)
|
|
}
|
|
return this
|
|
},
|
|
|
|
destroy: function() {
|
|
film2d.unregister(this._id)
|
|
}
|
|
}
|
|
|
|
return function(props) {
|
|
var defaults = {
|
|
type: 'sprite',
|
|
pos: {x: 0, y: 0},
|
|
image: null,
|
|
width: 1,
|
|
height: 1,
|
|
anchor_x: 0,
|
|
anchor_y: 0,
|
|
flip: {x: false, y: false},
|
|
rotation: 0,
|
|
color: {r: 1, g: 1, b: 1, a: 1},
|
|
opacity: 1,
|
|
tint: {r: 1, g: 1, b: 1, a: 1},
|
|
filter: 'nearest',
|
|
uv: {offset: {x: 0, y: 0}, scale: {x: 1, y: 1}, rotate: 0},
|
|
plane: 'default',
|
|
layer: 0,
|
|
groups: [],
|
|
visible: true
|
|
}
|
|
|
|
var data = {}
|
|
for (var k in defaults) data[k] = defaults[k]
|
|
for (var k in props) data[k] = props[k]
|
|
|
|
// Ensure groups is array
|
|
if (!data.groups) data.groups = []
|
|
if (is_text(data.groups)) data.groups = [data.groups]
|
|
|
|
var s = meme(sprite_proto, data)
|
|
film2d.register(s)
|
|
return s
|
|
} |