(FYI, running Build 863. Originally thought this was a Lime issue but excised Lime and problem remains)
Simple Project:
- A 64x64 tile grid. Each tile pulls from a single image sheet.
- A sprite, unanimated, that you can move around using…
- An enterFrame function to translate. (Code below)
- A touch function to enable the enterFrame function to “go” whenever you touch the screen.
Results:
- OSX Simulator (MBA) fine regardless
- iPad3 Device Build: seems fine
- iPhone4 Device Build: If I touch and hold to a single location, performance rarely drops and is mostly 60fps
- iPhone4 Device Build: If I touch and drag slowly (i.e.: arcs, circle) performance cuts down heavily by at least half
- iPhone4 Device Build: If I make an eraser-like rapid drag gesture, performance cuts down to single-frames
Code: I’d be ecstatic if this was just user-error on my part. But I’m utterly stumped as to what it could be, so any help would be appreciated…
[code]-- The enterFrame function.
function movePlayer(event)
if not pause then
– If moveDirection is set, the player is already moving…
if player.moveDirection then
– Update progress
player.moveProgress = player.moveProgress - speed
– Continue moving. Impulse is just a table. Speed is always 4px right now
player:translate( impulse[player.moveDirection][1], impulse[player.moveDirection][2] )
– If finished moving…
if player.moveProgress == 0 then
– Clear the movement direction
player.moveDirection = nil
end
– If the player has finished reaching the next tile (or has never moved before)…
else
– Find the best direction to move.
local xDifference = press.x - player.contentBounds.xMin
local yDifference = press.y - player.contentBounds.yMin
local direction
if math.abs(xDifference) > math.abs(yDifference) then
if xDifference < 0 then direction = “left” else direction = “right” end
else
if yDifference > 0 then direction = “down” else direction = “up” end
end
– If a movement direction was found…
if direction then
– Set the player’s direction flag
player.moveDirection = d.direction
– Reset the pixel progress
player.moveProgress = tileSize
player.moveProgress = player.moveProgress - speed
– Begin moving
player:translate( impulse[player.moveDirection][1], impulse[player.moveDirection][2] )
end
end
– If the game is paused but the player still has movement left to reach the tile edge…
elseif player.moveDirection then
– If finished moving…
if player.moveProgress == 0 then
– Clear the movement direction
player.moveDirection = nil
else
– Update progress
player.moveProgress = player.moveProgress - speed
– Continue moving
player:translate( impulse[player.moveDirection][1], impulse[player.moveDirection][2] )
end
end
end --/movePlayer()
– The touch-screen function. Attached to the tilemap.
function pressScreen(event)
– Since movePlayer() runs on enterFrame I need to store where the player is pressing.
press.x, press.y = event.x, event.y
if event.phase == “began” then
pause = false – whenever pause is false, movePlayer() is cranking away…
elseif event.phase == “ended” or event.phase == “cancelled” then
pause = true
end
end --/pressScreen()
[/code]
(Originally, my plan was to use transition.to, but there seems to be no way to link transition.to seamlessly so it doesn’t look like you’re stop-starting on every tile…) [import]uid: 41884 topic_id: 29141 reply_id: 329141[/import]
In fact, you can notice a slingshot effect; just touch and hold on a single location but drag your finger very slightly - it will slow down until your finger stops, at which point it speeds up again.