EDIT: The Perspective camera added ‘jumps’ in movement, thus causing the performance issue. I do not think there is a way around this other than to deal with it, therefore I will. -Chris
Hello all! I feel as if this is a newbie question, as there has to be something so basic that I’m doing wrong… but in theory it feels as if it /should/ work! I’m trying to get a character to move on my ‘play’ scene with Storyboard and Perspective. Keeping in mind my storyboard code placements are not good (I apologize), this is just test code. I’m still new to Corona…
DESCRIPTION: Using the Storyboard and Perspective add-ons, I am trying to get a character to move on a map. Storyboard is used to transition from main menu to page_play (this page), otherwise it is irrelevant. Perspective is used to track and center the character moving.
PROBLEM: Tends to act as if there’s ‘lag’ in movement. I’m not sure if it’s the constant cancellation of the transitions, if it’s the way I’m using the camera app, or maybe something else… or maybe there’s just a much better way to achieve character movement?
local storyboard = require( "storyboard" ) local widget = require( "widget" ) local scene = storyboard.newScene() local perspective=require("perspective") local camera=perspective.createView()
-- Called when the scene's view does not exist: function scene:createScene( event ) local group = self.view -- Used to tell whether or not to listen for finger movement or not local enableMovement = 1 -- Function moveChar function moveChar( event ) -- Get x and y of touch event in content local contentX, contentY = event.x, event.y if(enableMovement) then -- Turn off event listener temporarily enableMovement = false -- addMovement function re-enables ability to move character local function addMovement() enableMovement = true end -- Convert to local coordinates of localX, localY = event.target:contentToLocal( contentX, contentY ) -- Cancel any current transitions for char movement transition.cancel() -- SAMPLE MOVEMENT (work in progress) transition.to( unitMain, { time=1000, alpha=1, x=centerX + localX, y=centerY + localY } ) -- TESTING: print X and Y coords of touch print("X " .. localX .. " Y " .. localY) timer.performWithDelay( 250, addMovement) end --last\_action = current\_time --end return true end map = display.newImageRect ( "Uncharted\_Seas\_Map\_Final.jpg", 5000, 5000 ) map.x = centerX map.y = centerY group:insert(map) btnC = display.newImageRect ( "cancel.png", 24, 24 ) btnC.x = 12 btnC.y = 12 group:insert(btnC) unitMain = display.newImageRect ( "mainchar.gif", 100, 100 ) unitMain.x = centerX unitMain.y = centerY group:insert(unitMain) camera:add(map, 4, false) camera:add(unitMain, 1, true) camera:add(btnC, 1, false) camera:setFocus(unitMain) camera:setBounds(false) camera:track() group:insert(camera) end
-- Called immediately after scene has moved onscreen: function scene:enterScene( event ) local group = self.view ----------------------------------------------------------------------------- -- INSERT code here (e.g. start timers, load audio, start listeners, etc.) ----------------------------------------------------------------------------- function btnC:touch( event ) if event.phase == "ended" then print( "You touched the object!" ) storyboard.gotoScene ( "page\_menu", { effect = "slideRight" } ) end return true end btnC:addEventListener("touch",btnC) map:addEventListener("touch",moveChar) end
-Chris