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.7.4

Post by Karai17 »

Join the #love IRC channel and pm me (Karai)
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
Cucurbitacée
Prole
Posts: 47
Joined: Fri Dec 14, 2012 10:22 am
Location: Frankfurt am Main

Re: Simple Tiled Implementation - STI v0.7.4

Post by Cucurbitacée »

Hi there,

I've been using a previous version of STI in my current project and it was working fine. It was version 0.6.4, I think. As I'm getting to the point where I want to really use Tiled to design a level I decided to update to the current version.
And I have a problem with love.graphics.scale. My implementation is very basic:

Code: Select all

local sti = require "Libs.STI"
function love.load()
	...
	level.load(sti)
	...
end
function love.update(dt)
	...
	level.update(dt)
	...
end
function level.draw()
	...
	level.draw()
	...
end
function level.load(sti)
	...
	map = sti.new(maps/level1)
end
function level.update(dt)
	...
	map.update(dt)
end
function level.draw()
	map:draw()
	...
end
If I play with scale 1, it's fine, like this:
Image

But if I play with scale 2, it shows only a quarter of the screen like this:
Image

I tried to add setDrawRange(, but it didn't change anything... I'd be really glad if someone can tell me what I do wrong. :)
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.7.4

Post by Karai17 »

You need to add map:resize to love.resize. sti uses a canvas now to fix a lot of scaling issues, which needs to be resized when the screen changes.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
Cucurbitacée
Prole
Posts: 47
Joined: Fri Dec 14, 2012 10:22 am
Location: Frankfurt am Main

Re: Simple Tiled Implementation - STI v0.7.4

Post by Cucurbitacée »

Thanks a lot! :D Silly me, it was in the documentation. :oops:
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.7.4

Post by Karai17 »

Updated the documentation to be nice looking and more digestible. Whoop whoop!
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
sam
Prole
Posts: 32
Joined: Sat Nov 10, 2012 2:18 am

Re: Simple Tiled Implementation - STI v0.7.4

Post by sam »

Karai17 wrote:

Code: Select all

local sti = require "sti"

function love.load()
    map = sti.new("map")
    collision = map:getCollisionMap("Collision Layer")
    player = { x = 24, y = 36 } -- player is standing on the 24,36 block of the map
end

function love.keypressed(key, isrepeat)
    if key == "up" then
        if collision.data[player.y - 1][player.x] ~= 1 then
            -- the block above us is not collidable, so we can walk there!
            player.y = player.y - 1
        end

        return
    end

    if key == "down" then
        if collision.data[player.y + 1][player.x] ~= 1 then
            -- the block below us is not collidable, so we can walk there!
            player.y = player.y + 1
        end

        return
    end

    if key == "left" then
        if collision.data[player.y][player.x - 1] ~= 1 then
            -- the block to the left of us is not collidable, so we can walk there!
            player.x = player.x - 1
        end

        return
    end

    if key == "right" then
        if collision.data[player.y][player.x + 1] ~= 1 then
            -- the block to the right of us is not collidable, so we can walk there!
            player.x = player.x + 1
        end

        return
    end
end

i'm checking for collisions like this, but whenever i go to move my player, i get an error that looks like this -

Image

the code i'm using to set up my player looks like this -

Code: Select all

function bolo_load()
	img = love.graphics.newImage("gfx/bolo.png")
	img:setFilter("nearest")
	anim = newAnimation(img, 34, 38, 0, 0)

	x = 0
	y = 0
	spd = 90
	dir = 1

    grassmap = sti.new("maps/grass")
    grasscol = grassmap:getCollisionMap("collisions")
end

function bolo_update(dt)
	if love.keyboard.isDown("up") and grasscol.data[y - 1][x] ~= 1 then
        y = y - spd * dt
    end
	if love.keyboard.isDown("down") and grasscol.data[y + 1][x] ~= 1 then
        y = y + spd * dt
    end 
	if love.keyboard.isDown("left") and grasscol.data[y][x - 1] ~= 1 then
        x = x - spd * dt
        dir = -1
    end 
	if love.keyboard.isDown("right") and grasscol.data[y][x + 1] ~= 1 then
        x = x + spd * dt
        dir = 1
    end
end
i'm unsure why this is happening. maybe x and y are already used in the background of grasscol.data? not quite sure. any help would be appreciated!
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.7.4

Post by Karai17 »

You are having scope issues. You are using global x and y values for both you rmap indices and your movement speed.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
sam
Prole
Posts: 32
Joined: Sat Nov 10, 2012 2:18 am

Re: Simple Tiled Implementation - STI v0.7.4

Post by sam »

Karai17 wrote:You are having scope issues. You are using global x and y values for both you rmap indices and your movement speed.

Code: Select all

function bolo_load()
	img = love.graphics.newImage("gfx/bolo.png")
	img:setFilter("nearest")
	anim = newAnimation(img, 34, 38, 0, 0)

    bolo = {
    x = 40,
    y = 40
    }

	spd = 90
	dir = 1

    grassmap = sti.new("maps/grass")
    grasscol = grassmap:getCollisionMap("collisions")
end

function bolo_update(dt)
	if love.keyboard.isDown("up") and grasscol.data[bolo.y - 1][bolo.x] ~= 1 then
        bolo.y = bolo.y - spd * dt
    end
	if love.keyboard.isDown("down") and grasscol.data[bolo.y + 1][bolo.x] ~= 1 then
        bolo.y = bolo.y + spd * dt
    end 
	if love.keyboard.isDown("left") and grasscol.data[bolo.y][bolo.x - 1] ~= 1 then
        bolo.x = bolo.x - spd * dt
        dir = -1
    end 
	if love.keyboard.isDown("right") and grasscol.data[bolo.y][bolo.x + 1] ~= 1 then
        bolo.x = bolo.x + spd * dt
        dir = 1
    end
end
i've changed the variable name in case of said conflicts, but i'm still getting thrown the error. did i misunderstand what you said?
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.7.4

Post by Karai17 »

Yes. bolo.x = bolo.x + spd * dt is the problem. You are changing x and y to non-indexed numbers.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
sam
Prole
Posts: 32
Joined: Sat Nov 10, 2012 2:18 am

Re: Simple Tiled Implementation - STI v0.7.4

Post by sam »

Karai17 wrote:Yes. bolo.x = bolo.x + spd * dt is the problem. You are changing x and y to non-indexed numbers.
sorry, i'm somewhat new to lua so i'm kind of unclear on how to fix this (i came from a GML background). i have what you have in terms of movement (bolo.x = bolo.x + spd) so i'm unsure of what to do next.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests