Simple Tiled Implementation - STI v1.2.3.0

Showcase your libraries, tools and other projects that help your fellow love users.
Clean3d
Prole
Posts: 30
Joined: Fri Mar 29, 2013 4:16 pm

Re: Simple Tiled Implementation - STI v0.9.2

Post by Clean3d »

Jeeper, you will also need to call map:update(dt) in your update loop.
Clean3d's Twitter, Game, and Blog
User avatar
Jeeper
Party member
Posts: 611
Joined: Tue Mar 12, 2013 7:11 pm
Contact:

Re: Simple Tiled Implementation - STI v0.9.2

Post by Jeeper »

Clean3d wrote:Jeeper, you will also need to call map:update(dt) in your update loop.
That I do, thanks :)
Karai17 wrote:Tiled supports animated tiles natively, so do it in Tiled and it'll work in STI.
Thats quite amazing! Thanks :)
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Simple Tiled Implementation - STI v0.4.0

Post by s-ol »

Karai17 wrote:¡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.
How can I "catch" the object initialization? I use Tiled objects as "entities" for a custom collision map and spawn points, so how do I grab these and not have them rendered as polygons?

EDIT: nvm, I figured it out. I ended up just iterating over map.layers[LAYERNAME].objects and calling map:removeLayer( LAYERNAME ).

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.9.2

Post by Karai17 »

Aye, that's about the right way to do it. Glad you found the answer!

Alternatively, you can just set layer.visible to false if you want to hold onto the data.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Simple Tiled Implementation - STI v0.9.2

Post by s-ol »

Karai17 wrote:Aye, that's about the right way to do it. Glad you found the answer!

Alternatively, you can just set layer.visible to false if you want to hold onto the data.
I backed it up in a table called "olayer" so it doesn't even produce the tiniest overhad because I didn't know how "smart" layer.visible was being handled.

Well, not going to fix that, I'm in a jam and winners don't refractor :vamp:

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
ds84182
Prole
Posts: 11
Joined: Sun Jan 19, 2014 8:54 pm

Re: Simple Tiled Implementation - STI v0.9.2

Post by ds84182 »

Ohai! I think I found a problem. If I instance multiple maps the previous disappear... It's fairly easy to replicate, all you have to do is load two maps and try to draw them both.
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.9.2

Post by Karai17 »

Are you loading them into the same variable?

Also draw order and position is important. If you draw one map over top of the other, the first one is going to be hidden behind the second. You need to either draw one at a time, draw one offset to be beside the other, or draw one with some transparency.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
ds84182
Prole
Posts: 11
Joined: Sun Jan 19, 2014 8:54 pm

Re: Simple Tiled Implementation - STI v0.9.2

Post by ds84182 »

No, I managed to fix the problem though. framework.clear is called but it doesn't clear the actual canvas, instead it was clearing the screen.
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.9.2

Post by Karai17 »

Eh? That's weird. Each instance should have its own canvas and framework.clear shodul clear that canvas.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
JunoNgx
Prole
Posts: 2
Joined: Thu Jun 26, 2014 9:36 am
Location: Singapore

Re: Simple Tiled Implementation - STI v0.9.2

Post by JunoNgx »

@Karai17, I did tweet to you the other, yet somehow I'm still having serious problem access the tile id. Here's the full code of a test run of STI:

Code: Select all

local sti = require 'sti'

M = {}

function love.load()
	love.graphics.setBackgroundColor(40,40,40)
	map = sti.new("maps/tile_01")
end

function love.update(dt)
	map:update(dt)
end

function love.draw()
	map:draw()

	love.graphics.setColor(255,255,255)

	love.graphics.print(love.timer.getFPS(), 0, 00)

	love.graphics.print(love.mouse.getX(), 0, 40)
	love.graphics.print(love.mouse.getY(), 0, 60)

	local cx, cy = math.ceil(love.mouse.getX() / map.tilewidth), math.ceil(love.mouse.getY() / map.tileheight)

	love.graphics.print(tostring(cx), 0, 80)
	love.graphics.print(tostring(cy), 0, 100)

	love.graphics.print(tostring(map.layers['forelayer'].data[cx][cy].gid), 0, 200)
	love.graphics.print(tostring(map.layers['collision'].data[cx][cy].gid), 0, 200)
end

function love.keyreleased(key)
	if key == "escape" then
      love.event.quit()
   	end
end
PS: I have noted a syntax error, should have been data[cy][cx], but I don't think that's the problem here.

So far I have able to use the formula at line 24 to accurately get the tile coordinates of the cursor, yet I am unable to utilize these variables to access the tile id.

Line 29 can randomly get me the desired result with smaller tile coordinates(?) before giving me error (attempt to index a nil value) while I move my cursor to the bottom right corner of the screen. To get this to work, keep your cursor to the top left corner of the screen while running the *.love file. Yes I know this is weird, but I have tried and can confirm it.

On the other hand, line 30 has been an outright error without any excuse or exception.

I have already spent way too much time struggling with this. Is there anything I'm doing wrong?

PPS: looks like it's giving error when cursor is on a nil tile of that layer. Make sense, but this is making things difficult. Shouldn't it return 0 instead of this error?
Attachments
test-sti.love
(19.52 KiB) Downloaded 138 times
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests