Happy New Year!
I have this code that changes the gid of a tile whenever you drag a tile. I dont know why it’s not working. It acts as if I have destroyed the tile instead of setting a new gid. First I thought this was because maybe I was trying to set a non-existent or non-valid gid. But as far as I know this isn’t true, because it’s set automatically with the correct gid(i.e 352 for grass).
Here’s the code:
local startGridPos = nil
local notBuildableGid = nil
local dragging = false
local lastTile = nil
local lastRow = 1; local lastCol = 1
local onTouch = function( event )
if not startGridPos then
startGridPos = \_functions.screenToGridPosition(event)
end
--I have also set an onTap event listener, so I need to know only when it's dragging
if event.phase == "moved" then
local currTile = \_functions.getTileFromScreen( event )
--Set the gid ONLY for the first time
if not dragging then
if not notBuildableGid then
notBuildableGid = currTile.gid
end
end
dragging = true
currTile.alpha = 0.5
currTile:setImage(notBuildableGid)
currTile:getVisual():toFront()
--currTile:destroy()
local row, col = currTile:getGridPosition()
if not lastTile then
lastTile = currTile
end
lastRow = row;
lastCol = col;
end
if event.phase == "ended" then
if dragging then
dragging = false
notBuildableGid = nil
startGridPos = nil
lastTile = nil
lastRow = 1
lastCol = 1
local currTile = \_functions.getTileFromScreen( event )
if \_functions.\_isObstacle( \_functions.screenToGridPosition(event) ) then
print("Is Obstacle")
end
end
end
end
It doesnt give me any errors. It just doesn’t set the tile to any image(whatever gid I put in there). Btw, the tileset Im using it’s the forest.png from Lime’s Tutorials Number 13(“Moving a map via touch”), really good tutorials- I recommend them-.
I would appreciate any help anyone could give me. Thank you! [import]uid: 109816 topic_id: 19905 reply_id: 319905[/import]