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 »

map.layers is a table of all the layers in your map. What that comment is suggesting is that you cannot change the tiles in a map (yet) since they are all batched and I haven't put any code in to update batches.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
Cryogenical
Prole
Posts: 49
Joined: Mon Apr 28, 2014 5:23 pm

Re: Simple Tiled Implementation - STI v0.7.4

Post by Cryogenical »

I think I'm missing a key component to this whole thing.

I've altered the act_x and act_y variables to what you earlier on suggested, and I've tried to put in the .data array, but even when I changed the act_y and act_x to y and x in the"if collision.data[player.act_y - 1][player.act_x] ~= 1 then" statements on the love.keypressed events, nothing still happened, but it didn't crash.
Attachments
Love2D.love
(35.06 KiB) Downloaded 123 times
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 »

I don't think you're tying the player's drawn location to act_x and act_y. When you update the player's location, you need to use that new data to determine where on the screen it is actually drawn.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
Cryogenical
Prole
Posts: 49
Joined: Mon Apr 28, 2014 5:23 pm

Re: Simple Tiled Implementation - STI v0.7.4

Post by Cryogenical »

Can I bother you to explain what each part of this means?

Code: Select all

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

        return
    end
end
From what I understand, the key would be the up arrow when pressed, the if statement occurs, if coordinate [y-1][x] (ie: 7,6) is within 1 (what does this 1 represent? a "within" barrier?)
then it'll execute your player's movement (act_y - 1) (in which the 1 would have to be a bigger number, probably 32 for pixel size of tile?)
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 »

~= is "not equal to". If you check the data, you will see that all the values are either 0 or 1. 0 is the walkable space, 1 is the solid space.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
Cryogenical
Prole
Posts: 49
Joined: Mon Apr 28, 2014 5:23 pm

Re: Simple Tiled Implementation - STI v0.7.4

Post by Cryogenical »

In the map file, the tileset consists of many different numbers, not just 0s and 1s though? It's recognizing all other tiles as like 60s and 9s and 7s, etc.
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 »

getCollisionMap() grabs a copy of a layer, converts all the non-zero tiles to 1, and returns it.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
Cryogenical
Prole
Posts: 49
Joined: Mon Apr 28, 2014 5:23 pm

Re: Simple Tiled Implementation - STI v0.7.4

Post by Cryogenical »

Code: Select all

function player.update(dt)
	player.act_y = player.act_y - ((player.act_y - player.grid_y) * player.speed * dt)
	player.act_x = player.act_x - ((player.act_x - player.grid_x) * player.speed * dt)
end
Is there something wrong with this formula?
I keep rubber-banding back to the starting position whenever I try to move.
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 »

Code: Select all

function player.update(dt)
   if love.keyboard.isDown("up") then player.act_y = player.act_y - player.speed * dt end
   if love.keyboard.isDown("down") then player.act_y = player.act_y + player.speed * dt end
   if love.keyboard.isDown("left") then player.act_x = player.act_x - player.speed * dt end
   if love.keyboard.isDown("right") then player.act_x = player.act_x + player.speed * dt end
end
That will move you around at speed pixels per second
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
Cryogenical
Prole
Posts: 49
Joined: Mon Apr 28, 2014 5:23 pm

Re: Simple Tiled Implementation - STI v0.7.4

Post by Cryogenical »

While so, it's not processing any sort of collision nor moving by tile. I have a very simple platformer that I created; so I do know how to move a player freely, but I just don't fully understand how to restrict the player's movement to a grid.

Can you add me on skype or something? I really want to understand this but I think I'm just missing some key points.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest