Not seeing ball!

I am making the game.lua part of my game and im trying to display the ball . When I try to display the ball on line’s 124-125 of my code it doesn’t display on screen .

My level1.lua code:

local storyboard = require( "storyboard" ) local scene = storyboard.newScene() function scene:createScene( event ) local group = self.view local physics = require( "physics" ) physics.start() physics.setGravity(0, 7) -- display background image local background = display.newImage( "background.png" ) background.x = 10; background.y = 308 -- display ground image local ground = display.newImage( "ground.png" ) ground.x = 145; ground.y = 480 physics.addBody( ground, "static" , { friction=0.5, bounce=0.1 } ) -- create object local myObject = display.newRect( 0, 0, 100, 30 ) myObject:setFillColor( 0 ) myObject.x = 145; myObject.y = 400 physics.addBody( myObject, "kinematic" , { myObject, friction=0.5, bounce=1 } ) -- touch listener function function myObject:touch( event ) if event.phase == "moved" then self.x = event.x self.y = event.y end return true end -- make 'myObject' listen for touch events myObject:addEventListener( "touch", myObject ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.x, wall.y = -6, 387 wall.rotation = 90 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.x, wall.y = -6, 300 wall.rotation = 90 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.x, wall.y = -6, 202 wall.rotation = 90 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.x, wall.y = -6, 104 wall.rotation = 90 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.x, wall.y = -6, 7 wall.rotation = 90 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.x, wall.y = 50, -49 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.x, wall.y = 135, -49 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.x = 232 wall.y = -49 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.x = 335 wall.y = -49 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.rotation = 90 wall.x = 325 wall.y = 3 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.rotation = 90 wall.x = 325 wall.y = 98 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.x = 325 wall.y = 195 wall.rotation = 90 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.rotation = 90 wall.x = 325 wall.y = 292 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.rotation = 90 wall.x = 325 wall.y = 387 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=4 } ) local ball = display.newImageRect( "ball.xcf", 200, 200 ) ball.x = 200 ball.y = 480 group:insert(ball) group:insert(background) group:insert(ground) group:insert(myObject) group:insert(wall) group:insert(wall) group:insert(wall) group:insert(wall) group:insert(wall) group:insert(wall) group:insert(wall) group:insert(wall) group:insert(wall) group:insert(wall) group:insert(wall) group:insert(wall) group:insert(wall) group:insert(wall) end function scene:enterScene( event ) local group = self.view end function scene:exitScene( event ) local group = self,view end function scene:destroyScene( event ) local group = self.view end scene:addEventListener( "createScene", scene ) scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) scene:addEventListener( "destroyScene", scene ) return scene

What is the problem here ?

Thank you.

Hi.  XCF is not a valid image format.  I’d stick with PNG or JPG.

:slight_smile: I know its hard to tell what to post sometimes.  So, while I think you were trying for thoroughness, I think the creation call alone would have been enough.  

local ball = display.newImageRect( "ball.xcf", 200, 200 )

Don’t worry, we’ll ask for more if we need it.  Just try to be more concise if you can.  The more you code and post the easier this will be.

Meanwhile, good luck on your game.

Hi.  While I’m looking and since you posted it, let me make a suggestion.

You can make your code a lot smaller if you don’t do this:

local ball = display.newImageRect( "ball.png", 200, 200 ) ball.x = 10 ball.y = 100 group:insert(ball) local ball = display.newImageRect( "ball.png", 200, 200 ) ball.x = 20 ball.y = 100 group:insert(ball) local ball = display.newImageRect( "ball.png", 200, 200 ) ball.x = 30 ball.y = 100 group:insert(ball) ... etc.

Do this instead:

local ball = display.newImageRect( group, "ball.png", 200, 200 ) ball.x = 10 ball.y = 100 local ball = display.newImageRect( group, "ball.png", 200, 200 ) ball.x = 20 ball.y = 100 local ball = display.newImageRect( group, "ball.png", 200, 200 ) ball.x = 30 ball.y = 100 ... etc.

Also, you have a major logic error in your code.

You are only inserting the last created wall object in the group.

group:insert(ball) group:insert(background) group:insert(ground) group:insert(myObject) group:insert(wall) group:insert(wall) -- wall is same object as last call group:insert(wall) -- wall is same object as last call group:insert(wall) -- wall is same object as last call group:insert(wall) -- wall is same object as last call group:insert(wall) -- wall is same object as last call group:insert(wall) -- wall is same object as last call group:insert(wall) -- wall is same object as last call group:insert(wall) -- wall is same object as last call group:insert(wall) -- wall is same object as last call group:insert(wall) -- wall is same object as last call group:insert(wall) -- wall is same object as last call group:insert(wall) -- wall is same object as last call group:insert(wall) -- wall is same object as last call

All these extra inserts are not doing anything.  Also, only the last wall you created is getting inserted into the group.

Again, I suggest NOT using insert at all.  It is more compact and cleaner to supply the group as the first argument when creating (as I showed in my last post above).

Note: I cleaned up both of my last posts, so you may want to read them again to be sure you see what I wrote and coded.

Thank you for your suggestions.

Hi.  XCF is not a valid image format.  I’d stick with PNG or JPG.

:slight_smile: I know its hard to tell what to post sometimes.  So, while I think you were trying for thoroughness, I think the creation call alone would have been enough.  

local ball = display.newImageRect( "ball.xcf", 200, 200 )

Don’t worry, we’ll ask for more if we need it.  Just try to be more concise if you can.  The more you code and post the easier this will be.

Meanwhile, good luck on your game.

Hi.  While I’m looking and since you posted it, let me make a suggestion.

You can make your code a lot smaller if you don’t do this:

local ball = display.newImageRect( "ball.png", 200, 200 ) ball.x = 10 ball.y = 100 group:insert(ball) local ball = display.newImageRect( "ball.png", 200, 200 ) ball.x = 20 ball.y = 100 group:insert(ball) local ball = display.newImageRect( "ball.png", 200, 200 ) ball.x = 30 ball.y = 100 group:insert(ball) ... etc.

Do this instead:

local ball = display.newImageRect( group, "ball.png", 200, 200 ) ball.x = 10 ball.y = 100 local ball = display.newImageRect( group, "ball.png", 200, 200 ) ball.x = 20 ball.y = 100 local ball = display.newImageRect( group, "ball.png", 200, 200 ) ball.x = 30 ball.y = 100 ... etc.

Also, you have a major logic error in your code.

You are only inserting the last created wall object in the group.

group:insert(ball) group:insert(background) group:insert(ground) group:insert(myObject) group:insert(wall) group:insert(wall) -- wall is same object as last call group:insert(wall) -- wall is same object as last call group:insert(wall) -- wall is same object as last call group:insert(wall) -- wall is same object as last call group:insert(wall) -- wall is same object as last call group:insert(wall) -- wall is same object as last call group:insert(wall) -- wall is same object as last call group:insert(wall) -- wall is same object as last call group:insert(wall) -- wall is same object as last call group:insert(wall) -- wall is same object as last call group:insert(wall) -- wall is same object as last call group:insert(wall) -- wall is same object as last call group:insert(wall) -- wall is same object as last call

All these extra inserts are not doing anything.  Also, only the last wall you created is getting inserted into the group.

Again, I suggest NOT using insert at all.  It is more compact and cleaner to supply the group as the first argument when creating (as I showed in my last post above).

Note: I cleaned up both of my last posts, so you may want to read them again to be sure you see what I wrote and coded.

Thank you for your suggestions.