image_speed not working

Axl Trauts

Member
Hi, I am really confused here. I made my player object fire a missile that "goes to the sky", that is, disappears and when it does, it creates rain. Like a rain missile :p

Anyways, the thing is that the rain sprite does not animates at all, it has 4 subimages.

This is what I did on the Missile object :
Create event
Code:
image_alpha=1;
misil=1;
Step Event
Code:
// The Missile is fired and moves a bit until it disappears
if(image_alpha != 0)
{   image_alpha = image_alpha - 0.05;
    move_towards_point(x,y-50,5);
}   
else 
{   speed = 0;
    misil=0;        // Used to draw the rain
}
Draw Event
Code:
draw_self();
image_speed=1; // does nothing :(
if misil==0
{   draw_sprite(spr_lluvia,image_index,x,y); // no animation :(
}
 
If you are drawing the sprite manually then image speed does nothing. I think it only works when it has been given a sprite index, and if you're not doing that you'll have to sort out the frames yourself.

By the looks of things: I'd hazard a guess you've not given it a sprite due to wanting to change it when 'misil == 0', but that is not the only way to change what it is drawing. Give it the sprite that you want in the resource tree before creation, and then in game you can change it (when misil == 0) by setting sprite_index to the new sprite

One other thing - you are lowering the image alpha to zero. This is gradually making the instance invisible. So even if you are getting to the point where it changes what it's drawing - you are not going to be able to see it when that change happens, since the image alpha will remain at zero unless you reset it.

PS:

image_alpha -= 0.05

is a valid way to remove a value from any variable, though I don't know if it really make much difference overall
 

Azenris

Member
because you are using the image_index of one sprite ( the objects sprite ) for the image_index of another you have be to careful of some things.
Like the speed of the sprite in the resource tree of the objects sprite.
how many frames it has
 

TsukaYuriko

☄️
Forum Staff
Moderator
image_speed works if an instance has an assigned sprite and revolves around that sprite only.
image_index is a variable that is incremented by image_speed every frame. It is then assigned the result of the remainder of its current value divided by the amount of sub-images the assigned sprite has (like the modulo operator). So if your assigned sprite has two sub-images, it will wrap back around to 0 as soon as it would reach 2.

This also means that if your assigned sprite has one sub-image, image_index will only ever have values between 0 and 0.999... and therefore will only have a range of a single frame. If you then try to use this for anything else, that will not animate as well.

Handle the animation for that one yourself - make a second variable, add image_speed to it every step, then use that as your sub-image for the second sprite.
 

Axl Trauts

Member
I understand now the thing with image_index. First time I look at it. The sprite set to the object is 1 subimage only. Hence the image_index is 1 (or whatever number is returned).

I'm looking on Help with no luck, where do I get the image_index of the new drawn sprite and then get the animation?

If you are drawing the sprite manually then image speed does nothing. I think it only works when it has been given a sprite index, and if you're not doing that you'll have to sort out the frames yourself.

By the looks of things: I'd hazard a guess you've not given it a sprite due to wanting to change it when 'misil == 0', but that is not the only way to change what it is drawing. Give it the sprite that you want in the resource tree before creation, and then in game you can change it (when misil == 0) by setting sprite_index to the new sprite
I am not sure what you are sugesting about the resource tree. I am not understanding how to the the sprite_index or image_index of another sprite... I am not finding what function returns that.
I believe calling an object with the sprite spr_lluvia might solve the problem, but I think I'm losing some learning that way :)

One other thing - you are lowering the image alpha to zero. This is gradually making the instance invisible. So even if you are getting to the point where it changes what it's drawing - you are not going to be able to see it when that change happens, since the image alpha will remain at zero unless you reset it.

PS:

image_alpha -= 0.05

is a valid way to remove a value from any variable, though I don't know if it really make much difference overall
Oddly enough, the alpha has not affected the rain sprite (spr_lluvia).
 
image_speed works if an instance has an assigned sprite and revolves around that sprite only.
I am not sure what you are sugesting about the resource tree.
As TsukaYuriko said - you want a sprite assigned to sprite_index for image_speed to work automatically. You can change this ingame, but if it is the sprite you intend the object to have from the moment the room is created, then you may as well assign it before creation. That is what I meant by the resource tree (badly explained it, I guess) i.e you click on the object in the resource tree, go to a box in the top left where it says "sprite" and assign a sprite.

There's no need for draw_self if it already has a sprite attached, and that sprite can be changed at any point later on.

As to why the rain sprite still had full alpha - maybe the draw_sprite function always operates at full alpha? (there are extended draw sprite functions where the alpha is a value to be set) Or, as a value it only affects the sprite set in the sprite_index? I'm not sure.
 

TsukaYuriko

☄️
Forum Staff
Moderator
If you intend to draw multiple sprites and their sub-image count does not match, I suggest not messing around with the default drawing and instead handling it manually with custom variables instead of image_index, as it's not magical in nature by any means and can be substituted by any other variable that counts up every step.

There's no need for draw_self if it already has a sprite attached, and that sprite can be changed at any point later on.
Just to make sure this won't end up confusing anyone - this applies if an object does not have a Draw event. Then the sprite will be drawn automatically.
If there is a Draw event, default drawing is deactivated and the assigned sprite will not be drawn, making draw_self or any desired drawing function necessary if the assigned sprite should be drawn.

As to why the rain sprite still had full alpha - maybe the draw_sprite function always operates at full alpha? (there are extended draw sprite functions where the alpha is a value to be set) Or, as a value it only affects the sprite set in the sprite_index? I'm not sure.
To clarify this as well, image_alpha affects anything that uses image_alpha directly or implicitly (such as default drawing or draw_self). draw_sprite indeed draws at full alpha by default.
 
Just to make sure this won't end up confusing anyone - this applies if an object does not have a Draw event. Then the sprite will be drawn automatically.
If there is a Draw event, default drawing is deactivated and the assigned sprite will not be drawn, making draw_self or any desired drawing function necessary if the assigned sprite should be drawn.
I didn't know that, so it's good for me to have it clarified. But in the OPs original post they say the missile disappears, and then creates rain. So I'm not sure why they would be drawing the missile, and then also the rain effect, when it seems like only one or the other is meant to be shown - rather than both at the same time. They basically seem to be setting the image alpha to 0 for draw_self, and then drawing another sprite?

So I don't get why they don't just change the sprite_index at that point, and have the missile do a different behaviour when it's doing the rain. If for no other reason than avoiding needlessly doing draw_self + draw_sprite, when the former is invisible?
 
Top