Help with path_position variables

Pkirkby

Member
Hey everyone, I've got what is probably a simple question: I have some code that changes some variables as the path_position of my "oSun" and part of my code runs fine, but the other part doesnt seem to do anything.

So in my Create Event I have:

nightAlpha = 0;
path_position = room.x/2 + room.y/2;
path_start(pathSun, 100, path_action_stop, 0);

and in my Draw I have:

draw_self();
image_alpha = 0.4;
Sun();

if(path_position == 0.75)
{
nightAlpha += 0.1;
draw_sprite_ext(sNight,image_index,0,0,room_width,room_height,image_angle,image_blend,nightAlpha)
}

if (path_position == 1)
{
instance_destroy(self)
instance_create_depth(x,y,depth,oMoon)
global.light_alpha = 0;
}

The second if statement works great, but the " if (path_position == 0.75) doesnt seem to run any code when my path_position hits 0.75. Is it proper to run this in the draw event? I've tried it in Step event and it doesnt do anything either. Any help would be great, thanks.
 

Simon Gust

Member
What do you want to happen?
In your code sNight is only drawn at one frame of the whole path, either you're too tired to catch a one-frame image or path_position never exactly hits 0.75 and misses.
I think you probably meant this
Code:
if(path_position >= 0.75)
{
   nightAlpha += 0.1;
   draw_sprite_ext(sNight,image_index,0,0,room_width,room_height,image_angle,image_blend,nightAlpha)
}
 
S

Stratadox

Guest
Is it proper to run this in the draw event?
Partially. The draw event is meant to output the state to the screen.

What you're probably after is a mechanism in the step event that determines the state:

Code:
if (path_position >= 0.75) {
  sundown = true;
  nightAlpha += 0.1;
}
And in draw event:
Code:
if (sundown) {
  draw_sprite_ext(sNight,image_index,0,0,room_width,room_height,image_angle,image_blend,nightAlpha)
}
 

Pkirkby

Member
What do you want to happen?
In your code sNight is only drawn at one frame of the whole path, either you're too tired to catch a one-frame image or path_position never exactly hits 0.75 and misses.
I think you probably meant this
Code:
if(path_position >= 0.75)
{
   nightAlpha += 0.1;
   draw_sprite_ext(sNight,image_index,0,0,room_width,room_height,image_angle,image_blend,nightAlpha)
}
Thanks for your help, I think I got it now!
 
Top