Hi all,
I’m not sure which sub-forum to place this problem I have in, so any mods, please feel free to move it to the right section(although I know you will do so without me asking haha…) jokes aside, on to my problem.
I created a few rows of tiles, some cheese and one mouse(it’s a variant/heavily modified version of minesweeper idea i’m working on).
Random numbers are used to place the cheese on the tiles itself, I also have some code to ensure a tile doesn’t have two or more cheese on it.
The mouse’s location is also randomly selected among the tiles and some code to ensure the mouse isn’t on a tile that has a cheese on it. So here comes, perhaps a rather strange bug? The mouse’s location in the simulator doesn’t correspond to it’s x and y coordinates. For example, the mouse’s location is on tile 5, hence it’s x and y is the same as tile 5, but in the simulator, it is on tile 10. If it’s on tile 14, it will appear on tile 19 instead. See linked picture for a better description: http://imgur.com/a/AnNHk
This is the code for the creating the mice sprite. I had a temporary workaround that uses transition to move the mice up by a single tilesize, but this workaround affects another mechanic of the mice later on in the code, thus I would need to figure out what is wrong here.
for i = 1, map.numberOfMice do if #miceTbl == map.numberOfMice then do return end else local sheet\_movingMice = graphics.newImageSheet( "sprites/Mice Motion.png", sheetOptions ) -- sequences table local sequences\_movingMice = { -- consecutive frames, move right sequence { name = "MoveRight", frames = { 16,17,18,19,20 }, time = 800, loopCount = 0, loopDirection = "forward" }, -- consecutive frames, moving up, sequence { name = "MoveUp", frames = { 21,22,23,24,25 }, time = 600, loopCount = 0, loopDirection = "forward" }, -- consecutive frames, moving down, sequence { name = "MoveDown", frames = { 1,2,3,4,5 }, time = 600, loopCount = 0, loopDirection = "forward" } } local movingMice = display.newSprite( sheet\_movingMice, sequences\_movingMice ) movingMice:setSequence("MoveRight") movingMice:pause() MiceLocIndex = newRandNum(numberOfTiles) print('original mice index', MiceLocIndex) -- assign properties and coordinates movingMice.x = tilesTbl[MiceLocIndex].x movingMice.y = tilesTbl[MiceLocIndex].y movingMice.colliding = false movingMice.type = 'mice' movingMice.matchingTile = MiceLocIndex movingMice.revealed = false movingMice.xyGridCoordinate = tilesTbl[MiceLocIndex].xyGridCoordinate miceTbl[#miceTbl+1] = movingMice print('mice generated at tile', MiceLocIndex, 'location:', movingMice.x, movingMice.y) mapGroup:insert( movingMice ) --movingMice:toBack() --transition.to( movingMice, {time=10, delta=true, y=-tileSize} ) print('number of mice',#miceTbl) -- ensure mice do not spawn at same location as cheese if #miceTbl \>= 1 then for i = 1, #miceTbl do for j = 1, #cheeseTbl do if MiceLocIndex == cheeseTbl[j].matchingTile then repeat MiceLocIndex = newRandNum(numberOfTiles) until MiceLocIndex ~= cheeseTbl[j].matchingTile print('new mice index', MiceLocIndex) miceTbl[i].x = tilesTbl[MiceLocIndex].x miceTbl[i].y = tilesTbl[MiceLocIndex].y miceTbl[i].xyGridCoordinate = tilesTbl[MiceLocIndex].xyGridCoordinate miceTbl[i].matchingTile = MiceLocIndex mapGroup:insert( miceTbl[i] ) end end end end end end
I also have another question regarding movement of sprites using transition.to, but perhaps that is more suitable for another post or after this problem have been solved first.
Thanks for reading. Appreciate all feedback and help here!