This may be a basic question but I am having trouble getting my bird object to move even though I have applied the correct (I think) code.
In line 35 I added the event listener as you can see. And in line 78 I created the function it references to. Am Im obviously doing something wrong so can you guys please help me out? Maybe it has something to do with the scene?
[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 = display.contentWidth, display.contentHeight, display.contentWidth*0.5
– Called when the scene’s view does not exist:
function scene:createScene( event )
local group = self.view
– create the level background
local background = display.newImageRect( “Stage1BG.jpg”, display.contentWidth, display.contentHeight )
background:setReferencePoint( display.TopLeftReferencePoint )
background.x, background.y = 0, 0
– make the object, position it
local bird = display.newImage( “Bird2Side.png” )
bird.x = display.contentWidth/65 + 30
bird.y = display.contentHeight/2
– add physics to the bird
physics.addBody( bird, “dynamic”, { density=3.0, friction=0.3, bounce=0.2, radius=35 } )
–add an event listener to the bird
bird:addEventListener( “touch”, moveBird )
local startingBranch = display.newImage( “StartingBranch.png” )
startingBranch.x = display.contentWidth/65
startingBranch.y = display.contentHeight - 40
–add starting Branch as a physics body
physics.addBody(startingBranch, “static”, { friction=0.5 } )
local endingBranch = display.newImage(“EndingBranch.png”)
endingBranch.x = display.contentWidth
endingBranch.y = display.contentHeight - 40
–add ending Branch as a physics body
physics.addBody(endingBranch, “static”, { friction=0.5 })
local block1 = display.newImage(“WoodBlock1.png”)
block1.x = display.contentWidth/4
block1.y = display.contentHeight - 40
–add block 1 as physics body
physics.addBody( block1, “static”, { density=2.0, friction=0.3, bounce = 0.4 } )
local block2 = display.newImage(“WoodBlock2.png”)
block2.x = display.contentWidth/2
block2.y = display.contentHeight - 40
–add block 2 as physics body
physics.addBody( block2, “static”, { density = 1, friction = 2, bounce = 0.4, })
local block3 = display.newImage(“WoodBlock3.png”)
block3.x = display.contentWidth/1.33
block3.y = display.contentHeight - 40
–add block 3 as physics body
physics.addBody( block3, “static”, { density=2.0, friction=0.3, bounce = 0.4 } )
– all display objects must be inserted into group
group:insert( background )
group:insert( bird )
group:insert( block1 )
group:insert( block2 )
group:insert( block3 )
group:insert( startingBranch )
group:insert( endingBranch )
end
function scene:moveBird( event )
bird:applyLinearImpulse( 0 , -0.5, bird.x, bird.y)
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[/lua] [import]uid: 162953 topic_id: 29298 reply_id: 329298[/import]
[import]uid: 162953 topic_id: 29298 reply_id: 117942[/import]