Hi All,
Getting back into Corona again after a long break, trying out this ‘perspective’ camera – http://developer.coronalabs.com/code/perspective
Can’t get it to work, used a standard game template and added a left / right invisible button (touch left / right side of screen) which will move my ball respectively.
I am trying to move the ball as well as getting the camera to ‘track’ it but can’t work out why it isn’t working
Can anyone help?
thanks in advance
----------------------------------------------------------------------------------------- -- -- level1.lua -- ----------------------------------------------------------------------------------------- local storyboard = require( "storyboard" ) local scene = storyboard.newScene() -- include Corona's "physics" library local physics = require "physics" physics.start(); physics.pause() -------------------------------------------- -- forward declarations and other locals local screenW, screenH, halfW, halfH = display.contentWidth, display.contentHeight, display.contentWidth\*0.5, display.contentHeight\*0.5 local ball local perspective=require("perspective") local camera=perspective.createView() camera:setBounds(false) local leftBtn local rightBtn ----------------------------------------------------------------------------------------- -- BEGINNING OF YOUR IMPLEMENTATION -- -- NOTE: Code outside of listener functions (below) will only be executed once, -- unless storyboard.removeScene() is called. -- ----------------------------------------------------------------------------------------- local function leftBtnTouched(event) transition.to(ball, {x = ball.x + 150, transition=easing.outExpo}) end local function rightBtnTouched(event) transition.to(ball, {x = ball.x - 150, transition=easing.outExpo}) end -- Called when the scene's view does not exist: function scene:createScene( event ) local group = self.view -- create a grey rectangle as the backdrop local background = display.newRect( 0, 0, screenW, screenH ) background.anchorX = 0 background.anchorY = 0 background:setFillColor( .5 ) -- make a crate (off-screen), position it, and rotate slightly ball = display.newCircle(halfW, display.contentHeight - 200, 50) physics.addBody( ball, "dynamic",{density = 10}) camera:add(ball, 1, false) camera:setFocus(ball) camera:track() leftBtn = display.newRect(screenW\*0.25, halfH, halfW, screenH) leftBtn.alpha = 0.01 --can't be 0 as not touchable leftBtn:addEventListener( "touch", leftBtnTouched ) rightBtn = display.newRect(screenW\*0.75, halfH, halfW, screenH) rightBtn.alpha = 0.01 --can't be 0 as not touchable rightBtn:addEventListener( "touch", rightBtnTouched ) -- add physics to the crate physics.addBody( ball, { density=1.0, friction=0.3, bounce=0.3 } ) -- create a grass object and add physics (with custom shape) local grass = display.newImageRect( "grass.png", screenW, 82 ) grass.anchorX = 0 grass.anchorY = 1 grass.x, grass.y = 0, display.contentHeight -- define a shape that's slightly shorter than image bounds (set draw mode to "hybrid" or "debug" to see) local grassShape = { -halfW,-34, halfW,-34, halfW,34, -halfW,34 } physics.addBody( grass, "static", { friction=0.3, shape=grassShape } ) -- all display objects must be inserted into group group:insert( background ) group:insert( grass) group:insert( ball ) end -- Called immediately after scene has moved onscreen: function scene:enterScene( event ) local group = self.view physics.start() end -- Called when scene is about to move offscreen: function scene:exitScene( event ) local group = self.view physics.stop() end -- If scene's view is removed, scene:destroyScene() will be called just prior to: function scene:destroyScene( event ) local group = self.view package.loaded[physics] = nil physics = nil end ----------------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION ----------------------------------------------------------------------------------------- -- "createScene" event is dispatched if scene's view does not exist scene:addEventListener( "createScene", scene ) -- "enterScene" event is dispatched whenever scene transition has finished scene:addEventListener( "enterScene", scene ) -- "exitScene" event is dispatched whenever before next scene's transition begins scene:addEventListener( "exitScene", scene ) -- "destroyScene" event is dispatched before view is unloaded, which can be -- automatically unloaded in low memory situations, or explicitly via a call to -- storyboard.purgeScene() or storyboard.removeScene(). scene:addEventListener( "destroyScene", scene ) ----------------------------------------------------------------------------------------- return scene