Bug Report: Touch scroll with constrainCamera
Version: mte 0v980-6
Summary: Map becomes unresponsive at edges when touch scoll is enabled and constrainCamera is applied.
Background:
My game uses a top-down orthographic map like “CastleDemo” and “RotateConstrainStoryboard”. The world does not wrap and the hero is able to move to the very corners and edges of the world. I have set a single camera constraint that covers the entire map so that the camera never leaves the map when the hero is at the edges. The player is also able to touch scroll around the map (I also plan to implement zoom in / out now that the tile culling issue has been addressed for zoomed out views) so that the player can see the whole map independently of the hero sprite and decide where to move to next.
Problem:
The touch scroll works perfectly for the whole map until the player scrolls to the edges and the constraint comes in to force. At this point the touch becomes sticky and it’s often difficult to scroll away from the edge. If the player scrolls to the map corners then it’s almost impossible to scroll away and the map essentially freezes.
Reproduce:
In the “CastleDemo” project main.lua “UNCOMMENT TO TEST PINCH ZOOM / TOUCH SCROLL” (line 300 onwards) and add to line 56…
mte.constrainCamera({ loc = {1, 1, 100, 100} })
… then run the project and touch scroll to the edges/corners of the map.
Final thoughts
- If world wrap is not enabled would it be possible/preferable for the default behaviour to be a camera constraint to the full dimensions of the map, such as this? I can’t think of a time when visibly dead tile space would be useful (see the CastleDemo touch scroll without constrainCamera and toggleWorldWrapX and toggleWorldWrapY (lines 8 and 9)…)
- Would it be possible to add the touch scroll / pinch code to MTE itself so that it could be enabled and disabled easily as needed? It’s quite a big block of reused code to copy/paste/maintain across multiple projects when it could be housed internally. A couple of listeners could be set/called at key touch phases if customisation is required (such as enable/disable player’s hero’s movement). It could then be implemented with mte.enableMapTouch(), mte.disableMapTouch() and in the game loop the “isDragging” block could be dealt with during mte.update().
Thanks as always!