Page 28 of 92

Re: Simple Tiled Implementation - STI v0.9.2

Posted: Mon Nov 17, 2014 10:42 pm
by Clean3d
Jeeper, you will also need to call map:update(dt) in your update loop.

Re: Simple Tiled Implementation - STI v0.9.2

Posted: Mon Nov 17, 2014 11:01 pm
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 :)

Re: Simple Tiled Implementation - STI v0.4.0

Posted: Fri Nov 21, 2014 9:54 pm
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 ).

Re: Simple Tiled Implementation - STI v0.9.2

Posted: Sat Nov 22, 2014 12:52 am
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.

Re: Simple Tiled Implementation - STI v0.9.2

Posted: Sat Nov 22, 2014 6:52 pm
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:

Re: Simple Tiled Implementation - STI v0.9.2

Posted: Tue Nov 25, 2014 3:43 am
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.

Re: Simple Tiled Implementation - STI v0.9.2

Posted: Tue Nov 25, 2014 4:44 am
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.

Re: Simple Tiled Implementation - STI v0.9.2

Posted: Wed Nov 26, 2014 1:22 am
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.

Re: Simple Tiled Implementation - STI v0.9.2

Posted: Wed Nov 26, 2014 1:24 am
by Karai17
Eh? That's weird. Each instance should have its own canvas and framework.clear shodul clear that canvas.

Re: Simple Tiled Implementation - STI v0.9.2

Posted: Wed Dec 03, 2014 4:24 pm
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?