66 lines
1.0 KiB
JavaScript
66 lines
1.0 KiB
JavaScript
var sprite = {}
|
|
|
|
var graphics = use('graphics')
|
|
var render = use('render')
|
|
var draw2d = use('draw2d')
|
|
|
|
var ursprite = {}
|
|
|
|
ursprite.move = function move(mv)
|
|
{
|
|
this.rect.x += mv.x
|
|
this.rect.y += mv.y
|
|
}
|
|
|
|
ursprite.moveto = function moveto(pos)
|
|
{
|
|
this.rect.x = pos.x
|
|
this.rect.y = pos.y
|
|
}
|
|
|
|
ursprite.draw = function draw()
|
|
{
|
|
draw2d.image(this.image, this.rect, 0, this.anchor)
|
|
}
|
|
|
|
var sprites = []
|
|
|
|
sprite.create = function(image, pos, anchor = [0,0], layer = 0, props = {})
|
|
{
|
|
var sp = Object.create(ursprite)
|
|
|
|
var image = graphics.texture(image)
|
|
sp.image = image
|
|
sp.rect = {x:pos.x, y:pos.y, width: image.texture.width, height: image.texture.height}
|
|
sp.layer = layer
|
|
sp.props = props
|
|
sp.anchor = anchor
|
|
|
|
sprites.push(sp)
|
|
|
|
return sp
|
|
}
|
|
|
|
sprite.forEach = function(fn)
|
|
{
|
|
for (var sp of sprites)
|
|
fn(sp)
|
|
}
|
|
|
|
sprite.values = function()
|
|
{
|
|
return sprites.slice()
|
|
}
|
|
|
|
sprite.geometry = function()
|
|
{
|
|
return graphics.make_sprite_mesh(sprites)
|
|
}
|
|
|
|
sprite.queue = function()
|
|
{
|
|
return graphics.make_sprite_queue(sprites)
|
|
}
|
|
|
|
return sprite
|