[SOLVED} thank you Jezla! Fade effect for a specific instance

V

VansiusProductions

Guest
Hi guys,
How do I make a specific instance fade? I don't know how to only target a specific instance's instance variable. This is my code in a step event:
Code:
with (global.groupStop) {
    if (global.groupStop.alpha < 1) {
            global.groupStop.alpha += 0.05
    }
}
draw_sprite_ext(sprite_index,image_index,x,y,image_xscale,image_yscale,image_angle,c_white,global.groupStop.alpha)
I did global.groupStop.alpha so that it only uses the global.groupStop instance's alpha variable. The global.groupStop holds an instance id. Also, 1 thing i would note is that this instances is not created when the game starts, but later on in the game. So when i start the game, the variable is not defined and I get an error, how do I prevent this from happening?
Or suggest another system I should use. Thank you!
 

Jezla

Member
You don't need to use an accessor inside a with statement. Change the if conditional to check alpha instead of global.groupStop.alpha. Leave the draw function as it is since it is outside the with statement.

Also, if you want it to fade you need to decrease the alpha.
 
V

VansiusProductions

Guest
image_alpha
It didn't work, but the game didn't crash this time.
You don't need to use an accessor inside a with statement. Change the if conditional to check alpha instead of global.groupStop.alpha. Leave the draw function as it is since it is outside the with statement.

Also, if you want it to fade you need to decrease the alpha.
If I used alpha, it will do it to all instances. I don't know why though, even though I have the with statement
 

Jezla

Member
I did global.groupStop.alpha so that it only uses the global.groupStop instance's alpha variable. The global.groupStop holds an instance id. Also, 1 thing i would note is that this instances is not created when the game starts, but later on in the game. So when i start the game, the variable is not defined and I get an error, how do I prevent this from happening?
To prevent the crash, you need to have global.groupStop = noone in the code or script where you initialize your global variables.

This:
Code:
with (global.groupStop)
     {
          if (alpha > 0) alpha -= 0.05;
     }

draw_sprite_ext(sprite_index, image_index, x, y, image_xscale, image_yscale, image_angle, c_white, global.groupStop.alpha);
Should get you a fade effect.

If it's affecting all objects, then either you've assigned an object index to global.groupStop rather than an instance id, or the instance is a parent object. How do you set global.groupStop?
 
V

VansiusProductions

Guest
To prevent the crash, you need to have global.groupStop = noone in the code or script where you initialize your global variables.

This:
Code:
with (global.groupStop)
     {
          if (alpha > 0) alpha -= 0.05;
     }

draw_sprite_ext(sprite_index, image_index, x, y, image_xscale, image_yscale, image_angle, c_white, global.groupStop.alpha);
Should get you a fade effect.

If it's affecting all objects, then either you've assigned an object index to global.groupStop rather than an instance id, or the instance is a parent object. How do you set global.groupStop?
Sorry, it's still not fading.
This is what i'm trying to accomplish:

The group icons on the right are global.groupStop's (top one is global.groupStop, bottom one is global.groupStop2). And I want them to move and fade in, I already got the moving part working (which means global.groupStop is an instance id), all I need is the fading part to work. I want it to fade in, that's why I'm adding alpha.
 

Jezla

Member
Sorry, I misunderstood, the top post just said fade, so I assumed it was fade out. For your fade in code to work, you'll have to set the alpha to zero before it will fade in; add that to you click object code. Depending on your room speed, you may need to increase or decrease the amount that alpha changes. if you have a high room speed and a large increment, the object will fade in so quickly the effect won't be noticeable.
 
V

VansiusProductions

Guest
Sorry, I misunderstood, the top post just said fade, so I assumed it was fade out. For your fade in code to work, you'll have to set the alpha to zero before it will fade in; add that to you click object code. Depending on your room speed, you may need to increase or decrease the amount that alpha changes. if you have a high room speed and a large increment, the object will fade in so quickly the effect won't be noticeable.
I just successfully did a fade in effect with my other object. Using the same logic i applied to these group objects but it didn't work.
heres the click code:
Code:
if (global.groupHover != 0 && x < 352) {
    if (global.groupSelectedA == 0) {
        global.groupSelectedA = global.groupHover;
        global.groupClicked = 0
        movingGroup = instance_position(mouse_x,mouse_y,obj_group)
        moveX = movingGroup.x
        moveY = movingGroup.y
//IMPORTANT PART
        global.groupStop = instance_create(moveX, moveY, global.nameTemp3g);
        with (global.groupStop) {
            move_towards_point(352,64,27)
// i set the alpha
            global.groupStop.image_alpha = 0 
        }
        scr_displayElements()
    }
    else {
        if (global.groupSelectedB == 0 && x < 352) {
            global.groupSelectedB = global.groupHover;
            global.groupClicked = 1
            movingGroup2 = instance_position(mouse_x,mouse_y,obj_group)
            moveX2 = movingGroup2.x
            moveY2 = movingGroup2.y
            global.groupStop2 = instance_create(moveX2, moveY2, global.nameTemp3g);
            with (global.groupStop2) {
                move_towards_point(352,384,27) 
            }
            scr_displayElements()
        }
    }
}
Heres the step code:
Code:
with (global.groupStop) {
    global.groupStop.image_alpha += 0.05
}
 

Jezla

Member
I just successfully did a fade in effect with my other object. Using the same logic i applied to these group objects but it didn't work.
heres the click code:
Okay, I don't know which objects you're referring to now, you need to be more specific. Which instance did you get to fade in, and which instance is not working? Are you putting the draw_sprite_ext() function in the draw event?
 
V

VansiusProductions

Guest
Okay, I don't know which objects you're referring to now, you need to be more specific. Which instance did you get to fade in, and which instance is not working? Are you putting the draw_sprite_ext() function in the draw event?
The other objects are the elements (the air and water things with the word air and water, next to the group). I got them to work. I removed that line because i didn't even use it for the elements, it works fine without it.

I ran the game in debug mode and when the game is executing global.groupStop.image_alpha += 0.05, its alpha jumps straight to 1. That is weird since it doesnt happen for the elements
Another thing I'm noticing that after the instance is created which is stored in global.groupStop, and when I try to do show_debug_message(global.groupStop.image_alpha) it says that global.groupStop is not defined!?? But it should be or else how would the moving part work (move_toward_point)
 
Last edited by a moderator:

Jezla

Member
I removed that line because i didn't even use it for the elements, it works fine without it.
That makes sense, if you adjust image_alpha directly, then there's no need for a draw call.

I still say you don't need to use the accessor inside the with construction.

This:

Code:
global.groupStop = instance_create(moveX, moveY, global.nameTemp3g);
        with (global.groupStop) {
            move_towards_point(352,64,27)
            global.groupStop.image_alpha = 0
        }
should be either this:

Code:
global.groupStop = instance_create(moveX, moveY, global.nameTemp3g);
        with (global.groupStop) {
            move_towards_point(352,64,27)
            image_alpha = 0
        }
or this:

Code:
global.groupStop = instance_create(moveX, moveY, global.nameTemp3g);
        with (global.groupStop) {
            move_towards_point(352,64,27)
        }
     global.groupStop.image_alpha = 0
 
V

VansiusProductions

Guest
That makes sense, if you adjust image_alpha directly, then there's no need for a draw call.

I still say you don't need to use the accessor inside the with construction.

This:

Code:
global.groupStop = instance_create(moveX, moveY, global.nameTemp3g);
        with (global.groupStop) {
            move_towards_point(352,64,27)
            global.groupStop.image_alpha = 0
        }
should be either this:

Code:
global.groupStop = instance_create(moveX, moveY, global.nameTemp3g);
        with (global.groupStop) {
            move_towards_point(352,64,27)
            image_alpha = 0
        }
or this:

Code:
global.groupStop = instance_create(moveX, moveY, global.nameTemp3g);
        with (global.groupStop) {
            move_towards_point(352,64,27)
        }
     global.groupStop.image_alpha = 0
Both didn't work. I'm so confused
 
V

VansiusProductions

Guest
Well, it seems like gamemaker is faster than me, the image alpha increment is too high.
 
Top