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

tilemap.removeTile etc operations don't modify plus.tileAnimations #4

Open
nemoDreamer opened this issue Dec 11, 2017 · 3 comments
Open

Comments

@nemoDreamer
Copy link

I realize this is a nice-to-have, but would make using animations more plug-and-play:

When calling this.tilemap.removeTile(x, y, layer) (or "swap", "randomize", etc...), the corresponding this.tilemap.plus.tileAnimations[*].tileLocations[*] doesn't get "corrected".

I've currently got a crude external approach:

// keys: 23-27
// spear: 28
// dagger: 29
// money: 30
if (itemsTile && itemsTile.index >= 23 && itemsTile.index <= 30) {
    this.tilemap.removeTile(
        this.player.x,
        this.player.y,
        this.itemsLayer,
    );

    // remove rotating "key" animation?
    if (itemsTile.index >= 23 && itemsTile.index <= 27) {
        const anim = this.tilemap.plus.animation.tileAnimations.find(
            animation => animation.frames[0].tileId === 22,
        );
        const ind = anim.tileLocations.findIndex(
            location =>
                location.x === this.player.x &&
                location.y === this.player.y,
        );

        anim.tileLocations.splice(ind, 1);
    }
}

But would be sweet to have removeTile patched to remove "any tileLocations at given coordinates where tileAnimations' frames contains index".

And while typing this, I just realized that I could just as well override TileMap.prototype.removeTile and make this less clunky...

Maybe I'll send along a PR 😜

@colinvella
Copy link
Owner

You seem to have a good grasp of the code already! :)

As you figured out yourself, the system builds a structure that keeps track of the animated tiles. If you are confident you can submit a PR, please do go ahead! I think we should also look at other layer modification code besides removeTile(..).

@nemoDreamer
Copy link
Author

Yup, I mentioned "swap", "randomize" etc above.

Tilemap.swap will need to check for removal and potentially add a new tileLocation (and maybe even a whole new tileAnimation... (haven't checked if you add all available ones in the tileset, regardless of whether it's used.))

Tilemap.random will only need to correct tileLocation coordinates.

But yeah, nothing trivial in those 2...
Then apart from the obvious "add", there's "copy", "paste", "replace",...

Damn...
I understand why tile animations weren't made part of the core lib yet.

Would be a whole lot easier if it were the Tile object itself that was responsible for managing its own animations...

@colinvella
Copy link
Owner

Yeah, it would have been easier if it was encapsulated in each tile somehow. Also, when I initially coded the animation system, I didn't give much thought to map modification once it was loaded. I'll tackle this in the next update.

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

2 participants