Hi all,
I’ve a block sliding game, all working nicely as far as logic goes.
At the moment I have calculated a “padding” around all the tiles/bricks to help detect when they are nearing other tiles/bricks and then if needs be the moving tile/brick stops.
However, it’s all a bit messy.
If the player slides the tiles/bricks to quickly and they don’t stop perfectly within the grid lines, the bricks only need to be 1 or 2 units/pixels out and the other bricks around it wont move.
I thought to solve this, and make the user experience more friendly, I could snap a brick/tile to a column or row when it’s anchor is near the column/row centre.
All the maths already exist in my game.
I’ve used a transition.moveTo() function, which does what it says, but then I can’t free the brick.
The code is run through on a mili-second by mili-second basis, so I can’t wrap a loop or counter around it.
I’ve tried setting a property to the tile such as brick.snapped = true. But as the code runs in miliseconds, al that happens is I nudge the brick and tile before it’s identified as being near and snapped back again.
-- SNAP TO GRID local function snapToGridVertical(brickIn) local snapToZone = 10 local brick = brickIn -- test if brick is 1x3 tall or 1x2 tall if( brick.height == mod.gvBrick\_1x3 + (brick.strokeWidth \* 2 ) ) then print("Brick is 1x3 Vertical") if (brick.y \>= (mod.setRow\_1(brickIn) - snapToZone) and brick.y \<= (mod.setRow\_1(brickIn) + snapToZone)) then transition.moveTo( brick, { y = mod.setRow\_1(brickIn), time=500} ) end elseif( brick.height == mod.gvBrick\_1x2 + (brick.strokeWidth \* 2 ) )then print("Brick is 1x2 Vertical") end end
Thanks in advance for your help.
Ange