83 lines
1.7 KiB
Plaintext
83 lines
1.7 KiB
Plaintext
// sprite.cm - Sprite node factory
|
|
//
|
|
// Returns a function that creates sprite instances via meme()
|
|
|
|
var sprite = {
|
|
type: 'sprite',
|
|
pos: null,
|
|
layer: 0,
|
|
image: null,
|
|
width: 1,
|
|
height: 1,
|
|
anchor_x: 0,
|
|
anchor_y: 0,
|
|
scale_x: 1,
|
|
scale_y: 1,
|
|
color: null,
|
|
uv_rect: null,
|
|
slice: null,
|
|
tile: null,
|
|
material: null,
|
|
opacity: 1,
|
|
|
|
// Dirty tracking
|
|
dirty: 7, // DIRTY.ALL
|
|
|
|
// Setters that mark dirty
|
|
set_pos: function(x, y) {
|
|
if (!this.pos) this.pos = {x: 0, y: 0}
|
|
if (this.pos.x == x && this.pos.y == y) return this
|
|
this.pos.x = x
|
|
this.pos.y = y
|
|
this.dirty |= 1 // TRANSFORM
|
|
return this
|
|
},
|
|
|
|
set_image: function(img) {
|
|
if (this.image == img) return this
|
|
this.image = img
|
|
this.dirty |= 2 // CONTENT
|
|
return this
|
|
},
|
|
|
|
set_size: function(w, h) {
|
|
if (this.width == w && this.height == h) return this
|
|
this.width = w
|
|
this.height = h
|
|
this.dirty |= 2 // CONTENT
|
|
return this
|
|
},
|
|
|
|
set_anchor: function(x, y) {
|
|
if (this.anchor_x == x && this.anchor_y == y) return this
|
|
this.anchor_x = x
|
|
this.anchor_y = y
|
|
this.dirty |= 1 // TRANSFORM
|
|
return this
|
|
},
|
|
|
|
set_color: function(color) {
|
|
if (!this.color) this.color = {r: 1, g: 1, b: 1, a: 1}
|
|
if (this.color.r == color.r && this.color.g == color.g && this.color.b == color.b && this.color.a == color.a) return this
|
|
this.color.r = color.r
|
|
this.color.g = color.g
|
|
this.color.b = color.b
|
|
this.color.a = a
|
|
this.dirty |= 2 // CONTENT
|
|
return this
|
|
},
|
|
|
|
set_opacity: function(o) {
|
|
if (this.opacity == o) return this
|
|
this.opacity = o
|
|
this.dirty |= 2 // CONTENT
|
|
return this
|
|
}
|
|
}
|
|
|
|
stone(sprite)
|
|
|
|
// Factory function
|
|
return function(props) {
|
|
return meme(sprite, props)
|
|
} |