Jump to content

  • Log In with Google      Sign In   
  • Create Account

Animated tiles, need some input


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 Nausea   Members   -  Reputation: 257

Like
0Likes
Like

Posted 10 January 2013 - 12:00 PM

Hey,

So I was thinking of how I would go about creating tiles which will be animated. I think I have a pretty good idea, but I just wanted to see what some more well versed people think about it.

My thought is to have a Tileframe class that will just have X/Y coordinate for where from the image the picture will be drawn. The tile class will then have a list (vector) of tileframes that animation will loop over. The map class will then have a list of tiles. The map will handle all the saving and loading of map information to and from a binary file.

Does this sound like a good approach?

For map editing will I have to have one of each available tile hardcoded into the game that a new placed tile will copy it´s information from (animation etc) ?

Would be great to have some input, and maybe some alternative ways. And if this would be bad for performance in any way or if it´s a bad idea to save so much for a pretty simple tile map.

Thanks

Edited by Nausea, 10 January 2013 - 12:01 PM.


Sponsor:

#2 Servant of the Lord   Crossbones+   -  Reputation: 19520

Like
0Likes
Like

Posted 10 January 2013 - 12:46 PM

One thing to bear in mind is that different animations have different delays between frames - you need some way to specify the delay per frame of different animations loaded in your game. Some animations even have different delays between each frame (this is less common, though, and can be ignored)


It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#3 Nausea   Members   -  Reputation: 257

Like
0Likes
Like

Posted 10 January 2013 - 12:52 PM

One thing to bear in mind is that different animations have different delays between frames - you need some way to specify the delay per frame of different animations loaded in your game. Some animations even have different delays between each frame (this is less common, though, and can be ignored)

Ye this I know already, might not do different speed between the frames. However, I will maybe try to do it just for the learning experience.



#4 Waterlimon   Crossbones+   -  Reputation: 2562

Like
0Likes
Like

Posted 10 January 2013 - 01:43 PM

I was thinking something like having a way to tell the tile renderer to update a tile (assuming you dont resend all the data every frame), causing it to ask the tile class what it currently looks like (uvs/texture) given the context (position, world, data the tile instance contains)

o3o


#5 Nausea   Members   -  Reputation: 257

Like
0Likes
Like

Posted 11 January 2013 - 05:24 AM

I was thinking something like having a way to tell the tile renderer to update a tile (assuming you dont resend all the data every frame), causing it to ask the tile class what it currently looks like (uvs/texture) given the context (position, world, data the tile instance contains)

Could you expand on what you are saying? Not very clear to a noob like me. :I



#6 BaneTrapper   Members   -  Reputation: 1199

Like
2Likes
Like

Posted 11 January 2013 - 06:54 AM

Well, not much information given.
Your using c++ i see that, any library/engines ? that would greatly narrow our approach towards the problem.

 

Use one variable for position instead of two

Also Saving X and Y for each image instead of one variable like (int pos) and use it to get image from TileSheet?

EX:

//Tile size 32x32
//Tilesheet size 128x128
 
class Tile
{
public:
    int pos = 6;
};
int TileSheetSize = Image_Tile_Sheet.getSize().x / TILE_SIZE; // This would provide size of tilesheet.x as tiles
draw(Tile_List[My_Tile_To_Draw_From_Vector].pos % Tile_Sheet_Size,
     Tile_List[My_Tile_To_Draw_From_Vector].pos / Tile_Sheet_Size)//x, y

Now if you wandering what did this do?

Let me try to explain.

 

Image was 128x128 we divided by 32 we get 4x4

00 01 02 03
04 05 06 07
08 08 10 11
12 13 14 15

We grab the 06 witch would evaluate to 2 ints (x = 3 or x = 64, y = 2 or y = 32)

 

Tip for animated tiles

Also considering the animated tiles.
Point all tiles to one pointer / reference / sprite / texture that will hold the animation image, so in process of changing animated tile you just change one tile and all using this data instead of looping true all tiles, looking for specified ones and updating them all.

 

My thought on your approach

My thought is to have a Tileframe class that will just have X/Y coordinate for where from the image the picture will be drawn. The tile class will then have a list (vector) of tileframes that animation will loop over. The map class will then have a list of tiles. The map will handle all the saving and loading of map information to and from a binary file.

Does this sound like a good approach?

Define good. Most efficient No, Able to work this way YES, Would i do it this way NO.

But have in mind that (Thinking of something on your own, creating on your own) will allow you to develop a sense of (oh this is good, oh this is bad)

 

When i was starting to program my cousin shown me how to output to console and told me to output 100 times same text onto console.

After i finished that he shown me 'for' loop (hes asshole), doing something hard way is not without it benefits, you will find creative ways of dealing with code even then, and learning to do stuff efficiently comes much on its own.

I mean who wants to write same code 10 times? make a function for it and use it 10 other places to save up to 10x in time - function creation time = profit.

 

Am pretty sure most of "Experienced" programers would be able to improve your idea / design, but experience gained from you doing it the way you thought off, priceless. Am most sure you will notice flaws and think of better ideas as you progress.

Good luck!


Current projects:
The Wanderer, 2d turn based rpg style game

www.gamedev.net/topic/641117-check-up-the-wanderer/


#7 Nausea   Members   -  Reputation: 257

Like
0Likes
Like

Posted 11 January 2013 - 11:13 AM

Tip for animated tiles
Also considering the animated tiles.
Point all tiles to one pointer / reference / sprite / texture that will hold the animation image, so in process of changing animated tile you just change one tile and all using this data instead of looping true all tiles, looking for specified ones and updating them all.
How do you mean? I will be loading a big sprite sheet into a asset manager and all the tiles will use this surface. I won't load it for every tile, just once and then point to it. Could you expand on how you mean I will update all by changing one, if I understand you correctly? Won't I have to go through all tiles and update the animated ones on every frame?

Or I what i meant was that the map class will hold what tileset (spritesheet) to use and then all the tiles will use that one.

And I will use SDL btw.

Edited by Nausea, 11 January 2013 - 11:24 AM.


#8 BaneTrapper   Members   -  Reputation: 1199

Like
0Likes
Like

Posted 11 January 2013 - 01:20 PM

If you wont have performance issues it will be fine to do it the way you intent to.

Didn't do SDL in long time...

What i meant to do is

Declaration
SDL_Surface* water_Tile; // Surface that can load images and will be base that all tiles will point to
class TileBase{
public:
int type;
SDL_Surface** img;
};
Setup
if(Tile_Base.type_of_tile == enu_water_tile)
    Tile_Base.img = &water_Tile; // I know SDL uses allot of pointers, don't remember if this would be valid so you can access what water_Tile holds
//So you could do following when drawing tiles
SDL_BlitSurface( *Tile.img , NULL, Screen , Position);
The game loop
if(1 second passed)
{
water_Tile.update_Next_Frame(); //Here just grab next frame / image for water_Tile
}

water_Tile would be updated once and all tiles therefore would be updated.

NOTE::
This may not be the valid way to use in SDL, am unsure if doing SDL_Surface** and then using memory adress of another SDL_Surface* would provide you results your striving to achieve. Just trying to provide you with concept.


Edited by BaneTrapper, 11 January 2013 - 01:25 PM.

Current projects:
The Wanderer, 2d turn based rpg style game

www.gamedev.net/topic/641117-check-up-the-wanderer/


#9 BaneTrapper   Members   -  Reputation: 1199

Like
0Likes
Like

Posted 11 January 2013 - 01:27 PM

I apologize if the code is in mess, but editing the post totally replaces each newline with space character :(


Current projects:
The Wanderer, 2d turn based rpg style game

www.gamedev.net/topic/641117-check-up-the-wanderer/


#10 Nausea   Members   -  Reputation: 257

Like
0Likes
Like

Posted 11 January 2013 - 01:46 PM

I apologize if the code is in mess, but editing the post totally replaces each newline with space character sad.png

Ok, well thank you for your input anyway. Looks like I'm not totally lost on the subject after all. Well, guess I will have to test it out and see how it performs if I can manage to get it working.

 

Again, thank you :)



#11 Nausea   Members   -  Reputation: 257

Like
0Likes
Like

Posted 12 January 2013 - 06:32 PM

OK so I've declared some classes, namely: CMap, CTile and CTileFrame.
If someone could just take a quick look at the declarations and tell me if this is a total clusterf*** or if I am on the right track.
 

class CMap {

    public:

                            CMap();

                            CMap(std::string _mapName, std::string _tileImageFile, TPUINT32 _numTilesX, TPUINT32 _numTilesY, TPUINT32 _numLayers);

                            ~CMap();


    public:

        TPBOOL TPE_CALL     m_saveMap(std::string _file);

        CMap* TPE_CALL      m_loadMap(std::string _file);

    public:

        void TPE_CALL       m_setMapName(std::string _mapName);

        std::string TPE_CALL m_getMapName();

    public:

        void TPE_CALL       m_setSizeX(TPUINT32 _sizeX);

        void TPE_CALL       m_setSizeY(TPUINT32 _sizeY);

        TPUINT32 TPE_CALL   m_getSizeX();

        TPUINT32 TPE_CALL   m_getSizeY();

    public:

        void TPE_CALL       m_setNumTilesX(TPUINT32 _tilesX);

        void TPE_CALL       m_setNumTilesY(TPUINT32 _tilesY);

        TPUINT32 TPE_CALL   m_getNumTilesX();

        TPUINT32 TPE_CALL   m_getNumTilesY();

        TPUINT32 TPE_CALL   m_getNumTiles();

    public:

        void TPE_CALL       m_setNumLayers(TPUINT32 _numLayers);

        TPUINT32 TPE_CALL   m_getNumLayers();

    public:

        void TPE_CALL       m_setCurrentLayer(TPUINT32 _layer);

        TPUINT32 TPE_CALL   m_getCurrentLayer();

    public:

        void TPE_CALL       m_addTile(TPUINT32 _posX, TPUINT32 _posY);

        void TPE_CALL       m_deleteTile(TPUINT32 _posX, TPUINT32 _posY);

    public:

        std::list    v_tileList;

    private:

        std::string         s_mapName;

        TPUINT32            ui_sizeX;

        TPUINT32            ui_sizeY;

        TPUINT32            ui_numTilesX;

        TPUINT32            ui_numTilesY;

        TPUINT32            ui_numLayers;

        TPUINT32            ui_currentLayer;

};
class CTile {

    public:

                            CTile();

                            ~CTile();

    public:

        void TPE_CALL       m_addTileFrame(TPUINT32 _imgPosX, TPUINT32 _imgPosY);

    public:

        std::string TPE_CALL m_getName();

    public:

        void TPE_CALL       m_setLayer(TPUINT32 _layer);

        TPUINT32 TPE_CALL   m_getLayer();

    public:

        void TPE_CALL       m_setPosX(TPUINT32 _posX);

        void TPE_CALL       m_setPosY(TPUINT32 _posY);

        TPUINT32 TPE_CALL   m_getPosX();

        TPUINT32 TPE_CALL   m_getPosY();

    public:

        TPUINT32 TPE_CALL   m_getType();

    public:

        TPUINT32 TPE_CALL   m_getNumFrames();

        TPUINT32 TPE_CALL   m_getCurrentFrame();

        TPUINT32 TPE_CALL   m_getFrameDelay();

        TPBOOL TPE_CALL     m_isAnimated();

    public:

        std::vector<CTileFrame> v_tileFrameList;


    private:

        std::string         s_tileName;

        TPUINT32            ui_layer;

        TPUINT32            ui_posX;

        TPUINT32            ui_posY;

        TPUINT32            ui_type;

        TPUINT32            ui_numTileFrames;

        TPUINT32            ui_currentFrame;

        TPUINT32            ui_frameDelay;

        TPBOOL              b_animated;

};
class CTileFrame {

    public:

                            CTileFrame();

                            CTileFrame(TPUINT32 _imgPosX, TPUINT32 _imgPosY);

                            ~CTileFrame();

    public:

        TPUINT32 TPE_CALL   m_getPosX();

        TPUINT32 TPE_CALL   m_getPosY();

    private:

        TPUINT32            ui_imgPosX;

        TPUINT32            ui_imgPosY;

};

 

 

The CMap class is still missing a image pointer for what tile sprite sheet to use.

The idea is to have the map store the tiles, the tiles will have a list of frames for animation.
I guess the map class will handle the animation of every frame in each tile.

Any input would be appreciated. Thanks


Edited by Nausea, 12 January 2013 - 06:37 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS