Thank you very much for the break down. I’ve checked and re checked my code and can’t figure out why after I added the new code I still get a blank screen. Did I add this correctly?
local physics = require("physics")
physics.start()
physics.setGravity(0,16)
score = 0
local background = display.newImage("soccersky.png")
local ball = display.newImage("soccerball.png")
ball.x = display.contentWidth/2
physics.addBody(ball, {bounce = 0.3, friction = .1, radius = 43} )
ball.name = "ball"
local floor = display.newImage("soccerfield.png")
floor.x = 100; floor.y = display.contentHeight
physics.addBody(floor, "static", {density=3,friction=3,bounce=0})
floor.name = "floor"
local scoreTextfield = display.newText( "Score: " .. score, 20, 445, nil, 18)
scoreTextfield:setTextColor(255,255,255)
ballFell = false
local score = 0
local function onCollision(e)
if(e.phase == "ended") then
print("!")
elseif(e.other.name == "floor") then
if(score \> 0) then
score = 0
scoreTextfield.text = "Score: " .. score
end
end
end
local highestScore = 0
local highestScoreTextfield = display.newText( "High Score: " .. highestScore, 180, 445, nil, 18)
highestScoreTextfield:setTextColor(255,255,255)
-- High Score
local score = 0
if score \> highScore then
highScore = score
end
local saveToFile(theScore)
filePath = system.pathForFile( "score.txt", system.DocumentsDirectory )
file = io.open( filePath, "w+" )
file:write( theScore )
io.close( file )
end
local loadHighScore()
filePath = system.pathForFile( "score.txt", system.DocumentsDirectory )
file = io.open( filePath, "r" )
if file then
theScore = file:read( "\*a" )
else
theScore = 0
end
io.close( file )
return theScore
end
--End high score
local floor = display.newRect(320, 0, 1, 480)
local lWall = display.newRect(0, 480, 320, 1)
local rWall = display.newRect(0, -1, 320, 1)
local ceiling = display.newRect(-1, 0, 1, 480)
staticMaterial = {density=2, friction=.3, bounce=.4}
physics.addBody(floor, "static", staticMaterial)
physics.addBody(lWall, "static", staticMaterial)
physics.addBody(rWall, "static", staticMaterial)
physics.addBody(ceiling, "static", staticMaterial)
local function kick\_ball(e)
score = score + 1
scoreTextfield.text = "Score: " .. score
ball:applyLinearImpulse(-1, -2, ball.x, ball.y)
if(score == 50) then
media.playSound( "Crowdcheer.mp3", true )
end
end
ball:addEventListener("collision", onCollision)
ball:addEventListener("touch", kick\_ball)
Again thanks, I’ve been trying to figure this stuff out for days now. [import]uid: 72845 topic_id: 11899 reply_id: 43793[/import]