I checked the onComplete parameter of moveSprite to and it is working correctly. Your situation- running a function but also passing parameters to it- requires the use of a Lua closure. Simply put a closure is a function that returns another function. If you set onComplete equal to a function, that function will always run immediately. This isn’t a problem when you set it to the variable declaration of the function, because the function stored at that address will then run when the move is complete. However, calling a function will do just that: call a function, immediately.
mte.moveSpriteTo( { sprite = hero, locX = xTile, locY = yTile, time = 2000, transition = easing.linear,onComplete=removetile(player.level,xTile,yTile,name) } )
You are calling removetile(player.level,xTile,yTile,name). The function will run immediately and onComplete will be set equal to its output, which in this case I’m guessing is probably nothing.
You can change it like so:
mte.moveSpriteTo( { sprite = hero, locX = xTile, locY = yTile, time = 2000, transition = easing.linear,onComplete= function() return removetile(player.level,xTile,yTile,name) end } )
With this modification, you are calling the Lua closure immediately, which returns the function you want to call later, along with the variable arguments used by it, and onComplete is set equal to this function.
The default behavior of Corona’s physics implementation is to have downward gravity. The dynamic tiles are all over the place because they are 1) colliding with each other and the nearby static tiles and 2) being pulled down by gravity. Dynamic tiles are treated like sprites; they are not culled by the engine when they move offscreen. Static tiles are culled when they move offscreen. The result is that the dynamic tiles begin to “fall” towards the bottom of the screen because the world has culled out from under them. When you move back towards that part of the map and it comes onscreen, the engine respawns the static tiles which effectively lock the dynamic tiles in place where-ever they were at the time.
You can change the gravity with a physics API call:
physics.setGravity(0, 0)
You may find that the active tiles still wander around when they’re offscreen due to the last push given them by the static tiles as they cull. You can give them a shape property to define the shape of the physics body. You may want to reduce the (true) size of the physics bodies so that they don’t touch their neighbors and jostle around as they do in the very beginning of the video you posted.
As for the gaps which should be static tiles, are you sure you used the same grass tile, or that all the grass tiles have physics enabled? Some of the tilesets used in CastleDemo have duplicate tiles.