Jump to content


Photo

Score and lives moving with player


  • Please log in to reply
7 replies to this topic

#1 Ferda12

Ferda12

    GMC Member

  • New Member
  • 4 posts
  • Version:Unknown

Posted 27 July 2012 - 02:53 PM

Hello all,

I´m quite new in Game Maker. I have created already small platform game, but I have one fatal problem. I have room and I´m using views. So the camera is moving with player and everything work, BUT I really don´t know how to make score counter and lives move too with player. Can someone tell me how to do that? Like in the top on some position will be score and next to it lives but this will move as player move too. Thanks a lot!
  • 0

#2 Dark Dragon

Dark Dragon

    GMC Member

  • New Member
  • 5 posts

Posted 27 July 2012 - 03:09 PM

If you're using GML, try this


x = view_xview[0] + view_wiew[0] - <any value>
y = view_yview[0] + <any value>

draw_text(x,y,score)


Otherwise if you use D&D, try entering the above values as x and y as arguments.

Also,if you have only one active view, you can skip [0] index for simplicity.
Hope that helps..

Edited by Dark Dragon, 27 July 2012 - 03:11 PM.

  • 0

#3 TerraFriedSheep

TerraFriedSheep

    GMC Member

  • GMC Member
  • 2825 posts
  • Version:GM:Studio

Posted 27 July 2012 - 03:33 PM

To expand on Dark Dragon's response:

view_xview is the left position of the view currently visible, view_yview is the top position of the view currently visible. So, if you placed this code in the draw_event of an object:

draw_text(view_xview+10,view_yview+10,"Score: "+string(score));

You would draw the text in the top left hand corner of the view (at point 10,10 relative to the view).

view_wview is the width of the current view, view_hview is the height of the current view. Therefore, view_xview+view_wview is the right hand side of the view and view_yview+view_hview is the bottom of the view.

Edit: Spelling.

Edited by TerraFriedSheep, 27 July 2012 - 03:33 PM.

  • 0

#4 Ferda12

Ferda12

    GMC Member

  • New Member
  • 4 posts
  • Version:Unknown

Posted 27 July 2012 - 03:34 PM

Working, thanks!

Just where to put in this code text? Like if I want to have there "Score:"

EDIT: Thanks, got reply to this at the same time I wrote the question :D

Edited by Ferda12, 27 July 2012 - 03:35 PM.

  • 0

#5 TerraFriedSheep

TerraFriedSheep

    GMC Member

  • GMC Member
  • 2825 posts
  • Version:GM:Studio

Posted 27 July 2012 - 03:42 PM

Working, thanks!

Just where to put in this code text? Like if I want to have there "Score:"

EDIT: Thanks, got reply to this at the same time I wrote the question :D


Glad you got it sorted :)

You can combine text and variables in the same draw_text function using +, like so:

draw_text(view_xview+10,view_yview+10,"This is some text "+string(variable_name_here)+" a variable, and a bit more text!");

  • 0

#6 Ferda12

Ferda12

    GMC Member

  • New Member
  • 4 posts
  • Version:Unknown

Posted 28 July 2012 - 06:16 AM

Thanks to everybody, but got just some more problems:

1) How to change color of text of "Score: ..."? Or how to use some background for it?
2) How to do the same thing with lives if I want lives as images. I have tried to modify the previous code, but unsuccessfuly, can you help me with this too pls?

Thanks a lot in advance!
  • 0

#7 drt_t1gg3r

drt_t1gg3r

    GMC Member

  • GMC Member
  • 3230 posts
  • Version:Unknown

Posted 28 July 2012 - 09:42 AM

you can change the color of text two different ways
draw_set_color( c_red );
draw_text( someX, someY, "mytext" );
//   	*** or ***
draw_text_color( someX, someY, "myText", c_red, c_red, c_red, c_red, 1 );
to draw lives as an image you would just repeat the drawing of a sprite lives amount of times
for( i = 0; i < lives; i += 1 )
  draw_sprite( spr_someSprite, image_index, someX + xBuffer * i, someY + yBuffer * i );
// NOTE: spr_someSprite = name of sprite you wish to show
// someX/someY = the actual location you wish to view the sprite
// xBuffer/yBuffer = how far apart horizontally or vertically you want the sprites to be view
// ( put zero (0) if you don't want any )

Edited by drt_t1gg3r, 28 July 2012 - 09:43 AM.

  • 0

#8 Ferda12

Ferda12

    GMC Member

  • New Member
  • 4 posts
  • Version:Unknown

Posted 29 July 2012 - 09:52 AM

Thank you. I have after some experiments decided to make it from text cause it looks much better. But after trying codes for images It is showing me this when I want to make it as text: "Lives: 38" although there should be 3 at the start. I have checked everything, but I really don´t understand where it is getting number 38. I´m using this code:
draw_set_color( c_yellow );
draw_set_font(arialblack);
draw_text(view_xview+40,view_yview+20,"Lives:
 "+string(lives));

Is it wrong? I have really in create event in player: set live to 3 and It worked before I tried to make lives as picture. Have someone idea what can be wrong here? (It is showing everytime number 38 after "Lives:" even there is contact with enemy, this number is not getting down, but It worked before..)

EDIT: If I use directly function draw lives, It works, can someone tell me what is wrong in my code above?

Edited by Ferda12, 29 July 2012 - 02:27 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users