Simple Tiled Implementation - STI v1.2.3.0

Showcase your libraries, tools and other projects that help your fellow love users.
luaiscool
Prole
Posts: 34
Joined: Mon Apr 21, 2014 11:03 pm

Re: Simple Tiled Implementation - STI v0.16.0.3

Post by luaiscool »

I used that, set up my map, Collidable = true on my object, Sprite is properly size, Nothing. Just fazes right thro it
http://xkcd.com/979/

Code: Select all

if signature = true then
    print(signaturetext)
else
    print("Error: Signature Not Found")
end
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.16.0.3

Post by Karai17 »

Make sure you're updating the physics world, too.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
luaiscool
Prole
Posts: 34
Joined: Mon Apr 21, 2014 11:03 pm

Re: Simple Tiled Implementation - STI v0.16.0.3

Post by luaiscool »

Code: Select all

-- This example uses the default Box2D (love.physics) plugin!!

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(32)

    -- Load a map exported to Lua from Tiled
    map = sti("assets/maps/map01.lua", { "box2d" })

    -- Prepare physics world with horizontal and vertical gravity
    world = love.physics.newWorld(0, 0)
	speed = 250
    -- Prepare collision objects
    map:box2d_init(world)

    -- Create a Custom Layer
    map:addCustomLayer("Sprite Layer", 3)

    -- Add data to Custom Layer
    local spriteLayer = map.layers["Sprite Layer"]
    spriteLayer.sprites = {
        player = {
            image = love.graphics.newImage("assets/sprites/player.png"),
            x = 88,
            y = 200,
            r = 0,
        }
    }

    -- Update callback for Custom Layer
    function spriteLayer:update(dt)
        for _, sprite in pairs(self.sprites) do
            if love.keyboard.isDown("right") then sprite.x = sprite.x + (speed * dt) end 
			if love.keyboard.isDown("left") then sprite.x = sprite.x - (speed * dt) end 
			if love.keyboard.isDown("down") then sprite.y = sprite.y + (speed * dt) end
			if love.keyboard.isDown("up") then sprite.y = sprite.y - (speed * dt) end
        end
    end

    -- Draw callback for Custom Layer
    function spriteLayer:draw()
        for _, sprite in pairs(self.sprites) do
            local x = math.floor(sprite.x)
            local y = math.floor(sprite.y)
            local r = sprite.r
            love.graphics.draw(sprite.image, x, y, r, 0.5, 0.5)
        end
    end
end

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

function love.draw()
    -- Translation would normally be based on a player's x/y
    local translateX = 0
    local translateY = 0

    -- Draw Range culls unnecessary tiles
    map:setDrawRange(translateX, translateY, windowWidth, windowHeight)

    -- Draw the map and all objects within
    map:draw()

    -- Draw Collision Map (useful for debugging)
    love.graphics.setColor(255, 0, 0, 255)
    map:box2d_draw()

    -- Reset color
    love.graphics.setColor(255, 255, 255, 255)
end
Isn't the world already being updated?
http://xkcd.com/979/

Code: Select all

if signature = true then
    print(signaturetext)
else
    print("Error: Signature Not Found")
end
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.16.0.3

Post by Karai17 »

Oh, yeah, that example doesn't apply physics to the player. Check out the tech demo .love file in the OP, it should have some extra code in there.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
luaiscool
Prole
Posts: 34
Joined: Mon Apr 21, 2014 11:03 pm

Re: Simple Tiled Implementation - STI v0.16.0.3

Post by luaiscool »

<snip>
Last edited by luaiscool on Wed Nov 30, 2016 9:39 pm, edited 1 time in total.
http://xkcd.com/979/

Code: Select all

if signature = true then
    print(signaturetext)
else
    print("Error: Signature Not Found")
end
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.16.0.3

Post by Karai17 »

Yeah, that tech demo uses an older version of STI.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
luaiscool
Prole
Posts: 34
Joined: Mon Apr 21, 2014 11:03 pm

Re: Simple Tiled Implementation - STI v0.16.0.3

Post by luaiscool »

Thank you so much for your help, collisions are finally working. My Sprite's collisions are off of the actual image, I am trying to change the size.

I am so sorry for asking so many questions.
http://xkcd.com/979/

Code: Select all

if signature = true then
    print(signaturetext)
else
    print("Error: Signature Not Found")
end
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.16.0.3

Post by Karai17 »

No worries :3 try starting your spirit using love.graphics.draw's offset values
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
4aiman
Party member
Posts: 262
Joined: Sat Jan 16, 2016 10:30 am

Re: Simple Tiled Implementation - STI v0.16.0.3

Post by 4aiman »

Is there any sort of upper limit for the objects number in a layer that will be drawn?

Here's my level: Image
All the spikes, ladders and chests are objects.
Note the marked ones.

However, not every object is being drawn at run-time:
Image

It's all just fine in Tiled as well as in saved map file (i.e. all objects are exported properly with no "visible=false" fields).
STI loads the level properly too: I can see just that with collision boxes being shown:
Image

When I delete several objects, some of the ones that weren't drawn before begin to.


HOWEVER:
When I separate objects in 2 different layers the game draws every other object.


I've attached a *.love file which reproduces the issue. (Just stripped everything irrelevant off the map and the game itself => the amount of code which is unnecessary to reproduce the issue is overwhelming)
Attachments
issue.love
(124.04 KiB) Downloaded 103 times
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.16.0.3

Post by Karai17 »

That's definitely bizarre. There should be no limitations to number of objects drawn in a given frame. I'll look into this.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
Post Reply

Who is online

Users browsing this forum: No registered users and 75 guests