• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

trying to scale and affect opacity on all instances on specific layers

J

jwrose

Guest
Hello!
In order for a specific gameplay feature to work, I need to make all enemy instances on a specific layer, additional instances on another layer, and all tiles on a tile layer to essentially "zoom" toward the screen quickly and, at the same time, change opacity (image_alpha) so they do a fade to nothing effect. Ideally this would look like all these elements are coming at the player but quickly fading out.

I've been working through some of the related built-in variables and did several attempts but, so far, nothing has come close to working.

Does anyone have any ideas or know of any tools/shaders that could do something similar?

Thanks!!
 
D

Death

Guest
Just a thought: Couldn't you just change the original object's alpha and scale to make all instances simultaneous do that? Or maybe I misunderstood the question?
 
J

jwrose

Guest
Hmm.. that may work. I am reusing the same enemies on another layer, but I could just have separate objects and maybe use scripts to share the code...
I'll see what I can do. Thanks!
 
Which part are you stuck on?

1. Collecting references/having access to all the objects and tiles that require scaling/fading.
2. Scaling the objects sizes over time.
3. Fading the objects using alpha
4. If necessary, changing the depth/ layer of objects so they are drawn correctly with respect to the non-scaling objects.
 
J

jwrose

Guest
Which part are you stuck on?

1. Collecting references/having access to all the objects and tiles that require scaling/fading.
This has been my primary focus so far and giving me the biggest issue.

Thanks!
 
This has been my primary focus so far and giving me the biggest issue.

Thanks!
One way would be to use layer_get_all_elements() function, then grab the enemy instance ids. Check the docs for how to do it, and remember this function returns element ids, so you still need to convert them to instance ids using layer_instance_get_instance().

Alternatively, you could use a with() statement.

Code:
with ( obj_enemy_parent)
{
    if ( layer == layer_get_id("ENEMY LAYER NAME" )
    {
        // Collect all the enemy instance ids here, and / or do the scaling and fading if appropriate.
    }
}
Is that enough to get you started?

If you need more info let me know, or if you have already gotten this far with your code, it would be useful to see what code you have tried so far, then we can know what level of detail to write the replies to you.
 
J

jwrose

Guest
Thanks!
I played around with the with() statement example, but I've run into a slight issue. For now, I'm just changing xscale to a single value as a first step to get this implemented. Below is the code with my modifications. What's throwing me is my enemies are across two layers: "Enemy" and "Enemy2". I only want to affect enemies on the "Enemy" layer. Even though we have the if statement for "Enemy" the change is occurring on instances for both "Enemy" and "Enemy2". Is it just essentially running the xscale code on any obj_enemy_parent as long as the Enemy layer exists?

with (obj_enemy_parent)
{
if (layer == layer_get_id("Enemy"))
{
obj_enemy_parent.image_xscale = 0.5;
}

}
 
Have you manually changed the depth of the instances or used instance_create_depth()? If you did, layer will return -1, and it also looks like layer_get_id() has the possibility of returning -1, so perhaps both functions are returning -1 and therefore every instance of the enemy will always return true in your if statement.
 

Yal

šŸ§ *penguin noises*
GMC Elder
Apart from the depth sorting, this seems like it would be pretty easy if you did all of these at once:
Code:
//Scale up
image_xscale += 1
image_yscale += 1
//Fade out
image_alpha -= 0.025
//Keep centered
x -= 0.5*sprite_xoffset
y -= 0.5*sprite_yoffset
 
Thanks!
I played around with the with() statement example, but I've run into a slight issue. For now, I'm just changing xscale to a single value as a first step to get this implemented. Below is the code with my modifications. What's throwing me is my enemies are across two layers: "Enemy" and "Enemy2". I only want to affect enemies on the "Enemy" layer. Even though we have the if statement for "Enemy" the change is occurring on instances for both "Enemy" and "Enemy2". Is it just essentially running the xscale code on any obj_enemy_parent as long as the Enemy layer exists?

with (obj_enemy_parent)
{
if (layer == layer_get_id("Enemy"))
{
obj_enemy_parent.image_xscale = 0.5;
}

}
As you are running the code inside a with() block, you need to drop the obj_enemy_parent prefix and just use image_x scale += 0.5 by itself.
 
J

jwrose

Guest
As you are running the code inside a with() block, you need to drop the obj_enemy_parent prefix and just use image_x scale += 0.5 by itself.
Hmm.. actually, that's what I originally had and nothing happened. Putting the reference to the object affects both (which makes sense- I wasn't thinking about it before) but having no reference to obj_enemy_parent doesn't affect either layer. I'm doing this on the step event, FYI.

[EDIT]
OK, disregard... I have no idea what changed, but when I used the code from Yal, it worked... same image_xscale command. Hmm...

Anyway, thanks again!
 
J

jwrose

Guest
Apart from the depth sorting, this seems like it would be pretty easy if you did all of these at once:
Code:
//Scale up
image_xscale += 1
image_yscale += 1
//Fade out
image_alpha -= 0.025
//Keep centered
x -= 0.5*sprite_xoffset
y -= 0.5*sprite_yoffset
Thanks! This is great- I've got some adjustments for my specific needs- but this is an awesome start!
 
J

jwrose

Guest
Have you manually changed the depth of the instances or used instance_create_depth()? If you did, layer will return -1, and it also looks like layer_get_id() has the possibility of returning -1, so perhaps both functions are returning -1 and therefore every instance of the enemy will always return true in your if statement.
I wasn't using instance_create_depth() here, but this is useful as I have played around with it a bit in the past and I think I ran into this. Thanks!
 
Hmm.. actually, that's what I originally had and nothing happened. Putting the reference to the object affects both (which makes sense- I wasn't thinking about it before) but having no reference to obj_enemy_parent doesn't affect either layer. I'm doing this on the step event, FYI.

[EDIT]
OK, disregard... I have no idea what changed, but when I used the code from Yal, it worked... same image_xscale command. Hmm...

Anyway, thanks again!
You're welcome.

In the original code you posted you had = 0.5 rather than += 0.5, could that have been part of the problem?
 
J

jwrose

Guest
Could be- but changing the value only should only affect the value of the scale and not the object/instance selection, right?
Hmm... I'm going to play around with that more in a bit to see - but I'm not at my computer now.

Thanks again!
 
Could be- but changing the value only should only affect the value of the scale and not the object/instance selection, right?
Hmm... I'm going to play around with that more in a bit to see - but I'm not at my computer now.

Thanks again!
Yeah that's right. There must have been another reason for it, maybe like @RefresherTowel said.

Sounds like you are getting results now, so that's great!
 
Top