Simple Tiled Implementation - STI v1.2.3.0

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation

Post by Karai17 »

Aye, I plan to implement real-time updating of tile data.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
bekey
Party member
Posts: 255
Joined: Tue Sep 03, 2013 6:27 pm

[]

Post by bekey »

-snip-
Last edited by bekey on Fri Jan 24, 2014 2:20 am, edited 7 times in total.
User avatar
Daniel Eakins
Citizen
Posts: 99
Joined: Thu Jul 18, 2013 9:14 pm
Location: France

Re: Simple Tiled Implementation

Post by Daniel Eakins »

Karai17 wrote:Aye, I plan to implement real-time updating of tile data.
Awesome! :D
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation

Post 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.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
Fayer
Prole
Posts: 26
Joined: Tue Jan 07, 2014 5:48 pm
Location: Mexico City

Re: Simple Tiled Implementation

Post by Fayer »

Yey, thanks for this!
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation

Post by Karai17 »

Did a minorish update, fixed a small bug, and updated the Tech Demo love file.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
Kadoba
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Re: Simple Tiled Implementation

Post 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. :)
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.2.1

Post 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!
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.3.1

Post 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
Last edited by Karai17 on Thu Jan 16, 2014 8:57 pm, edited 1 time in total.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
pauljessup
Party member
Posts: 356
Joined: Wed Jul 03, 2013 4:06 am

Re: Simple Tiled Implementation - STI v0.3.1

Post 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.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest