tiles and animations?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
hertzcastle
Party member
Posts: 100
Joined: Sun Jan 04, 2009 4:51 pm
Location: brighton, uk

tiles and animations?

Post by hertzcastle »

hi!
building my first tilemap as per the tutorial in the documentation section, thats fine, BUT, wouldn't it be a lot simpler from an artist point of view to load a sheet of tiles instead of individual tiles, like just in one image file?
that way when you hit save in your graphics app, every tile is updated.
i was thinking about how this idea would apply to love, and found animation:seek()
The basic idea would be to set the cell width and height to the size of your tile and then use maybe

Code: Select all

local x = 1
local y = 1
for i, v in ipairs(map) do
	tileMap:seek(i)
	love.graphics.draw(tileMap, x * wTile, y * hTile)
	x = x + 1
	
	if x > (wMap) then
	x = 0 
	y = y + 1
	end
end
where map is a numeric table, tileMap is the animation, wTile is the width of the tile, hTile is the height.
Any ideas why this doesn't work?
x
User avatar
hertzcastle
Party member
Posts: 100
Joined: Sun Jan 04, 2009 4:51 pm
Location: brighton, uk

Re: tiles and animations?

Post by hertzcastle »

sorry, got it wrong, need to iterate like this:

Code: Select all

for y = 1, hMap do
	for x = 1, wMap do
		tile = map[y][x]
		tileMap:seek(tile)
		love.graphics.draw(tileMap, x * wTile, y * wTile)
	end
end
again, i'm simple, get confused, sorry.x
User avatar
Avalon
Prole
Posts: 49
Joined: Sat Sep 12, 2009 11:37 am

Re: tiles and animations?

Post by Avalon »

In 0.5.0, this can be achieved with the draws function.

http://love2d.org/docs/love_graphics_draws_1.html

Or are you playing with the 0.6.0 builds? :)

--

When I was working with 0.5.0, the editor I created saved tilemaps in the following format.
map = {}

map.tileset = love.graphics.newImage("Graphics/Tilesets/001.png", love.image_optimize)

map.tiles = {}

map.tiles.background = {}

-- // X-Pos, Y-Pos, X-Offset, Y-Offset, Width, Height, Passable (0/1).
map.tiles.background[1] = {16, 16, 0, 0, 32, 32, 0}
map.tiles.background[2] = {48, 16, 0, 0, 32, 32, 0}
map.tiles.background[3] = {80, 16, 0, 0, 32, 32, 0}
map.tiles.background[4] = {112, 16, 0, 0, 32, 32, 0}
The background layer was then drawn as follows.
-- Draw background tile layer.
for i,v in ipairs(map.tiles.background) do
love.graphics.draws(map.tileset, map.tiles.background[1], map.tiles.background[2], map.tiles.background[3], map.tiles.background[4], map.tiles.background[5], map.tiles.background[6])
if debug.grid == 1 then
if map.tiles.background[7] == 0 then
-- Passable tiles.
love.graphics.setColor(255, 255, 255)
love.graphics.rectangle(1, map.tiles.background[1]-16, map.tiles.background[2]-16, 32, 32)
elseif map.tiles.background[7] == 1 then
-- Impassable tiles.
love.graphics.setColor(255, 0, 0)
love.graphics.rectangle(1, map.tiles.background[i][1]-16, map.tiles.background[i][2]-16, 32, 32)
love.graphics.setColor(255, 255, 255)
end
end
end


Whilst this is quite possibly horribly inefficient, I was getting 700FPS on a full map with vsync disabled. Additional tile layers posed close to zero performance issues.
User avatar
hertzcastle
Party member
Posts: 100
Joined: Sun Jan 04, 2009 4:51 pm
Location: brighton, uk

Re: tiles and animations?

Post by hertzcastle »

omg i missed that! should have known love would make it even easier :nyu:
thanks avalon!
User avatar
hertzcastle
Party member
Posts: 100
Joined: Sun Jan 04, 2009 4:51 pm
Location: brighton, uk

Re: tiles and animations?

Post by hertzcastle »

by the way, which editor were you using? ive tried Tiled but i cant seem to save as Lua. im guessing theres a plugin somewhere...?x
User avatar
Avalon
Prole
Posts: 49
Joined: Sat Sep 12, 2009 11:37 am

Re: tiles and animations?

Post by Avalon »

hertzcastle wrote:by the way, which editor were you using? ive tried Tiled but i cant seem to save as Lua. im guessing theres a plugin somewhere...?x
avalonmap.exe :P.

A tool I wrote to save it in the necessary format. :)
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 70 guests