Page 29 of 92

Re: Simple Tiled Implementation - STI v0.9.3

Posted: Wed Dec 03, 2014 9:13 pm
by Karai17
I've updated STI to return "false" instead of "nil" for tile positions where there is no tile, so that should at least fix some issues.

In your particular case, I also needed to add a check for the mouse that it was within bounds of the map. Check the attached file, it has the updated STI and it works well. :)

Re: Simple Tiled Implementation - STI v0.9.2

Posted: Fri Dec 05, 2014 10:53 pm
by Karai17
ds84182 wrote: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.
I submitted a real fix to this issue.

Re: Simple Tiled Implementation - STI v0.9.4

Posted: Wed Dec 10, 2014 7:15 am
by DmL
I only read over the last few posts on the topic, so if this is addressed somewhere, I do apologize.
I have had a couple of problems with the codebase, which I have worked around, but would like some clarification on.

First:
You mentioned that you set empty tiles to false in the newest version. The older version works correctly for me but this new change leaves me with:
"map.lua : line 296 - attempt to index local 'tile' (a boolean value)"
Changing line 524 (approx.) in map.lua from:

Code: Select all

map[y][x] = false
to:

Code: Select all

map[y][x] = nil
gets it running again. Can you help me understand this?

Secondly, on line approx. 300 in the collidable layer property of the calculateObjectPosition(object, tile) method of the Map:initWorldCollision(world) function, changing:

Code: Select all

x		= x * self.width + tile.offset.x,
y		= y * self.height + tile.offset.y,
to:

Code: Select all

x		= x * tile.width + tile.offset.x,
y		= y * tile.height + tile.offset.y,
fixes a huge gap (200 pixels for a 24x24 tile) between collision objects.

Anyway, this is mostly academic. Thank you so much for your library, it has helped me tremendously, and it was easy enough to add userdata to the tiles for collision callbacks, etc, although I am just figuring all this out. : )

Re: Simple Tiled Implementation - STI v0.9.4

Posted: Thu Dec 11, 2014 6:03 pm
by Xianbaum
Hey, I'm trying to learn how to use STI and so I tried compiling with the initWorldCollision example and it gives an error.

I tried exporting from Tiled 10.2 initially and then Tiled 10.1. It is a single-layer 100x100 map, tiles 16x16, with certain tiles having the property collidable=true I'm using the latest version.

Here is the code I'm using to compile

Code: Select all

local sti = require "sti"

function love.load()
    -- Grab window size
    windowWidth = love.graphics.getWidth()
    windowHeight = love.graphics.getHeight()

    -- Set world meter size (in pixels)
    love.physics.setMeter(16)

    -- Load a map exported to Lua from Tiled
    map = sti.new("assets/maps/map1")

    -- Prepare physics world (horizontal and vertical gravity)
    world = love.physics.newWorld(0, 0)

    -- Prepare collision objects
    collision = map:initWorldCollision(world)
end
And here is the error:

Code: Select all

Error: sti/map.lua:270: bad argument #1 to 'ipairs' (table expected, got nil)
stack traceback:
	[C]: in function 'ipairs'
	sti/map.lua:270: in function 'initWorldCollision'
	main.lua:19: in function 'load'
	[string "boot.lua"]:407: in function <[string "boot.lua"]:399>
	[C]: in function 'xpcall'

Re: Simple Tiled Implementation - STI v0.9.4

Posted: Mon Dec 15, 2014 9:55 pm
by Xianbaum
Hey guys, in regards to the problem above, changing line 269 from

Code: Select all

			elseif tile.properties.collidable == "true" then
to

Code: Select all

			elseif tile.properties.collidable == "true" and self.tileInstances[gid]~=nil then
fixes this. Turns out, the reason it's nil is simply because if there a tile with the property "collidable=true" that is not placed on the map, then self.tileInstances[gid] will be nil for that tile.

Re: Simple Tiled Implementation - STI v0.9.4

Posted: Mon Dec 15, 2014 11:24 pm
by Karai17
Cool, I'll be sure to fix this soon!

Re: Simple Tiled Implementation - STI v0.9.4

Posted: Tue Dec 16, 2014 12:39 am
by CrackedP0t
Two questions: How would I draw the map to the entire screen regardless of its resolution, and how easy would implementing bump.lua alongside STI be?

Re: Simple Tiled Implementation - STI v0.9.4

Posted: Tue Dec 16, 2014 1:03 am
by Karai17
Do you mean to scale the map up or down to fit the screen, or just draw everything, ignoring culling?

I have not used bump.lua, give it a go and report back.

Re: Simple Tiled Implementation - STI v0.9.4

Posted: Tue Dec 16, 2014 1:06 am
by CrackedP0t
Scaling it to fit the screen

bump.lua integration shouldn't be too hard

Re: Simple Tiled Implementation - STI v0.9.4

Posted: Tue Dec 16, 2014 1:55 am
by Karai17
Local scale = window_height / (map.height * map.tileheight)