Hey guys, I’m using the perspective API. It’s pretty cool, but I don’t see any support for moving a character based on touch. Here’s part of my code to try to simulate this. Problem is that if someone drags a finger, I want it to move to where they’re finger is moving (and follow them), much like you’d expect. Well, when I use the following code, the character will stand virtually still until a definitive choice is made. I believe this is due to the constant transition.to cancellations (which makes sense). What would be the best way to approach this? Oh and I tried using ostime to only allow a new transition.to (and cancellation) every xx ms, but it acted very strangly for different phones. Suggestions?
local storyboard = require( "storyboard" ) local widget = require( "widget" ) local scene = storyboard.newScene() local perspective=require("perspective") local camera=perspective.createView()
-- Code for clicks -- Create text objects to display content and local coordinates local contentText = display.newText( "", 0, 0, display.nativeSystemFont, 25 ) local localText = display.newText( "", 0, 0, display.nativeSystemFont, 25 ) localText.anchorX = 0 ; localText.anchorY = 0 contentText.anchorX = 0 ; contentText.anchorY = 0 function moveChar( event ) -- Get x and y of touch event in content coordinates local contentX, contentY = event.x, event.y -- Convert to local coordinates of localX, localY = event.target:contentToLocal( contentX, contentY ) transition.cancel() transition.to( unitMain, { time=500, alpha=1, x=centerX + localX, y=centerY + localY } ) return true end
camera:add(map, 4, false) camera:add(unitMain, 1, true) camera:setFocus(unitMain) camera:setBounds(false) camera:track() group:insert(camera)
btnC:addEventListener("touch",btnC) map:addEventListener( "touch", moveChar )