Save highscore on corona sdk?

前端 未结 3 2003
你的背包
你的背包 2021-01-27 19:51

I want to save the highscore created in the game and can be seen in the main menu when the player hits the highscore button, can someone help me?

相关标签:
3条回答
  • 2021-01-27 20:25

    You can solve your problem in a easier way..

    Just declare a Variable for the Score like this..

    local score=0
    

    Then Increment the score variable by 1 whenever it hits the paddle. So Insert the coding in Collision Function as given below:

    local function onCollision(event)
    {
    score=score+1
    }
    ball.collision=onCollision
    ball:addEventListener("collision",ball)
    

    Finally When you need to save your highscore (after gameover), You can use Preference instead of json which makes the larger coding.

    local preference= require "preference"
    local highscore=0
    
    preference.save{highscore=score}
    

    If you want to display the Highscore, then use the following:

    highscore_value=preference.getValue("highscore")
    display.newText(highscore_value,0,0,nil,30)
    

    This might be useful for your problem !!

    0 讨论(0)
  • 2021-01-27 20:30

    you can use SQLITE to save the highscore to database another way is make a file that write the score to a Text File and save it to the directory of the system

    0 讨论(0)
  • 2021-01-27 20:49

    Multiple libraries exist for this purpose. GGScore is an open source library built by GlitchGames which can easily allow you to do this: GlitchGames/GGScore

    All the documentation you need is in the main page (README.md) so there isn't really a need for me to explain the code. But it's really easy to use.

    0 讨论(0)
提交回复
热议问题