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 - STI v0.3.1

Post by Karai17 »

I was thinking of just grabbing the vertices for the objects and drawing them directly. I might change this in the future but for the sake of getting them working, I'll be using the most direct method.

Bjorn is a bro. :)

You should add that idea to the issue tracker. :)
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.4.0

Post by Karai17 »

¡Double Post!

STI v0.4.0 now draws Object Layers, so all the main things are in place! The library still needs optimization, among other things, but I would suggest that it could actually be used now if you're not too worried about performance, or have smaller sized maps. Performance optimizations will come in time, and should be a drop-in replacement so feel free to get used to the library's API now.

If you find any bugs, want to request a feature, feel free to add an issue in the GitHub Issue Tracker, or post here if you do not have a GitHub account.

I updated the love file in the OP, and I will be writing documentation in the near future. For now, you can check out the Quick Example on GitHub to get started.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
Daniel Eakins
Citizen
Posts: 99
Joined: Thu Jul 18, 2013 9:14 pm
Location: France

Re: Simple Tiled Implementation - STI v0.4.0

Post by Daniel Eakins »

Nice! :D I tried simply loading and drawing a map but the tile layer appears offset (unlike the object layer):

Image

Also there is some sort of light ray projecting from the top-left corner toward the first object?
Attachments
test.love
(21.67 KiB) Downloaded 284 times
pauljessup
Party member
Posts: 355
Joined: Wed Jul 03, 2013 4:06 am

Re: Simple Tiled Implementation - STI v0.4.0

Post by pauljessup »

The library still needs optimization, among other things,
I saw that you're drawing a complete map and offsetting it - have you thought of drawing only what's visible on the screen, by limiting the tiles drawn to those that will be seen, using the love.window.getHeight and getWidth?

An example of what I use in GreenTea-


Below, the camera width and camera height are basically the love.window.getWidth and Height values. I made it so that each layer has it's own camera, with height, width, and x,y offset positions and speed. Easy to do parallax scrolling and other effects :)

Code: Select all


--get the visible area.
--x/y are the start of the visible area
--c_width, c_height are the height of the visible area.
			local c_width, c_height=math.floor(self.camera.width/self.tileset.tile_width), math.floor(self.camera.height/self.tileset.tile_height)
			local x, y=math.floor(self.camera.x/self.tileset.tile_width), math.floor(self.camera.y/self.tileset.tile_height)

--ox, oy are the original x and y, so we can get those if needed, since we will be changing local x and y in our while loop.
--ex, ey are our ending of the visible area. We take the start, add the height/width, then we add four tiles. This is our
--overdraw.
			local ox, oy, ex, ey=x, y, (x+c_width)+4, (y+c_height)+4

--this offset is for when we start halfway through a tile, or a quarter of the way through a tile, etc.
			local offsetx, offsety=self.camera.x%self.tileset.tile_width, self.camera.y%self.tileset.tile_height			

--Here's our loop.
			while(y<ey) do
				while(x<ex) do
					local tile=self:get_tile(x, y)
--This is just a draw quad. But also doing some stuff for animated tiles.
-- but the key here is the X and Y calculations.
--x is ((x-ox)*self.tileset.tile_width)-offsetx
--y is ((y-oy)*self.tileset.tile_height)-offsety
						self.tileset:draw(tile, ((x-ox)*self.tileset.tile_width)-offsetx, ((y-oy)*self.tileset.tile_height)-offsety, self.opacity)
					x=x+1
				end
				x=ox
				y=y+1
			end	
Hopefully that helps.
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.4.0

Post by Karai17 »

pauljessup wrote:
The library still needs optimization, among other things,
I saw that you're drawing a complete map and offsetting it - have you thought of drawing only what's visible on the screen, by limiting the tiles drawn to those that will be seen, using the love.window.getHeight and getWidth?

An example of what I use in GreenTea-


Below, the camera width and camera height are basically the love.window.getWidth and Height values. I made it so that each layer has it's own camera, with height, width, and x,y offset positions and speed. Easy to do parallax scrolling and other effects :)

~CODE~

Hopefully that helps.
Thanks for the advice! I haven't made any efforts to optimize drawing yet. A few things I plan are only drawing what is visible, and sprite batching. :)
Daniel Eakins wrote:Nice! :D I tried simply loading and drawing a map but the tile layer appears offset (unlike the object layer):

~IMAGE~

Also there is some sort of light ray projecting from the top-left corner toward the first object?
I found the offset bug. Change lines 83 and 84 to the following:

Code: Select all

x = -map.tilewidth,
y = -tileset.tileheight,
Tiled 0.9.1 has a bug where it doesn't add the tile offset to the lua export, so I am stuffing it in there. I was setting them to 0, instead of the right values.

As for the light casting thingy, I'm baffled by that. I'll continue to debug that though.

Edit: I've fixed the polygon bug, too. Thanks for reporting these issues! You can download the latest version from GitHub, or dissect it form the Tech Demo on the OP.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
Daniel Eakins
Citizen
Posts: 99
Joined: Thu Jul 18, 2013 9:14 pm
Location: France

Re: Simple Tiled Implementation - STI v0.4.2

Post by Daniel Eakins »

Awesome! I have now replaced ATL with this library in the project I am working on.
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.4.3

Post by Karai17 »

Cool! Thanks for your support :)

Edit: Added a small update that now takes the layer's x/y position into account when drawing. This can be useful for parallax effects.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

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

Re: Simple Tiled Implementation - STI v0.4.3

Post by pauljessup »

Awesome!

You know, in the future I might find a way to use this in the basis of Greentea. So it can be the best of both worlds, so to speak.
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.4.3

Post by Karai17 »

That would be cool! I have most of the functionality working now, so I'm going to start working on optimizations to the draw call. I'm reading the example you posted above, hopefully I can figure it all out soon. :)
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
Kingdaro
Party member
Posts: 395
Joined: Sun Jul 18, 2010 3:08 am

Re: Simple Tiled Implementation - STI v0.4.3

Post by Kingdaro »

Great library, I'll see myself using this in a future project of mine! :awesome:

You should probably link the library itself on the documentation page though, as it's possible someone will find the library through that page itself (that, and it would easily make a good central "hub" for the library, like the lua-enet page.
Post Reply

Who is online

Users browsing this forum: No registered users and 62 guests