Author Topic: Animated tiles, how?  (Read 2077 times)

test84

  • Key Contributor
  • *****
  • Posts: 1328
  • Karma: +0/-0
  • ت
    • View Profile
    • My personal site.
Animated tiles, how?
« on: Tue, Jul 10, 2012 »
Hi,

Does anyone has any idea on how to do animated tiles? I'm currently using DAME and I prefer to find a way to let me do that with DAME but I'm ready to get down and dirty and even hard code.

Regards.
blog, twitter, Check out my award winning game, Rot Gut:

Charlie Riot

  • Highly Super
  • Member
  • **
  • Posts: 69
  • Karma: +0/-0
    • View Profile
Re: Animated tiles, how?
« Reply #1 on: Tue, Jul 10, 2012 »
The first solutions that come to my mind are:

  • Timer-based tile swapping using setTileByIndex()
  • Sprites instead of tiles where the animation should occur

Needless to say, these are both pretty terrible and inefficient ideas, so I'm hoping you get somewhere with this!

test84

  • Key Contributor
  • *****
  • Posts: 1328
  • Karma: +0/-0
  • ت
    • View Profile
    • My personal site.
Re: Animated tiles, how?
« Reply #2 on: Wed, Jul 11, 2012 »
Thanks Charlie, I went with the second approach a while ago but collisions was acting strange when dealing with sprites acting as tiles. First approach seems better but I rather do something better, preferably with DAME.
blog, twitter, Check out my award winning game, Rot Gut:

01010111

  • Member
  • **
  • Posts: 48
  • Karma: +0/-0
    • View Profile
Re: Animated tiles, how?
« Reply #3 on: Wed, Jul 11, 2012 »
Hey! If you're using DAME, just go to Layer Options and click on the Animation tab. It's pretty straight-forward from there :)

test84

  • Key Contributor
  • *****
  • Posts: 1328
  • Karma: +0/-0
  • ت
    • View Profile
    • My personal site.
Re: Animated tiles, how?
« Reply #4 on: Wed, Jul 11, 2012 »
Thanks but does it work? Since last time I asked Charles, he was not so sure about it.
blog, twitter, Check out my award winning game, Rot Gut:

01010111

  • Member
  • **
  • Posts: 48
  • Karma: +0/-0
    • View Profile
Re: Animated tiles, how?
« Reply #5 on: Wed, Jul 11, 2012 »
Hm! I've never actually exported any maps that use it, I'll give it a go later though.

Chelnok

  • Contributor
  • ****
  • Posts: 257
  • Karma: +0/-0
    • View Profile
Re: Animated tiles, how?
« Reply #6 on: Thu, Jul 12, 2012 »
Try to modify this one:
http://forums.flixel.org/index.php/topic,5398.0.html

The function:

Code: [Select]
public function tileToFlxSprite(X:uint,Y:uint,NewTile:int=0):FlxSprite
{
var rowIndex:int = X + (Y * widthInTiles);
var rect:Rectangle = _rects[rowIndex] as Rectangle;
var pt:Point = new Point(0, 0);
var tileSprite:FlxSprite = new FlxSprite();

tileSprite.makeGraphic(_tileWidth,_tileHeight,0x00000000,true)

tileSprite.x = X * _tileWidth;
tileSprite.y = Y * _tileHeight;

if (rect != null)
tileSprite.pixels.copyPixels(_tiles, rect, pt);

tileSprite.dirty = true

if (NewTile >= 0)
setTile(X,Y,NewTile);

return tileSprite;
}

and part that needs changes:

Code: [Select]
var tileSprite:FlxSprite = new FlxSprite();

tileSprite.makeGraphic(_tileWidth,_tileHeight,0x00000000,true)

i suppose you can comment out this line:
tileSprite.makeGraphic(_tileWidth,_tileHeight,0x00000000,true)

and change:
var tileSprite:FlxSprite = new FlxSprite();

to
var tileSprite:MyAnimatedFlxSprite = new tileSprite:MyAnimatedFlxSprite();

if you got more tiles needs to be animated, check the tiletype and make if else / switch statement.. or perhaps something more flexible if you got lots of different anims.

XanderXevious

  • Contributor
  • ****
  • Posts: 360
  • Karma: +0/-0
    • View Profile
    • Deadly Alien Microbots
Re: Animated tiles, how?
« Reply #7 on: Sun, Jul 15, 2012 »
I've updated the DAME samples to show how you can setup/export animated tiles from DAME:

http://dambots.com/dame-samples