mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-02-24 21:44:08 -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
|
sprite
|
||||||
|
|
||||||
removeSprite: (sprite) ->
|
removeSprite: (sprite) ->
|
||||||
sprite.imageObject.parent.removeChild sprite.imageObject
|
sprite.layer.removeCocoSprite(sprite)
|
||||||
thang = sprite.thang
|
thang = sprite.thang
|
||||||
delete @sprites[sprite.thang.id]
|
delete @sprites[sprite.thang.id]
|
||||||
@spriteArray.splice @spriteArray.indexOf(sprite), 1
|
@spriteArray.splice @spriteArray.indexOf(sprite), 1
|
||||||
|
|
|
@ -42,12 +42,20 @@ module.exports = class WebGLLayer extends CocoClass
|
||||||
|
|
||||||
addCocoSprite: (cocoSprite) ->
|
addCocoSprite: (cocoSprite) ->
|
||||||
cocoSprite.options.resolutionFactor = @resolutionFactor
|
cocoSprite.options.resolutionFactor = @resolutionFactor
|
||||||
|
if cocoSprite.layer
|
||||||
|
console.warn 'CocoSprite being re-added to a layer?'
|
||||||
|
|
||||||
|
cocoSprite.layer = @
|
||||||
cocoSprite.updateBaseScale()
|
cocoSprite.updateBaseScale()
|
||||||
@cocoSprites.push cocoSprite
|
@cocoSprites.push cocoSprite
|
||||||
@loadThangType(cocoSprite.thangType)
|
@loadThangType(cocoSprite.thangType)
|
||||||
@addDefaultActionsToRender(cocoSprite)
|
@addDefaultActionsToRender(cocoSprite)
|
||||||
@setImageObjectToCocoSprite(cocoSprite)
|
@setImageObjectToCocoSprite(cocoSprite)
|
||||||
# TODO: actually add it as a child
|
# TODO: actually add it as a child
|
||||||
|
|
||||||
|
removeCocoSprite: (cocoSprite) ->
|
||||||
|
cocoSprite.imageObject.parent.removeChild cocoSprite.imageObject
|
||||||
|
@cocoSprites = _.without @cocoSprites, cocoSprite
|
||||||
|
|
||||||
loadThangType: (thangType) ->
|
loadThangType: (thangType) ->
|
||||||
if not thangType.isFullyLoaded()
|
if not thangType.isFullyLoaded()
|
||||||
|
|
|
@ -24,6 +24,7 @@ describe 'SpriteBoss', ->
|
||||||
world = new World()
|
world = new World()
|
||||||
world.thangs = [
|
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 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 = {}
|
||||||
world.thangMap[thang.id] = thang for thang in world.thangs
|
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 }
|
{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
|
world.thangMap[thang.id] = thang for thang in world.thangs
|
||||||
spriteBoss.update(true)
|
spriteBoss.update(true)
|
||||||
defaultLayer.once 'new-spritesheet', ->
|
defaultLayer.once 'new-spritesheet', ->
|
||||||
|
|
Loading…
Reference in a new issue