score and lives

Non-platform specific questions.

score and lives

Postby praaab » Sun Oct 30, 2011 1:20 pm

how would you create a score and lives and display them in an ipod rotated left view?
praaab
 
Posts: 82
Joined: Sat Jun 18, 2011 2:14 pm
Score: 1 Give a positive score

Re: score and lives

Postby savvy » Sun Oct 30, 2011 4:14 pm

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
--> For my help, i ask for a simple +1 if it helps! ^-^
--> I dont code, I type art which you dont understand.
--> I keep winning the 3D model challenge at college, teacher says: "you keep winning im not giving you prizes".
User avatar
savvy
 
Posts: 494
Joined: Wed Jun 03, 2009 11:55 am
Location: England
Score: 44 Give a positive score

Re: score and lives

Postby lcl » Sun Oct 30, 2011 6:03 pm

@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 -
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: score and lives

Postby praaab » Tue Nov 01, 2011 7:24 pm

both of you, thanks a lot +1 for both :D
praaab
 
Posts: 82
Joined: Sat Jun 18, 2011 2:14 pm
Score: 1 Give a positive score

Re: score and lives

Postby praaab » Tue Nov 01, 2011 8:38 pm

one more thing, im not understanding wats making the lives being set to 3?
praaab
 
Posts: 82
Joined: Sat Jun 18, 2011 2:14 pm
Score: 1 Give a positive score

Re: score and lives

Postby skydereign » Tue Nov 01, 2011 8:53 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest