I have looked at the various sprite tutorials on youtube and have followed them to the dot. I can’t get this to work even though it seems I’m using the right code and I have tried doing it the “old” way and the new way. Perhaps I am just misplacing things? 
*Lines 56-64 are the important ones*
(I only included the necessary portion of code)
There are 11 different frames in my sprite, and I created a sprite data sheet as well in Zwoptex.
[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
local bird
– BEGINNING OF YOUR IMPLEMENTATION
– NOTE: Code outside of listener functions (below) will only be executed once,
– unless storyboard.removeScene() is called.
– move Bird function
local function moveBird(event)
if event.phase == “began” then
local target = event.target – this is the bird that was touched
target:applyLinearImpulse( .3 , -1.3, bird.x, bird.y)
end
return true
end
– 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 a bird (off-screen), position it, and rotate slightly
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=0.2, friction=0.3, bounce=0.4, radius=22 } )
–add an event listener to the bird
bird:addEventListener( “touch”, moveBird )
–allow sprites
require (“sprite”)
local data = require(“NewBlock”).getSpriteSheetData()
local sheet1 = sprite.newSpriteSheet( “NewBlock.png”, data )
local spriteSet1 = sprite.newSpriteSet(sheet1, 1, 11)
local instance1 = sprite.newSprite( spriteSet1? )
instance1.x = display.contentWidth / 2
instance1.y = display.contentHeight / 2
instance1:play()
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 = .7 } )
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 = .7, })
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 = .7 } )
– 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[/lua]
[import]uid: 162953 topic_id: 29450 reply_id: 329450[/import]
[import]uid: 52491 topic_id: 29450 reply_id: 118310[/import]