Jump to content

spritebatch sprite collision?


Elgan
 Share

Recommended Posts

Hey,

 

i have a spritebatch which spawns several fire sprites as an explosion. 

 

I want the firesprites to burn players if they hit them,

 

I have tried everything but am not able to get the sprites to collide?

 

this is a spritebatch extension

            this.enableBodyDebug = true;            this.enableBody = true;            this.physicsBodyType = Phaser.Physics.ARCADE;            
                  var sprite = this.game.add.sprite(position.x, position.y, 'bombfire', this);                                        sprite.game.physics.enable(sprite, Phaser.Physics.ARCADE);                    sprite.body.fixedRotation = true;                    sprite.body.setSize(16, 16, 0, 0)                    sprite.body.immovable = true;   this.add(sprite); //the spritebatch, add the sprite
            if (this.game.physics.arcade.collide(this, this.game.level.playersGroup)) {            }
Link to comment
Share on other sites

sprite.body.immovable I believe stops the sprite from generating collisions. Also unless you have very specific reasons for using SpriteBatch I'd use Group instead, as it'll cause fewer headaches. Once you're certain the problem isn't related to SpriteBatch (I'm not sure if it will be or not, but I think SpriteBatch is meant for rapid display of sprites at the cost of many of the features of a normal Group) you could re-implement it.

Link to comment
Share on other sites

The reason for a spritebatch is because all the fires are the same image, though they slowly animate over time. There might be a max of 27 of those fire images. The spritebatch would optimise the drawcalls.

The spritebatch i think stops the sprites update?

immovable i use with other things, and they collide still, but dont get moved, they are immovable, which i want. 

i didnt want the fire to move; I removed immovable and called each sprites update (using a new spriteclass with collides in the update method) and if i walk into the fire, its pushed..

--so collision IS working,  somewhere...BUT only on an impact and not colliding with the map, only players..*(it should blow up boxes too)

Link to comment
Share on other sites

it seems things only fire if there is velocity?

EDIT: Yes thats the reason, if i use .overlap() it works for other sprites,

 

but not the tilemap, But i can use gettile to workout if it hit a tile. 

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...