Page 1 of 1

score and lives

PostPosted: Sun Oct 30, 2011 1:20 pm
by praaab
how would you create a score and lives and display them in an ipod rotated left view?

Re: score and lives

PostPosted: Sun Oct 30, 2011 4:14 pm
by savvy
add a normal actor, click text and make the text somehting like 00 or however many digits it will need (it will expand if it goes over that amount of digits) then add code in actors such as...
Destroy actor (enemy
Code: Select all
score.textNumber+=20;

then for level when the level goes up use
Code: Select all
level.textNumber=0;

as examples.

to make it in rotate left set your screen size to iphone rotate left, its towards the bottom of preset screen size list in game properties.
then just put the text actor where you want!

this help?
savvy

Re: score and lives

PostPosted: Sun Oct 30, 2011 6:03 pm
by lcl
@savvy:
I wouldn't advice anyone to use textNumber, because then they will start using it as variable, but as you may have noticed, it doesn't fit for use like variables. :)

@praaab:
You'd need to make variables for score and lives and then print them on screen.
It goes like this:

We need two integer variables, score and lives
1. Go to script editor (in any event), click variables and click add.
2. Then name it score, leave it to be global and integer. Then just press add.
3. Do the same again but name variable as lives.
4. Now you can use your score and lives variables to hold the numbers.
You can have something like:
Player - collision any side of enemy - script editor:
Code: Select all
lives -= 1;

That code would take 1 life away when you collide with enemy actor.
5. What comes to showing variables on screen, create two actors, showScore and showLives.
Give these actors some font in "Text" option and set their text to be a few 0's.
Then go to showScore - draw actor - script editor:
Code: Select all
sprintf(text, "%i", score);

That code will make the actor show the score.

And finally, for showing the lives, go to showLives - draw actor - script editor:
Code: Select all
sprintf(text, "%i", lives);


That sprintf() is a function for setting text.
What we did now was set the event actor text to be the number we wanted.
sprintf() needs two arguments, destination string and source string.
The destination string was text, which means current actors text. We could've used showScore.text. as well, but there was no need for it because we were in the showScore actors event.
The source string is the one inside " and ". We had here %i which means that we want to add an integer variable to the string. And finally, after the source string marked with " and " we had score, which means that we will place the value of the variable named score to the source string to the place where the %i is.

I wish that helped you! :)
Ask if you still need help understanding it.

- lcl -

Re: score and lives

PostPosted: Tue Nov 01, 2011 7:24 pm
by praaab
both of you, thanks a lot +1 for both :D

Re: score and lives

PostPosted: Tue Nov 01, 2011 8:38 pm
by praaab
one more thing, im not understanding wats making the lives being set to 3?

Re: score and lives

PostPosted: Tue Nov 01, 2011 8:53 pm
by skydereign
You've already done that kind of thing (at least you have it in your game). You need to set the lives variable to 3, just like you would for hp. All this is, is using a variable, so if you need to set it to 3 when your player is created (that way you actually have lives) then all you need to do is set it in the player's create actor event.