Page 1 of 1

HOW: Object-Animated Objects Tiled?. And Game Framework

Posted: Sat Aug 25, 2012 1:47 pm
by dreyk533
Hello, I'm working right now in this little game, but I have problems with creating levels and place objects animated and static from Tiled Map Editor, I can not make a connection between the program and the code of the game, as well as the creation new levels.

Well, here attached the framework if they can help me and anyone else who is starting in lua like me.

Re: HOW: Object-Animated Objects Tiled?. And Game Framework

Posted: Mon Aug 27, 2012 7:40 pm
by Kadoba
Sorry I didn't see this before.

ATL doesn't have direct support for animated tiles but it's still possible. First you need to iterate through all of the tiles and then store the ones you want to animate. Then have an updater function switch the tiles frames. You could also create an animated tile object and draw over the tiles you wish to animate.

Here's one way to do it:

Code: Select all

-- Setup
local ATL = require "AdvTiledLoader"
local map = ATL.load("mymap.tmx")

-- We'll place our animated tile information in here
local animated = {}

-- Set the next tile in the animation
animated.next = {}
animated.next[map.tiles[1]] = map.tiles[2]
animated.next[map.tiles[2]] = map.tiles[1]

-- The delay between frames and the current time accrued 
animated.delay = 0.5
animated.time = 0 

-- Find all of the animated tiles and store their location
for i, tileLayer in pairs(map.tileLayers) do
   for x, y, tile in tileLayer.tileData:iterate() do
      if tile.properties.animated then
         animated[ #animated+1 ] = {tileLayer=tileLayer, x=x, y=y}
      end
   end
end

-- Update the animations
local a, tile
function love.update(dt)
   a.time = a.time + dt
   if a.time > a.delay then
      a.time = a.time % a.delay
      -- Change each animated tile to the next tile in the animation
      for i = 1,#a do
         tile = a[i].tileLayer.tileData( a[i].x, a[i].y )
         a[i].tileLayer.tileData:set( a[i].x, a[i].y, a.next[ tile ]  or tile)
      end
   end
   map:forceRedraw()
end

-- Draw the map
function love.draw()
   map:draw()
end

Re: HOW: Object-Animated Objects Tiled?. And Game Framework

Posted: Tue Sep 11, 2012 5:16 pm
by dreyk533
I dont get it. Do you see http://projecthawkthorne.com/ ? a lua game based on the tv series community? Well, on tiled map editor you put a Object properties and placed the type, and hippy eg course it appears on the map when compiling the game. nodes in the folder the file is hippy.lua, even not as such connections fail.

Re: HOW: Object-Animated Objects Tiled?. And Game Framework

Posted: Tue Sep 11, 2012 5:38 pm
by coffee
dreyk533 wrote:I dont get it. Do you see http://projecthawkthorne.com/ ? a lua game based on the tv series community?
hola! Actually it's even more that a Lua game. It's done with LOVE framework
viewtopic.php?f=5&t=9302&p=57754

And you should trust Kadoba advices! He made Advanced Tiled Loader (http://love2d.org/forums/viewtopic.php?f=5&t=2567) used also by hawkthorne I think. You can't find greater expertise than him on the matter here.

Re: HOW: Object-Animated Objects Tiled?. And Game Framework

Posted: Tue Sep 11, 2012 9:22 pm
by Kadoba
Actually I think I got confused or something. I thought the topic was about animated tiles, not objects. Ignore what I said before.

Objects are interpreted however you want. The goal of ATL is to load data from .tmx files and provide simple rendering and a structure for you to build on. All object functionality, including animations, is up to you. So there is no one way to animate things.

Generally though these are the steps you need to take:
1. Find an animation library such as anim8 or ANAL.
2. Iterate through the ObjectLayer.objects and create your objects and animations with the data
3. Define custom layers to animate your objects

Re: HOW: Object-Animated Objects Tiled?. And Game Framework

Posted: Wed Sep 12, 2012 5:23 pm
by qaisjp
Apply two data's to it "animated" and "animset"
Then in love check those two and draw it.