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

Add support for animated tiles #6

Open
fallahn opened this issue Jan 5, 2014 · 10 comments
Open

Add support for animated tiles #6

fallahn opened this issue Jan 5, 2014 · 10 comments
Milestone

Comments

@fallahn
Copy link
Owner

fallahn commented Jan 5, 2014

It would be nice to eventually add support for animated tiles. This isn't a feature in Tiled so would need some serious consideration as to how animated tiles would be designated in the editor. Overall this feature is low priority but I would love input from anyone who has ideas about how this could be done.

@Caerind
Copy link

Caerind commented Jan 6, 2014

I got an idea :

You make a Tile class and each Tile will have a std::map<std::string /Property/, std::string /Value/> mProperties

With that the user can set property for animated tile or any property he wants

The Tile are stored on a Layer (I think you can also make a class Layer) maybe on a std::vector <std::vector >

A Tile can modify the texture of itself directly by modify the VertexArray of the Layer

Then the user can do that :

For (layer.getTile ())
{
if (Tile.hasProperty ("animated") && Tile.hasProperty ("water")
{
Myvectoroftileofwater.pushback (Tile);
}
}

And then he can modify the texture each x second like that :

Void update(time)
{
tileTime = Tile.getValueOf ("animated-time").asTime ();
If (tileTime >= time)
{
Tile.switchTextureRect ();
}
}

My code is an example in pseudo code but I think you understand what I mean :)

(I'm on my phone and I'm French so the corrector automatic isnt cool at all for speaking English and write code...)

@Caerind
Copy link

Caerind commented Jan 6, 2014

Little bug for the container of Tile in Layer :

Std::vector < std::vector < Tile > >

@fallahn
Copy link
Owner Author

fallahn commented Jan 6, 2014

OK I think I get what you mean. There are already Tile and Layer structs so modifying them wouldn't be a stretch. What I really need to think about is how Tiled itself should mark a tile as being animated. When you design a map it has no direct support for animated tile maps. Perhaps it would be as simple as adding a pointer to an sf::Drawable to the tile struct and providing public access so users can attach any drawable they like (including animated sprite) which the map loader will draw when the pointer != nullPtr

@Caerind
Copy link

Caerind commented Jan 6, 2014

In the Tiled editor you can add properties to Tiles
I think that's the best way to handle animated Tiles. This method allow also so much possibilities so I think that a great feature to had.

I will see in the anothers tiled loader how they handle animated tiles

@Caerind
Copy link

Caerind commented Jan 6, 2014

Okay I've just seen the TinyXML Loader : http://code.google.com/p/tmx-parser/

It use a system like I told you with property :)

@fallahn
Copy link
Owner Author

fallahn commented Jan 6, 2014

Right, in which case there's probably not much to do. Object properties are already parsed and publicly available, so if a user wants to look for an animated property in an object and handle it in whichever way they see fit, they can.

@Kojirion
Copy link

Actually animated tiles were first implemented in Tiled around the time this issue was posted. These are stored in xml like this:

  <tile id="31">
   <animation>
    <frame tileid="31" duration="100"/>
    <frame tileid="34" duration="100"/>
   </animation>
  </tile>

@fallahn fallahn added this to the 2.0.0 milestone May 18, 2016
@fallahn
Copy link
Owner Author

fallahn commented May 19, 2016

always happy to accept pull requests on the Next branch! ;)

@dean1012
Copy link

Any news on this?

I've been able to grab the animation data like @Kojirion showed and load it into TileInfo but that's as far as I've gotten while I pick apart your code.

The first problem I'm going to have is that I don't know how to easily convert the local tile ID given in the tag to the global ID that would presumably be needed for rendering the appropriate frame.

The second problem I'm going to have is that I'm not quite sure how the rendering itself works in your code at this time. It looks like you are rendering layer sets which use MapTile but it seems that MapTile is only used in Image layers which I'm not using.

@fallahn
Copy link
Owner Author

fallahn commented Jul 17, 2017

I know it's probably not what you want to hear, but I've pretty much abandoned this in favour of tmxlite - although I see you've already forked it ;) You'll be able to get all of your animation data out of it, but will have to set up the rendering yourself.

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

No branches or pull requests

4 participants