Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411522 Posts in 69377 Topics- by 58431 Members - Latest Member: Bohdan_Zoshchenko

April 28, 2024, 08:35:33 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)New problem... rotating/ line of sight....
Pages: [1]
Print
Author Topic: New problem... rotating/ line of sight....  (Read 3036 times)
pgil
Guest
« on: December 27, 2009, 12:15:02 PM »

So in my game, I have a sign object. When the player gets close to it, it displays text. Simple.

My problem is with the depth. I want the text to be displayed on top of everything else, while the object's sprite in the world should be drawn behind most other objects. Here's my code:

Code:
depth = 100000
draw_sprite(sprite_index,image_index,x,y)
if collision_rectangle(x-8,y-8,x+16,y+16,ob_player,false,true){    
   depth = -100000
   draw_text_ext(view_xview[0]+8,view_yview[0]+170,text,10,300)
}

Instead of drawing the sign behind everything, though, it draws it in front of everything just like the text. No matter what order I put the two depth declarations in, it always seems to draw everything with the first one. Am I doing something wrong, or is this just how Game Maker works?
« Last Edit: December 29, 2009, 10:20:22 AM by pgil » Logged
Desert Dog
Level 4
****



View Profile
« Reply #1 on: December 27, 2009, 12:34:12 PM »

It's how GM works. An instance can only draw at one depth per draw event.

You'll have to use another object for displaying that stuff.

Logged

pgil
Guest
« Reply #2 on: December 27, 2009, 01:10:36 PM »

Ah, that's what I thought. I just made it so the player object draws the text (passing it from the sign), and everything works fine now  Beer!
Logged
ஒழுக்கின்மை (Paul Eres)
Level 10
*****


Also known as रिंकू.


View Profile WWW
« Reply #3 on: December 28, 2009, 05:33:23 AM »

you can only change the depth in the step event, not the draw event. you can't change it in the draw event because the flow of a gm game is:

- go through every object's step event
- go through every object's draw event, in order of their depth

changing the depth in the draw event won't change the order that it's currently going through, because it'd make no sense.
Logged

pgil
Guest
« Reply #4 on: December 28, 2009, 08:06:32 AM »

Yeah, that makes sense now. I tend to get confused and do things ass-backwards when I've been working in GM too long.
Logged
pgil
Guest
« Reply #5 on: December 29, 2009, 10:19:43 AM »

Another stupid question that probabvly has an obvious answer:

I have an object that I want to rotate at a constant rate... Kind of like those rotating statues in Zelda that shoot at you.

Here's my create event:
Code:
dir = 0
//set a direction

Then I make it rotate in the step event:
Code:
dir +=1

The problem is where I try to find its line of sight. Here's my collision code (also in the step event):
Code:
if collision_line(x,y,lengthdir_x(40,dir),lengthdir_y(40,dir),ob_player,true,true)&&guntimer <= 0{
   i=instance_create(x,y,ob_pl_shot_missile)
   i.dir = point_direction(x,y,ob_player.x,ob_player.y)
   i.hspd = lengthdir_x(5,i.dir)
   i.vspd = lengthdir_y(5,i.dir)
   guntimer = 20
}
That creates a missile, but it goes in the wrong direction. To test my line of sight, I decided to draw it:
Code:
draw_line(x,y,lengthdir_x(40,dir),lengthdir_y(40,dir))

And sure enough, the line doesn't just rotate slowly, it waves back and forth in a right sinewave pattern.

I checked the "dir" variable, and it's adding one each steo like I told it to. So I guess I'm doing something wrong in the "lengthdir" functions. Anyone know what I'm doing wrong?
« Last Edit: December 29, 2009, 10:23:04 AM by pgil » Logged
Desert Dog
Level 4
****



View Profile
« Reply #6 on: December 29, 2009, 11:21:40 AM »

Quote
Anyone know what I'm doing wrong?
Yes, it's a simple mistake, but actually took me far longer than it should have to pick up.  Smiley

It's
Code:
draw_line(x,y,x+lengthdir_x(40,dir),y+lengthdir_y(40,dir))
Logged

pgil
Guest
« Reply #7 on: December 29, 2009, 11:43:02 AM »

Thank you!  Beer!

I knew it would be something simple like that.
Logged
Desert Dog
Level 4
****



View Profile
« Reply #8 on: December 29, 2009, 12:03:24 PM »

Your welcome!  Coffee
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic