简体   繁体   中英

Saving high score and other things - corona

I want to save a high score in my game. I saw that you need to use json library but I dont know how to use it. i want to save a table and not just a written text. Ther is an easy way of doing that?

adit: I have found Ego: http://techority.com/2011/12/28/ego-easy-saving-and-loading-in-your-corona-apps/ it works very good! but I am concern. i am not Savvy at thise things. someone can the me if it is Reliable?

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

Refer here : Save highscore on corona sdk?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM