Page 2 of 92

Re: Simple Tiled Implementation

Posted: Tue Jan 14, 2014 9:14 pm
by Karai17
Aye, I plan to implement real-time updating of tile data.

[]

Posted: Tue Jan 14, 2014 9:18 pm
by bekey
-snip-

Re: Simple Tiled Implementation

Posted: Tue Jan 14, 2014 9:51 pm
by Daniel Eakins
Karai17 wrote:Aye, I plan to implement real-time updating of tile data.
Awesome! :D

Re: Simple Tiled Implementation

Posted: Wed Jan 15, 2014 12:17 am
by Karai17
bekey wrote:Will the library later be expanded into multiple files, or is that out of the intentional scope?
If the code grows, I'll probably abstract it into several files. Only time will tell. :)

Edit: I updated the love file to allow a bit of human input. You can now move around the map and shift your speed a bit.

Re: Simple Tiled Implementation

Posted: Wed Jan 15, 2014 1:19 am
by Fayer
Yey, thanks for this!

Re: Simple Tiled Implementation

Posted: Wed Jan 15, 2014 3:29 am
by Karai17
Did a minorish update, fixed a small bug, and updated the Tech Demo love file.

Re: Simple Tiled Implementation

Posted: Wed Jan 15, 2014 10:45 pm
by Kadoba
Karai17 wrote:You can think of the TMX file as a project file, and the exported JSON/Lua as a program-ready file. I'm not sure if Kadoba was aware that Tiled exported directly to Lua since ATL made use of XML parsing, but STI uses the native Lua spec so hopefully it will load files faster and allow more flexibility when working with the map table.
The Lua export feature wasn't implemented yet when I first created ATL or I most likely would have based it on that. Last I looked it actually tosses out some minor map data so be careful. Also it doesn't do any sort of compression so very large maps can actually take up a good chunk of memory. Those reasons, and the convenience of being able to directly load the native Tiled format is the reason I stuck with TMX (also it doesn't have to be nearly as complicated or slow as I made it).

Anyway, I'm glad to see an alternative to ATL being made so good luck with the project. :)

Re: Simple Tiled Implementation - STI v0.2.1

Posted: Wed Jan 15, 2014 10:55 pm
by Karai17
I'm glad you approve! :)

I actually talked with Bjorn (Tiled Dev) and the lua file has come a long way, holding virtually all the data that the XML holds. It is definitely the better option at this point in time.

Edit: Updated the lib/love file to include collision layer support!

Re: Simple Tiled Implementation - STI v0.3.1

Posted: Thu Jan 16, 2014 6:40 am
by Karai17
¡Double post!

This library is officially useful now (though drawing still needs an efficiency overhaul). With the new Custom Layer feature, you can add in your own data to a layer. Custom Layers also have a draw callback that you can override for your own needs. Currently you need to add a dummy layer in Tiled and then convert that layer using Map:convertToCustomLayer(layer), but I may add the ability to create a new Custom Layer in the future.

Code: Select all

local sti = require "libs.sti"

function love.load()
	map = sti.new("assets/maps/map01")
	
	local spriteLayer = map.layers["Sprite Layer"]
	map:convertToCustomLayer("Sprite Layer")
	spriteLayer.sprite = {
		x = 64,
		y = 64,
		image = love.graphics.newImage("sprite.png"),
	}
	
	function spriteLayer:update(dt)
		self.sprite.r = self.sprite.r + 90 * dt
	end

	function spriteLayer:draw()
		local x = math.floor(self.sprite.x)
		local y = math.floor(self.sprite.y)
		love.graphics.draw(self.sprite.image, x, y)
	end
end

function love.update(dt)
	local sprite = map.layers["Sprite Layer"].sprite
	local down = love.keyboard.isDown
	local speed = 64 -- pixels per second
	
	if down("w") or down("up")		then sprite.y = sprite.y - speed * dt end
	if down("s") or down("down")	then sprite.y = sprite.y + speed * dt end
	if down("a") or down("left")	then sprite.x = sprite.x - speed * dt end
	if down("d") or down("right")	then sprite.x = sprite.x + speed * dt end

	map:update(dt)
end

function love.draw()
	local sprite = map.layers["Sprite Layer"].sprite
	
	love.graphics.push()
	local tx = math.floor(-sprite.x + 384)
	local ty = math.floor(-sprite.y + 284)
	
	love.graphics.translate(tx, ty)
	map:draw()
	love.graphics.pop()
end

Re: Simple Tiled Implementation - STI v0.3.1

Posted: Thu Jan 16, 2014 3:06 pm
by pauljessup
How do you plan on handling objects? I am curious about this. When I was working on my own Tiled loader, I was just referencing them and then creating in game objects based on an ID I assigned to them. Wasn't a lot of fun to work with that way (eg: cheap hack!). I'm working on the Tiled importer for Greentea, and was just wondering on what you plan on doing/how it will compare/etc to other libs way of doing it (Lovely Tiles, etc).

Also- Bjorn is awesome, no? One of the nicest people ever. A kick ass programmer, too.

Will you be letting users draw each layer separately? Or move each layer separately? For things like parallax scrolling, etc.