I have been building on my first game for a while now, but it's my first time coding anything. I am making a puzzle where a tiles can only be stepped on once. It works quite well by simply swapping on collect. However I am swapping from a tile which is mostly white (stone) to a tile which is mostly black (lava). As my player sprite is mostly black, I cannot see my player as the tile I am standing on immediately switches to black (lava) when I collect it.
Would there be a way to swap the tile only when I step off the tile?
You'd probably want to just store the player's position when you move, and the use the stored position when the player moves again, before updating them. Something like:
(room script:)
on enter do
playerX = event.px
playerY = event.py
end
(player script:)
on update do
lastPosition = "{playerX},{playerY}" // eg "4,6"
positionNow = "{event.px},{event.py}" // eg "4,7"
// There's a chance update has fired but the player hasn't moved
if lastPosition != positionNow then
tell playerX, playerY to
swap "black" // update tile at previous position
end
end
// now update the stored coordinates, ready for next check on next update
playerX = event.px
playerY = event.py
end
Hey @scribe6, thanks a lot for the suggestion. I'll experiment with it, and see what it does. I think I might have to embed a condition that makes sure that the last tile was a "stepstone" tile, as not all tiles in the room should be able to swap for "lava".
Yep, that makes sense. Depending on how many tiles you need to deal with (eg if you have more than 1 "stepstone" type tile), you can run that check in different ways. My favourite approach these days is to just call a custom event on the tile, and handle that event for the tiles which need to, eg:
if lastPosition != positionNow then
tell playerX, playerY to
call "playerSteppedoff"
end
end
(and then in the tile:)
on playerSteppedOff do
swap "black"
end