balloon counter tutorial problem



– main.lua


local tapCount = 0

local background = display.newImageRect( “background.png”, 360, 570 )
background.x = display.contentCenterX
background.y = display.contentCenterY

local tapText = display.newText( tapCount, 300, 300, native.systemFont, 100 )
tapText:setFillColor( 0, 0, 250)

local platform = display.newImageRect( “platform.png”, 300, 50 )
platform.x = display.contentCenterX
platform.y = display.contentHeight-25

local balloon = display.newImageRect( “balloon.png”, 112, 112 )
balloon.x = display.contentCenterX
balloon.y = display.contentCenterY
balloon.alpha = 0.8

local physics = require( “physics” )
physics.start()

physics.addBody( platform, “static” )
physics.addBody( balloon, “dynamic”, { radius=50, bounce=0.3 } )

local function pushBalloon()
 balloon:applyLinearImpulse( 0, -0.75, balloon.x, balloon.y )
 tapCount = tapCount + 1
 tapText.text = tapCount
end

balloon:addEventListener( “tap”, pushBalloon )

why cant I see the counter

The counter is hiding below your platform. Corona draws things on the screen from back to front in the order you list them in your code. Also make sure the color of your text is going to be visible too.  Corona colors are specified using a color range of 0 … 1, not 0 … 255.  

Rob

Thank you rob


 main.lua


local tapCount = 0

local tapText = display.newText( tapCount, 300, 300, native.systemFont, 100 )
tapText:setFillColor( 0, 0, 0.2)

local background = display.newImageRect( “background.png”, 360, 570 )
background.x = display.contentCenterX
background.y = display.contentCenterY

local platform = display.newImageRect( “platform.png”, 300, 50 )
platform.x = display.contentCenterX
platform.y = display.contentHeight-25

local balloon = display.newImageRect( “balloon.png”, 112, 112 )
balloon.x = display.contentCenterX
balloon.y = display.contentCenterY
balloon.alpha = 0.8

local physics = require( “physics” )
physics.start()
physics.addBody( platform, “static” )
physics.addBody( balloon, “dynamic”, { radius=50, bounce=0.3 } )

local function pushBalloon()
 balloon:applyLinearImpulse( 0, -0.75, balloon.x, balloon.y )
 tapCount = tapCount + 1
 tapText.text = tapCount

end
balloon:addEventListener( “tap”, pushBalloon )

@brubeaster,

  1. Please post code in code blocks. 

formatyourcode.jpg

  1. You gotta ask a question too. :slight_smile:

  2. I see a problem.  As Rob said, Corona uses the painter’s algorithmso order matters.

This is wrong:

local tapCount = 0 local tapText = display.newText( tapCount, 300, 300, native.systemFont, 100 ) tapText:setFillColor( 0, 0, 0.2) local background = display.newImageRect( "background.png", 360, 570 )

This is better:

local background = display.newImageRect( "background.png", 360, 570 ) local tapCount = 0 local tapText = display.newText( tapCount, 300, 300, native.systemFont, 100 ) tapText:setFillColor( 0, 0, 0.2)

In the future try debugging by commenting out all your code.

Then, uncomment line by line and re-run it each time you make a change to see what happens and what changes.

The counter is hiding below your platform. Corona draws things on the screen from back to front in the order you list them in your code. Also make sure the color of your text is going to be visible too.  Corona colors are specified using a color range of 0 … 1, not 0 … 255.  

Rob

Thank you rob


 main.lua


local tapCount = 0

local tapText = display.newText( tapCount, 300, 300, native.systemFont, 100 )
tapText:setFillColor( 0, 0, 0.2)

local background = display.newImageRect( “background.png”, 360, 570 )
background.x = display.contentCenterX
background.y = display.contentCenterY

local platform = display.newImageRect( “platform.png”, 300, 50 )
platform.x = display.contentCenterX
platform.y = display.contentHeight-25

local balloon = display.newImageRect( “balloon.png”, 112, 112 )
balloon.x = display.contentCenterX
balloon.y = display.contentCenterY
balloon.alpha = 0.8

local physics = require( “physics” )
physics.start()
physics.addBody( platform, “static” )
physics.addBody( balloon, “dynamic”, { radius=50, bounce=0.3 } )

local function pushBalloon()
 balloon:applyLinearImpulse( 0, -0.75, balloon.x, balloon.y )
 tapCount = tapCount + 1
 tapText.text = tapCount

end
balloon:addEventListener( “tap”, pushBalloon )

@brubeaster,

  1. Please post code in code blocks. 

formatyourcode.jpg

  1. You gotta ask a question too. :slight_smile:

  2. I see a problem.  As Rob said, Corona uses the painter’s algorithmso order matters.

This is wrong:

local tapCount = 0 local tapText = display.newText( tapCount, 300, 300, native.systemFont, 100 ) tapText:setFillColor( 0, 0, 0.2) local background = display.newImageRect( "background.png", 360, 570 )

This is better:

local background = display.newImageRect( "background.png", 360, 570 ) local tapCount = 0 local tapText = display.newText( tapCount, 300, 300, native.systemFont, 100 ) tapText:setFillColor( 0, 0, 0.2)

In the future try debugging by commenting out all your code.

Then, uncomment line by line and re-run it each time you make a change to see what happens and what changes.