phaserjs / phaser

Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
https://phaser.io
MIT License
37.12k stars 7.1k forks source link

TileSprites don't collide #263

Closed RafaelOliveira closed 10 years ago

RafaelOliveira commented 10 years ago

game.physics.collide don't work with TileSprites. The collide function don't have tilesprites in the valid objects.

alaslipknot commented 10 years ago

Yes am facing the same problem too, physics.collide doesn't work properly (i post a more descriptive topic with examples here http://www.html5gamedevs.com/topic/2538-sprite-stop-moving-weirdly/)

rezoner commented 10 years ago

Just ran into the same problem

Quick fix is (if you are using ArcadePhysics)

https://github.com/photonstorm/phaser/blob/master/src/physics/arcade/ArcadePhysics.js#L489

Change to:

 if (object1.type == Phaser.SPRITE || object1.type == Phaser.TILESPRITE)
            {
                if (object2.type == Phaser.SPRITE || object2.type == Phaser.TILESPRITE)
                {

My blind guess is that you can do this for all collisions using Sprite because in TileSprite constructor we can see:

Phaser.Sprite.call(this, game, x, y, key, frame);

photonstorm commented 10 years ago

While this will work I'd just like to add that the Sprites body will be set to the same size as the source image. I have however just pushed up a new 1.1.4 build which fixes it properly, to a degree (if you rotate or scale the tilesprite, the bounds don't update correctly yet).

totty90 commented 10 years ago

Still doesnt collide with tile sprite (:

gaurav-jhaveri commented 9 years ago

TileSprite and Sprite collision stopped working with Phaser 2.3.0 Arcade Physics. Still works with 2.2.2. Tried with the example on the website as well.

photonstorm commented 9 years ago

Already fixed in dev, please search gh issues for options.

chaping commented 9 years ago

In the version 2.3.0 it seems that TileSprite doesn't have the property physicsType,so I think we can do that to fix it temporarily:

someTileSprite.physicsType = Phaser.SPRITE; //add this property manually
someGame.physics.arcade.collide(someSprite, someTileSprite); //and collide will now work
alexandresgf commented 9 years ago

Still the same! I can't collide TileSprite and Sprite. I've try every tutorial that I found in the internet and still doesn't work. I'm using Phaser 2.4.4

Game.prototype.update = function () {
    this.game.physics.arcade.collide(this._player, this._ground);
};

this._ground is the TileSprite and this._player is the Sprite. Does anyone know if it has fixed and the solution?

Thanks!

photonstorm commented 9 years ago

Yes it's fixed: http://phaser.io/examples/v2/tile-sprites/colliding-with-tiling-sprite