MTE’s movement functions move the map relative to the native size of the map. If your tiles are 32x32, you call goto() with a blockScale of 64x64, and you call moveCamera(2,0) the map will appear to move 4 pixels across the screen. I’d never thought of it from the perspective of moving the map with a finger swipe, but now that you mention it you would have to compensate for this difference.
I threw something together to see just what might be necessary to scroll a map via touch. This is just one way to go about doing it. You’re correct that moveCamera would be best in this situation. Anytime you need to move the camera or a sprite on a per-frame basis, moveCamera() and moveSprite() are the preferred functions. moveCameraTo() and moveSpriteTo() are meant for longer motions taking many frames, during which the movement can’t be modified. None of the movement functions will appear to do anything unless you call mte.update() in an enterFrame event.
local scaleFactor = blockScale / 32 --The ratio of the blockScale to the native size of your tiles local startX, startY, currentX, currentY local isDragging = false local drag = function(event) if event.phase == "began" then startX = event.x startY = event.y currentX = event.x currentY = event.y isDragging = true end if event.phase == "moved" then currentX = event.x currentY = event.y end if event.phase == "ended" or event.phase == "cancelled" then startX, startY = nil, nil currentX, currentY = nil, nil isDragging = false end end local gameLoop = function(event) if isDragging then mte.moveCamera((startX - currentX) / scaleFactor, (startY - currentY) / scaleFactor) startX = currentX startY = currentY end mte.update() end Runtime:addEventListener("touch", drag) Runtime:addEventListener("enterFrame", gameLoop)
And here’s the result, using the platformer test level because it was on hand. Sorry about the weird compression artifacts. The ground texture really seems to confuse Quicktime.
[media]http://www.youtube.com/watch?v=wwhuMGtgU2g[/media]
Speaking of the platformer/sidescroller sample project, it’s coming along nicely. When finished there will be three little test maps, each in a seperate storyboard scene, each demonstrating more complicated movement and collision detection then the last. The first map will feature collision detection against entire tiles- each tile is either completely solid or completely passable. That is just about finished and you can see it in the video below. The second map will add sloped ground to the mix. The third will demonstrate how to go about making freeform ground surfaces within a tile using tile properties.
[media]http://www.youtube.com/watch?v=jMqPHjnKhYw[/media]
I’ve been making incremental improvements to the Million Tile Engine as well. The next update will bring greatly improved convert() performance.