mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 09:35:39 -05:00
Got the SpriteBoss to handle removing sprites again.
This commit is contained in:
parent
63758acd2e
commit
0b948d4a1e
3 changed files with 11 additions and 1 deletions
|
@ -170,7 +170,7 @@ module.exports = class SpriteBoss extends CocoClass
|
|||
sprite
|
||||
|
||||
removeSprite: (sprite) ->
|
||||
sprite.imageObject.parent.removeChild sprite.imageObject
|
||||
sprite.layer.removeCocoSprite(sprite)
|
||||
thang = sprite.thang
|
||||
delete @sprites[sprite.thang.id]
|
||||
@spriteArray.splice @spriteArray.indexOf(sprite), 1
|
||||
|
|
|
@ -42,12 +42,20 @@ module.exports = class WebGLLayer extends CocoClass
|
|||
|
||||
addCocoSprite: (cocoSprite) ->
|
||||
cocoSprite.options.resolutionFactor = @resolutionFactor
|
||||
if cocoSprite.layer
|
||||
console.warn 'CocoSprite being re-added to a layer?'
|
||||
|
||||
cocoSprite.layer = @
|
||||
cocoSprite.updateBaseScale()
|
||||
@cocoSprites.push cocoSprite
|
||||
@loadThangType(cocoSprite.thangType)
|
||||
@addDefaultActionsToRender(cocoSprite)
|
||||
@setImageObjectToCocoSprite(cocoSprite)
|
||||
# TODO: actually add it as a child
|
||||
|
||||
removeCocoSprite: (cocoSprite) ->
|
||||
cocoSprite.imageObject.parent.removeChild cocoSprite.imageObject
|
||||
@cocoSprites = _.without @cocoSprites, cocoSprite
|
||||
|
||||
loadThangType: (thangType) ->
|
||||
if not thangType.isFullyLoaded()
|
||||
|
|
|
@ -24,6 +24,7 @@ describe 'SpriteBoss', ->
|
|||
world = new World()
|
||||
world.thangs = [
|
||||
{id: 'Tree 1', spriteName: 'Tree 1', exists: true, pos: {x:4, y:0}, action: 'idle', health: 20, maxHealth: 20, rotation: Math.PI/2, acts: true }
|
||||
{id: 'Tree Will Disappear', spriteName: 'Tree 1', exists: true, pos: {x:2, y:0}, action: 'idle', health: 20, maxHealth: 20, rotation: Math.PI/2, acts: true }
|
||||
]
|
||||
world.thangMap = {}
|
||||
world.thangMap[thang.id] = thang for thang in world.thangs
|
||||
|
@ -64,6 +65,7 @@ describe 'SpriteBoss', ->
|
|||
|
||||
{id: 'Fangrider 1', spriteName: 'Ogre Fangrider', exists: true, pos: {x:8, y:8}, action: 'move', health: 20, maxHealth: 20, rotation: 0, acts: true }
|
||||
]
|
||||
_.find(world.thangs, {id: 'Tree Will Disappear'}).exists = false
|
||||
world.thangMap[thang.id] = thang for thang in world.thangs
|
||||
spriteBoss.update(true)
|
||||
defaultLayer.once 'new-spritesheet', ->
|
||||
|
|
Loading…
Reference in a new issue