This site requires JavaScript, please enable it in your browser!
Greenfoot back
sharifahhilwa
sharifahhilwa wrote ...

2014/8/25

How do i add in a ScoreBoard

sharifahhilwa sharifahhilwa

2014/8/25

#
I do know that i have to ->edit->import class. But i dont understand how to fill in the codes. I dont know how to make it work
Super_Hippo Super_Hippo

2014/8/25

#
The scoreboard which you can import will sort every user who played your game in descending order of their 'score'. For every user, you can store a 'score', 10 ints and 5 strings. If you double click on 'World' and click on 'PREV CLASS' in the top left corner, you get to the 'UserInfo' help. As a standard way to store a score, it is written like this:
     if (UserInfo.isStorageAvailable()) {
         UserInfo myInfo = UserInfo.getMyInfo();
         if (newScore > myInfo.getScore()) {
             myInfo.setScore(newScore);
             myInfo.store();  // write back to server
         }
     }
So in this case, if you get points or something in your game, you save these points in 'newScore'. And when the user dies, loses or get a game over, you place this code, so it checks whether or not the user beat this best score and if he did, this score will be his new best score and will be stored. If you want display this scoreboard, you do something like
getWorld().addObject(new ScoreBoard(getWorld().getWidth(), getWorld().getHeight()), getWorld().getWidth()/2,getWorld().getHeight()/2);
If you want more than one scoreboard in the same game to display different kind of scores, you have to store your scores in the int fields and manually get the order of everyone. This is a bit more complicated. You can also make your ScoreBoard, which is a subclass of 'Actor' to a subclass of world. I did that in my game Mr Flap. Then, instead of creating a new object of scoreboard, you change the world to this world.
You need to login to post a reply.