- EDIT -
technowand beat me to it again! ;-p
As for your first question all you have to do is create a variable and increment it inside the spawnApple function then check to see if it is at the amount you want. I have modified the code below.
[lua]local apple = display.newImage ( “Red Apple.png” )
physics.addBody(apple, {density=3.0})
apple.name = “apple”
local spawnApple – forward reference for the spawnApple function below
local function onLocalCollision( self,event )
if self.name == “apple” and event.other.name == “pig” then
timer.performWithDelay( 1000, spawnApple, 1 )
score = score + 1
scoreText.text = score
self:removeSelf()
end
if self.name == “apple” and event.other.name == “line” then
timer.performWithDelay( 1000, spawnApple, 1 )
self:removeSelf()
end
end
apple.collision = onLocalCollision
apple:addEventListener( “collision”, apple )
local n = 0 – This will be our counter variable
local maxApples = 5 – You can use any number you want here
– You can use this function for whatever you want I have just used it to print to the terminal as an example
local noMoreApples = function()
print(“Out of apples!”)
end
spawnApple = function() – this is where the spawnApple “variable” gets declared as the spawnApple function
– This is where we check to see if the counter has reached the maximum number of apples allowed
if n >= maxApples then
noMoreApples()
end
local apple = display.newImage ( “Red Apple.png” )
physics.addBody( apple, { density = 3.0 } )
apple.x = math.random(40, 260)
apple.y = math.random(60, 210)
apple.name = “apple”
apple.collision = onLocalCollision
apple:addEventListener( “collision”, apple )
n = n + 1 – This is where the counter variable gets incremented
end[/lua]
As for your second question, do you have the font file in the same folder as your main.lua file? Remember that if you are using a font not natively support by the device you have to include it yourself. [import]uid: 27965 topic_id: 12870 reply_id: 47927[/import]