[Resolved] Scoreing system with images instead of fonts

@peach pellen

How would that code apply to replacing hud in the game?
[lua]

local hud = function()

eggText = display.newText( "Caught: " … eggCount, 0, 0, “Arial”, 45 )
eggText:setTextColor( 255, 255, 255, 255 )
eggText.xScale = 0.5; eggText.yScale = 0.5
eggText.x = (480 - (eggText.contentWidth * 0.5)) - 15
eggText.y = 305

gameGroup:insert( eggText )

livesText = display.newText( "Lives: " … gameLives, 0, 0, “Arial”, 45 )
livesText:setTextColor( 255, 255, 255, 255 ) --> white
livesText.xScale = 0.5; livesText.yScale = 0.5
livesText.x = (480 - (livesText.contentWidth * 0.5)) - 15
livesText.y = 15

gameGroup:insert( livesText )

scoreText = display.newText( "Score: " … gameScore, 0, 0, “Arial”, 45 )
scoreText:setTextColor( 255, 255, 255, 255 ) --> white
scoreText.xScale = 0.5; scoreText.yScale = 0.5
scoreText.x = (scoreText.contentWidth * 0.5) + 15
scoreText.y = 15

gameGroup:insert( scoreText )

local onPauseTouch = function( event )
if event.phase == “release” and pauseBtn.isActive then
audio.play( buttonSound )[/lua] [import]uid: 128294 topic_id: 28718 reply_id: 119558[/import]

You’d replace scoreText section with the section from the tutorial. If you watch it you will see is fairly simple :slight_smile: [import]uid: 52491 topic_id: 28718 reply_id: 119626[/import]

@TheRealTonyK

Meaning the text in maingame lua file would look like this on top?
[lua]local background
local ground
local charObject
local brknLy
local scoreText
local lyText
local livesText
local shade
local gameOverScreen

local gameIsActive = false
local startDrop
local livesText = require(“livesText”)
local scoreText = require(“scoreText”)
local lyText = require(“eggText”)
local mRand = math.random
local lyDensity = 1.0
local lyShape = {-12,-13, 12,-13, 12,13, -12,13 }
local bagShape = {15,-13, 65,-13, 65,13, 15,13 } [/lua]

ly short for lychee nuts. [import]uid: 128294 topic_id: 28718 reply_id: 120436[/import]

@peach pellen

Though, how does that work livesText and and eggText for example? [import]uid: 128294 topic_id: 28718 reply_id: 119716[/import]

If using it more than once you’d copy and rename the file - that’s basic, only set up for one display. (Very easy to change, though.) [import]uid: 52491 topic_id: 28718 reply_id: 119837[/import]

That looks like a good start to me. :slight_smile: [import]uid: 21331 topic_id: 28718 reply_id: 120574[/import]

@ peach pellen

I just don’t understand how the same code from your score example would apply to losing lives & how many times player caught the object. [import]uid: 128294 topic_id: 28718 reply_id: 119853[/import]

@theRealTonyK

[lua]lyText.init({x=(480 - (lyText.contentWidth * 0.5)) - 15), y=305})[/lua]

That would go into scoreText? or maingame.lua?

What would I do for gameover results? This is what I have since I didn’t modify final score to render score and number images.
[lua]
local callGameOver = function()

audio.play( gameOverSound )

gameIsActive = false
physics.pause()

– make sure pause button is hidden
pauseBtn.isVisible = false
pauseBtn.isActive = false

shade = display.newRect( 0, 0, 570, 320 )
shade:setFillColor( 0, 0, 0, 255 )
shade.x = 240; shade.y = 160
shade.alpha = 0

gameOverScreen = display.newImageRect( “over.png”, 400, 300 )

local newScore = gameScore
setScore( newScore )

gameOverScreen.x = 240; gameOverScreen.y = 160
gameOverScreen.alpha = 0

gameGroup:insert( shade )
gameGroup:insert( gameOverScreen )

–transittion game over assets
transition.to( shade, { time=200, alpha=0.65 } )
transition.to( gameOverScreen, { time=500, alpha=1 } )

scoreText.isVisible = false
scoreText.text = "Score: " … gameScore
scoreText.xScale = 0.5; scoreText.yScale = 0.5
scoreText.x = 240
scoreText.y = 160
scoreText:toFront()
timer.performWithDelay( 0, function() scoreText.isVisible = true; end, 1 )

–compare scores
if gameScore > highScore then
highScore = gameScore
local highScoreFilename = “highScore.data”
saveValue( highScoreFilename, tostring(highScore) )
end

–show high score
highScoreText = display.newText( "Best Game Score: " … highScore, 0, 0, “Arial”, 30 )
highScoreText:setTextColor( 255, 255, 255, 255 )
highScoreText.xScale = 0.5; highScoreText.yScale = 0.5
highScoreText.x = 240
highScoreText.y = 120

gameGroup( highScoreText )

local onMenuTouch = function( event )
if event.phase == “release” then

audio.play( buttonSound )
storyboard.gotoScene( “mainmenu”, “fade”, 500 )

end
end
[/lua]
[import]uid: 128294 topic_id: 28718 reply_id: 120594[/import]

I’ve done this before with this class. You would start with copying the “score.lua” file to say:
eggText.lua
livesText.lua
scoreText.lua

then require with:

eggText = require("eggText")  
livesText = require("livesText")  
scoreText = require("scoreText")  

Starting to see the trick. :slight_smile:
then init them:

eggText.init({x=(480 - (eggText.contentWidth \* 0.5)) - 15), y=305})  

I think you see where this is going in relation to your code.

Looking at the score.lua, it would be quite easy for you to add a “prefix” variable even to handle your "Caught: ", "Lives: ", etc. as well as other specific needs.

Looking a little further it would be easy for you modify the original score.lua to instantiate multiple instances as well, but that one is for you. :slight_smile:

[import]uid: 21331 topic_id: 28718 reply_id: 120016[/import]

@TheRealTonyK

Meaning the text in maingame lua file would look like this on top?
[lua]local background
local ground
local charObject
local brknLy
local scoreText
local lyText
local livesText
local shade
local gameOverScreen

local gameIsActive = false
local startDrop
local livesText = require(“livesText”)
local scoreText = require(“scoreText”)
local lyText = require(“eggText”)
local mRand = math.random
local lyDensity = 1.0
local lyShape = {-12,-13, 12,-13, 12,13, -12,13 }
local bagShape = {15,-13, 65,-13, 65,13, 15,13 } [/lua]

ly short for lychee nuts. [import]uid: 128294 topic_id: 28718 reply_id: 120436[/import]

Help. Anyone??? [import]uid: 128294 topic_id: 28718 reply_id: 121190[/import]

That looks like a good start to me. :slight_smile: [import]uid: 21331 topic_id: 28718 reply_id: 120574[/import]

@theRealTonyK

[lua]lyText.init({x=(480 - (lyText.contentWidth * 0.5)) - 15), y=305})[/lua]

That would go into scoreText? or maingame.lua?

What would I do for gameover results? This is what I have since I didn’t modify final score to render score and number images.
[lua]
local callGameOver = function()

audio.play( gameOverSound )

gameIsActive = false
physics.pause()

– make sure pause button is hidden
pauseBtn.isVisible = false
pauseBtn.isActive = false

shade = display.newRect( 0, 0, 570, 320 )
shade:setFillColor( 0, 0, 0, 255 )
shade.x = 240; shade.y = 160
shade.alpha = 0

gameOverScreen = display.newImageRect( “over.png”, 400, 300 )

local newScore = gameScore
setScore( newScore )

gameOverScreen.x = 240; gameOverScreen.y = 160
gameOverScreen.alpha = 0

gameGroup:insert( shade )
gameGroup:insert( gameOverScreen )

–transittion game over assets
transition.to( shade, { time=200, alpha=0.65 } )
transition.to( gameOverScreen, { time=500, alpha=1 } )

scoreText.isVisible = false
scoreText.text = "Score: " … gameScore
scoreText.xScale = 0.5; scoreText.yScale = 0.5
scoreText.x = 240
scoreText.y = 160
scoreText:toFront()
timer.performWithDelay( 0, function() scoreText.isVisible = true; end, 1 )

–compare scores
if gameScore > highScore then
highScore = gameScore
local highScoreFilename = “highScore.data”
saveValue( highScoreFilename, tostring(highScore) )
end

–show high score
highScoreText = display.newText( "Best Game Score: " … highScore, 0, 0, “Arial”, 30 )
highScoreText:setTextColor( 255, 255, 255, 255 )
highScoreText.xScale = 0.5; highScoreText.yScale = 0.5
highScoreText.x = 240
highScoreText.y = 120

gameGroup( highScoreText )

local onMenuTouch = function( event )
if event.phase == “release” then

audio.play( buttonSound )
storyboard.gotoScene( “mainmenu”, “fade”, 500 )

end
end
[/lua]
[import]uid: 128294 topic_id: 28718 reply_id: 120594[/import]

Help. Anyone??? [import]uid: 128294 topic_id: 28718 reply_id: 121190[/import]