Save highscore on corona sdk?

本小妞迷上赌 提交于 2019-12-20 07:10:07

问题


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?


回答1:


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




回答2:


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 !!




回答3:


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.



来源:https://stackoverflow.com/questions/17782311/save-highscore-on-corona-sdk

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!