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

Post by Karai17 »

when you draw the player, floor their position too.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
Saphiresurf
Prole
Posts: 14
Joined: Thu Mar 16, 2017 1:53 am

Re: Simple Tiled Implementation - STI v0.18.1.0

Post by Saphiresurf »

Oh my god I can't believe I missed that... that worked perfectly though thanks for the help Karai I really appreciate it!
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.18.1.0

Post by Karai17 »

:) <3
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
jonandev
Prole
Posts: 6
Joined: Sat Dec 03, 2016 2:30 am

Re: Simple Tiled Implementation - STI v0.18.1.0

Post by jonandev »

I'm having some trouble with moving around on the map I created. (Admittedly, I haven't spent much time with lua or Love, but even less with Tiled.)

Attached is a .love that shows the problem. As I translate around the map, I see the AABBs from Box2d moving around the screen. The tile layers though, don't seem to render correctly. The tiles to follow the translation, but I only see the same tiles...

I put my map into the STI Tech Demo (that uses an older version of STI), and it rendered properly. What am I missing? Any help is super appreciated.

jonandev
Attachments
sti-sandbox.love
(30.28 KiB) Downloaded 417 times
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.18.2.0

Post by Karai17 »

I'm looking into this now.
Last edited by Karai17 on Thu May 18, 2017 8:49 pm, edited 1 time in total.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.18.2.1

Post by Karai17 »

I've pushed an update that should fix this issue. the main cause of this is that I need to scale the map from whatever the user sets the scale to back to 1.0 to draw to the canvas. This fixes weird graphical glitches and tearing that can occur. However, the way I implemented this meant that translating no longer worked properly (I didn't catch this when I was testing). So to solve both problems (be able to scale and translate), I've decided that STI needs to take over love's transforms for a short time. This means that instead of calling love.graphics.scale or love.graphics.translate yourself, you just need to pass in those values to the map.draw function.

Code: Select all

local sti = require "sti"
local tx, ty, sx, sy, map

function love.load()
   map    = sti("assets/map.lua")
   tx, ty = 0, 0
   sx, sy = 1.5, 1.5
end

function love.update(dt)
   local k = love.keyboard.isDown

   if k("left")  then tx = tx - 150 * dt end
   if k("right") then tx = tx + 150 * dt end
   if k("up")    then ty = ty - 150 * dt end
   if k("down")  then ty = ty + 150 * dt end
end

function love.draw()
   map:draw(-tx, -ty, sx, sy)
end
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
jonandev
Prole
Posts: 6
Joined: Sat Dec 03, 2016 2:30 am

Re: Simple Tiled Implementation - STI v0.18.2.1

Post by jonandev »

Thank you so much for the fix and for the library in general, Karai. It's really awesome!!
User avatar
gmestanley
Prole
Posts: 2
Joined: Mon Apr 03, 2017 11:45 pm

Re: Simple Tiled Implementation - STI v0.18.2.1

Post by gmestanley »

So, I tried using STI to put the Tiled maps I made into my game, but the objects don't work. They are drawn, but the collision doesn't exist.
Here's a pic of what it looks like:
Image

Can you help me? Here's all the .lua files (there's 4 of 'em)

main.lua

Code: Select all

require "object"
require "player"
require "msgbox"
local sti = require "Simple-Tiled-Implementation-master/sti"

function love.load()
    game_map = 1

    love.window.setTitle("Elkiria")
    
    world_map01 = love.physics.newWorld(0, 0)
    map_intro = sti("data/map_intro.lua", { "box2d" })
    map_intro:box2d_init(world_map01)
    spr_player = love.graphics.newImage("data/spr_adam.png")
    fnt_system = love.graphics.newFont("data/arial.ttf", 20)
    fnt_dialogue = love.graphics.newFont("data/FreePixel.ttf", 20)    
end

function love.update(dt)
    map_intro:update(dt)
    Player:update(dt)
    Msgbox:keypressed()
end

function love.draw()
    map_intro:draw()
    map_intro:box2d_draw()
    Player:draw(spr_player, Player.xcoor, Player.ycoor)
    love.graphics.setFont(fnt_system)
    love.graphics.print(Player.xcoor, 0, 0)
    love.graphics.print(Player.ycoor, 0, 20)
    if msgbox_01 == true then
        Msgbox:draw("Hello world!", 70, 440, 660, 110)
    end
end
object.lua

Code: Select all

require "core"

Object = {}
Object.__index = Object

Object.speed = 0
Object.state = "idle"
Object.xcoor = 0
Object.ycoor = 0

return Object
player.lua

Code: Select all

require "core"
require "object"
Player = {}
Player.__index = Player

setmetatable(Object, Player)
Player.xcoor = 100
Player.ycoor = 100
Player.speed = 2

function Player:update(dt)
    if love.keyboard.isDown("down") then
        Player.state = "moving"
        Player.ycoor = Player.ycoor + Player.speed
    end
    if love.keyboard.isDown("up") then
        Player.state = "moving"
        Player.ycoor = Player.ycoor - Player.speed
    end
    if love.keyboard.isDown("left") then
        Player.state = "moving"
        Player.xcoor = Player.xcoor - Player.speed
    end
    if love.keyboard.isDown("right") then
        Player.state = "moving"
        Player.xcoor = Player.xcoor + Player.speed
    end
    if not love.keyboard.isDown("down", "up", "left", "right") then
        Player.state = "idle"
    end
end

function Player:draw(sprite, xcoor, ycoor)
    love.graphics.draw(sprite, xcoor, ycoor)
end

return Player
msgbox.lua

Code: Select all

require "core"

Msgbox = {}
Msgbox.__index = Msgbox

msgbox_01 = false

function Msgbox:keypressed()
    function love.keypressed(key)
        if key == "z" then
            msgbox_01 = true
        elseif key == "x" then
            msgbox_01 = false
        end
    end
end

function Msgbox:draw(string, x, y, width, height)
    love.graphics.setColor(0, 0, 0)
    love.graphics.rectangle("fill", x, y, width, height)
    love.graphics.setColor(255, 255, 255)
    love.graphics.print(string, x + 10, y + 10)
end
and yes, my player's sprite is a rectangle with the word "Placeholder".
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.18.2.1

Post by Karai17 »

Can you post a .love file?
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
sefan
Prole
Posts: 23
Joined: Fri Jul 31, 2015 7:03 am
Contact:

Re: Simple Tiled Implementation - STI v0.18.2.1

Post by sefan »

I'm using Box2D and rotating and flipping tiles sets the collision box in the wrong cell.
See attachment, black lines are tiles and red boxes are collision box.
Have downloaded the latest Tiled and STI with plugins.
I'm doing something wrong or so the plugin not support rotating/flipping tiles?

Edit, Fixed it. Added this to the Box2D plugin. Based on the code from init.lua file in STI.

Code: Select all

local function setFlippedGID(gid, object)
	if gid ~= nil then
		local bit31   = 2147483648
		local bit30   = 1073741824
		local bit29   = 536870912
		local flipX   = false
		local flipY   = false
		local flipD   = false
		local sx 	  = false
		local sy 	  = false
		local realgid = gid

		if realgid >= bit31 then
			realgid = realgid - bit31
			flipX   = not flipX
		end

		if realgid >= bit30 then
			realgid = realgid - bit30
			flipY   = not flipY
		end

		if realgid >= bit29 then
			realgid = realgid - bit29
			flipD   = not flipD
		end

		if flipX then
			if flipY and flipD then
				sx = true
				sy = true
			elseif flipY then
				sx = true
				sy = true
			elseif flipD then
				sx = true
			else
				sx = true
			end
		elseif flipY then
			sy = true
		end

		if sx then object.x = object.x - object.w end
		if sy then object.y = object.y - object.h end
	end
	return object
end
Attachments
TiledFlip.png
TiledFlip.png (1.3 KiB) Viewed 6965 times
Sefan.se GitHub.com Itch.io
Looking for help on graphics/music/sound effects. PM me if interested.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 3 guests