Page 16 of 92

Re: Simple Tiled Implementation - STI v0.7.4

Posted: Fri May 16, 2014 8:21 pm
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.

Re: Simple Tiled Implementation - STI v0.7.4

Posted: Sat May 17, 2014 1:43 pm
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.

Re: Simple Tiled Implementation - STI v0.7.4

Posted: Sat May 17, 2014 1:46 pm
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.

Re: Simple Tiled Implementation - STI v0.7.4

Posted: Sat May 17, 2014 11:03 pm
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?)

Re: Simple Tiled Implementation - STI v0.7.4

Posted: Sat May 17, 2014 11:20 pm
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.

Re: Simple Tiled Implementation - STI v0.7.4

Posted: Sun May 18, 2014 4:13 am
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.

Re: Simple Tiled Implementation - STI v0.7.4

Posted: Sun May 18, 2014 3:48 pm
by Karai17
getCollisionMap() grabs a copy of a layer, converts all the non-zero tiles to 1, and returns it.

Re: Simple Tiled Implementation - STI v0.7.4

Posted: Sun May 18, 2014 9:15 pm
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.

Re: Simple Tiled Implementation - STI v0.7.4

Posted: Sun May 18, 2014 10:25 pm
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

Re: Simple Tiled Implementation - STI v0.7.4

Posted: Mon May 19, 2014 12:07 am
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.