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.18k stars 7.1k forks source link

getTile after it's deleted causes error #862

Closed elgansayer closed 10 years ago

elgansayer commented 10 years ago

If you use getTile, it works well,

if you then delete that tile using removeTile()

it clears the data, and then if you use getTile on the same coord's, it crashes at this line;

getTile: function (x, y, layer, nonNull) {

    if (typeof nonNull === 'undefined') { nonNull = false; }

    layer = this.getLayer(layer);

    if (x >= 0 && x < this.layers[layer].width && y >= 0 && y < this.layers[layer].height)
    {
        if (this.layers[layer].data[y][x].index === -1)

this.layers[layer].data[y][x].index ()

this.layers[layer].data[y][x] is NULL, undefined. removed;

so this would also explain why hasTile is true for tiles that are not actually there?

removeTile, and non tile's are not being set to -1 somewhere, Tomorrow's adventure time .

for now, im just going to use a check if(!this.layers[layer].data[y][x] ) { return null; };

mandarinx commented 10 years ago

I'm experiencing the same issue with Phaser 2.0.5. An alternative to removing a tile could be to set it's index to 0, but that results in this error:

Uncaught TypeError: Cannot read property '2' of undefined phaser.js:54889
Phaser.TilemapLayer.render phaser.js:54889
Phaser.TilemapLayer.postUpdate phaser.js:54540
Phaser.Group.postUpdate phaser.js:17659
Phaser.Stage.postUpdate phaser.js:16295
Phaser.Game.update phaser.js:20000
Phaser.RequestAnimationFrame.updateRAF phaser.js:35470
_onLoop phaser.js:35456
photonstorm commented 10 years ago

I've checked through this and removeTile and removeAll doesn't null anything anymore, it just creates -1 indexed tiles. I've searched the whole of Tilemap.js for = null and it's not happening anywhere, so I'm going to close this off unless you've a test case you can show me please.

mandarinx commented 10 years ago

I can confirm it works. I just tested with the Starstruck example from the phaser-examples repo (using Phaser 2.1.0). I used some of the code from the Paint tiles example to test it. My test code is in this Gist.