Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getTile after it's deleted causes error #862

Closed
elgansayer opened this issue May 30, 2014 · 3 comments
Closed

getTile after it's deleted causes error #862

elgansayer opened this issue May 30, 2014 · 3 comments

Comments

@elgansayer
Copy link

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
Copy link
Contributor

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
Copy link
Collaborator

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
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants