Slick Forums

Discuss the Slick 2D Library
It is currently Thu May 23, 2013 9:08 am

All times are UTC




Post new topic Reply to topic  [ 22 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: animated tiles
PostPosted: Wed May 11, 2011 6:42 pm 
Offline

Joined: Tue Mar 01, 2011 4:34 am
Posts: 7
Hello i was just wondering if there is a way to animate tiles on a tileD map.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 11, 2011 8:18 pm 
Offline
Game Developer
User avatar

Joined: Thu Mar 03, 2011 6:22 pm
Posts: 534
yes, just implement a system for it^^
like using the objects system of Tiled with specific properties.

_________________
Current Projects:
Image Mr. Hat I
Image Vegan Vs. Zombies
Projects:
RadicalFish Engine - Build on top of Slick2D, Ideas, Bugs? Open an Issue ticket!


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 12, 2011 12:35 am 
Offline

Joined: Tue Mar 01, 2011 4:34 am
Posts: 7
cool i'm new to slick and i don't really know anything about it i tried following the tutorials but there not really what i'm looking for. How would i learn to implement this system? I could just make my own tilemaps that automatically come with animation capabilities.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 12, 2011 3:08 am 
Offline

Joined: Tue Mar 01, 2011 4:34 am
Posts: 7
i did some messing around and i made 1 tile animate by adding this code to my render method

Code:
count++;
      
      if(count == 5)
      {
         count = 0;
         if(map.getTileId(0, 11, 0) == 26)
         {
            map.setTileId(0, 11, 0, 13);
         }
         else
         {
            map.setTileId(0, 11, 0, 26);
         }
      }


This is problematic because i would need to find each tile on the map that would need to have its graphic changed.

I'm going to continue messing around with the other methods maybe see if i can use the tile properties to my advantage. But that's for tomorrow its bed time now.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 12, 2011 6:02 am 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1172
I have animated tiles in the TWL Tiled Demo.
This is done at load time by converting this tile to an animated one.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 12, 2011 8:01 am 
Offline
Game Developer
User avatar

Joined: Thu Mar 03, 2011 6:22 pm
Posts: 534
@giuseppe105

Oh well that you should avoid xD No what I want to say is, that you should use the objects system of the Tiled Map Editor^^ Set a Object, then name it (like "water"). No you add some properties like, which tiles it takes.
I did this by settinga propertie named "start" with the value x,y. and a second propertie telling me the amount of tiles the animation takes horizontal from the start point ( + some other properties but the basic system works that way).

When reading the objects I just check all objects layer (well not really, I just check one^^) and load the animations.

note that this only works on passive animations.

_________________
Current Projects:
Image Mr. Hat I
Image Vegan Vs. Zombies
Projects:
RadicalFish Engine - Build on top of Slick2D, Ideas, Bugs? Open an Issue ticket!


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 12, 2011 3:45 pm 
Offline

Joined: Tue Mar 01, 2011 4:34 am
Posts: 7
so when i make my map i create an object layer and set properties to that object then i have java read the objects properties and populate an animation. Then where ever an animation would be placed on the map i draw the animation?

This seems more of a work around to not being able to use animated tiles. I think its a better idea to make a 2d array of a animations and just make a method to populate it. useing the tiled map


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 12, 2011 3:59 pm 
Offline
Game Developer
User avatar

Joined: Thu Mar 03, 2011 6:22 pm
Posts: 534
No it's not much work... When i had the idea it was done in one hour. What you want to do is pretty much hard coded.
Slick already has a super easy to use Animation class. I just mak a new intance of an Animation an tell it the tiles it should use for the animation. Water and Waterfalls or other NONE moving objects a made this way. Anything is made via my own map editor.

_________________
Current Projects:
Image Mr. Hat I
Image Vegan Vs. Zombies
Projects:
RadicalFish Engine - Build on top of Slick2D, Ideas, Bugs? Open an Issue ticket!


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 12, 2011 7:12 pm 
Offline

Joined: Tue Mar 01, 2011 4:34 am
Posts: 7
I'm having a hard time understanding you. I don't want to ask for code without giving something in return but.

Could you show me how to set up objects and could you show me how to deal with them in java.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 12, 2011 7:57 pm 
Offline
Game Developer
User avatar

Joined: Thu Mar 03, 2011 6:22 pm
Posts: 534
Okay, well I will try... (not that could in explaining stuff)

First, make a new object layer and name it: "Animations".

Now you just add some objects, and make sure the size of them is suitable for the size of tiles. There is an option in Tiled for this (can't check this right now). Name the Objects in a typical way. e.g. water for water animations.
Now add the following Properties and values:

Code:
start:     x,y  // first tile for the animation
tilesTake: z    // number of tiles the animation takes
duration:  time // the time between each frame


So know to read the layer make an new class which extends from TiledMap.
In the constructor, you just iterate trough the object layers an search for a layer with the name: "Animations". Now you iterate trough the objects from this layer and add a new Animation for every entry, add frames like set in the Properties.

That's all, Just work with Tiled Editor and get use to it and stuff, you will see that this is a good way to add static none moving objects to the map.

I can't post src sry... Maybe my PC will return next week and i can post some code. Tho it's dirty right now xD

_________________
Current Projects:
Image Mr. Hat I
Image Vegan Vs. Zombies
Projects:
RadicalFish Engine - Build on top of Slick2D, Ideas, Bugs? Open an Issue ticket!


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 12, 2011 8:29 pm 
Offline

Joined: Tue Mar 01, 2011 4:34 am
Posts: 7
ok i will try but i still don't understand how i would display the animations where they should be on the map. And how i would get the other frames. And what is X and Y? X and Y on the map or X and Y on the tileSet?


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 19, 2011 9:28 pm 
Offline

Joined: Tue Mar 01, 2011 4:34 am
Posts: 7
I managed to get a 2 frame animation running by drawing different layers of the tiled map. But it has some problems.

1. I have to hardcode the switching of frames and would need to hardcode different animation patters.
2. I am not useing the functionality of slick 2d.

@MatthiasM

I see that you have an animated tile but how dose this help me?

I have no idea what TWL is what its used for or how to use it.

I would like to learn how to make my maps have animations in them too just as you did.

If you could help me in anyway possible that would be awsome


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 19, 2011 11:17 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1172
The animation is created by adding a property to the base tile (which is placed on the map):
Code:
<tile id="46">
  <properties>
    <property name="animated" value="speed=200,46,47,48,49,50,51"/>
  </properties>
</tile>

This property can set the animation speed (in this case 200 ms per frame) and it specified which tile images should be cycled through.
Now when a tile 46 is found inn the map it will render the tile images 46...51.

This is handled by my tiled map renderer (which uses TWL - a OpenGL GUI library).

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 21, 2011 4:03 pm 
Offline
Game Developer
User avatar

Joined: Thu Mar 03, 2011 6:22 pm
Posts: 534
So you create an object for every tile with an animation?

_________________
Current Projects:
Image Mr. Hat I
Image Vegan Vs. Zombies
Projects:
RadicalFish Engine - Build on top of Slick2D, Ideas, Bugs? Open an Issue ticket!


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 21, 2011 4:23 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1172
Every tile image is represented as an Image object - the animated ones are just a bit more complex :)

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 22 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group