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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | 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 |
Hey, this is a bug in the current version of Lime that is fixed in the upcoming version ( which I promise really is coming out soon :-) MonkeyDead is sort of going through a transitional period right now which is slowing things down ) but it is an easy fix, just go into "lime-tile.lua" and find the Tile:setImage() function.
Towards the bottom you should find this code:
1 2 | -- Build the tile physical self:build() |
Thank you very much, it does fix it.
It sets the tile image, but right now Im having a new problem, the gid returned by currTile.gid appears to be incorrect(it returns 352 which is the grass tile, when I touch the tree tile). Do you have any idea why this might be?(It's the same code as before).
Thank you very much Graham.
Ok just put in a fix for this, what you need to do is after those lines you just added also add this:
1 | return self |
It's still not working. Btw, the notBuildableGid which I set the image with currTile:setImage(notBui...) it's set before in this:
1 2 3 4 5 6 | if not dragging then if not notBuildableGid then --It returns the wrong gid in here(before doing the currTile = currtile... notBuildableGid = currTile.gid end end |
Hmm strange, are you able to package up a simple demo showing off the issue and send it to me: support@justaddli.me
What is a gid?
I think it stands for Global ID. It's the id according to the tileset tile position.
From a previous post of mine that Graham answered.
1 2 3 4 5 6 7 | The GID is controlled by your Tilesets in Tiled. Essentially each individual tile in a tileset has an ID, these start from 1 and then go sequentially up from left to right, top to bottom. With me so far? Then the GID ( global id ) is the tiles' ID but each tilesets first id is 1 more than the last id of the previous tileset. http://dl.dropbox.com/u/571145/globalIDs.png |
send message and call to a person
Forum: Report Spam + PM
[INSTALL_PARSE_FAILED_NO_CERTIFICATES]
[SOLVED] Director ERROR: Failed to execute new( params ) function on 'screen1'
Too many (200) local variables
Corona SVG Level Builder released. Drag and drop physics level editor with Inkscape and SVG.
Small bug in Collectible Items example
Pivot Joints and apparent elasticity
Can't make removeSelf() delayed
can i program into several files not only main.lua
Touch event on image (using mask) or getColor function
corona movieclip crash
I still don't think I am removing things right.
some unexpected table length issues
Timer Expired Pause
Talking Gina like application for iphone using Lua
How to save image to camera roll?
deauthorize problem