Help with image_sprite change

J

Jax_the_grey_cat

Guest
Hello, first congrats on the new forums!

I've been having a little trouble with switching sprites maybe you guys can help me out.

This is my code for this action in particular

if canattack = true and instance_exists(objPlayer)
{
if distance_to_object(objPlayer)<12
{
if sprite_index = sprOrcScoutDown
{
sprite_index = sprOrcScoutAttackDown;
image_speed = 0.2;
attacking = true;
{
if (image_index > 10.8 && image_index <= 11.2)
{
canattack = false;
sprite_index = sprOrcScoutDown;
attacking = false;
alarm[0]=90;
}
}
}
}
}

sorry for the unclean code, it's the best I can do so far.

My problem comes when switching from the "sprOrcScoutDown" sprite to the "sprOrcScoutAttackDown" sprite, when it switches it doesn't start from the subimage 0 of the sprOrcScoutAttackDown sprite, it starts from a random subimage.

If anyone could give me a tip on how to solve this I would really appreciate it.

Thank you very much!
 

Phil Strahl

Member
Hello, first congrats on the new forums!

I've been having a little trouble with switching sprites maybe you guys can help me out.

This is my code for this action in particular

if canattack = true and instance_exists(objPlayer)
{
if distance_to_object(objPlayer)<12
{
if sprite_index = sprOrcScoutDown
{
sprite_index = sprOrcScoutAttackDown;
image_speed = 0.2;
attacking = true;
{
if (image_index > 10.8 && image_index <= 11.2)
{
canattack = false;
sprite_index = sprOrcScoutDown;
attacking = false;
alarm[0]=90;
}
}
}
}
}

sorry for the unclean code, it's the best I can do so far.

My problem comes when switching from the "sprOrcScoutDown" sprite to the "sprOrcScoutAttackDown" sprite, when it switches it doesn't start from the subimage 0 of the sprOrcScoutAttackDown sprite, it starts from a random subimage.

If anyone could give me a tip on how to solve this I would really appreciate it.

Thank you very much!
Just add image_index = 0; after switching to the new sprite
 
J

Jax_the_grey_cat

Guest
Just add image_index = 0; after switching to the new sprite
Hello Phil, thank you for you answer, I've already tried that like this:

sprite_index = sprOrcScoutAttackDown;
image_index = 0;
image_speed = 0.2;
attacking = true;

But it doesn't work, it's stuck at subimage 0 and it doesn't animate.
 
W

Wild_West

Guest
Hello Phil, thank you for you answer, I've already tried that like this:

sprite_index = sprOrcScoutAttackDown;
image_index = 0;
image_speed = 0.2;
attacking = true;

But it doesn't work, it's stuck at subimage 0 and it doesn't animate.
That part with your image_index checking is using decimals, have you tried just rounding it to the nearest whole number?
Also make sure you don't set image_speed or index to any fixed value in the step event of course as that happens every second of the game and tends to overwrite everything else. I've had that happen a few times xD
 
J

Jax_the_grey_cat

Guest
That part with your image_index checking is using decimals, have you tried just rounding it to the nearest whole number?
Also make sure you don't set image_speed or index to any fixed value in the step event of course as that happens every second of the game and tends to overwrite everything else. I've had that happen a few times xD
Hello! Thanks for your answer.

I tried rounding it but read in the old forums some time ago that because of how game maker works the best idea was to do it that way and that sort of stuck with me. Still rounding it I have the same problem with the sprite not starting from the beginning.

All of that code happens in the step event, I can't imagine how to do the sprite change and assign it the speed I want if not on step event :(
 
W

warbo

Guest
Hey there, i was having problems with my Sprite not playing when i wanted, and after some back and forth conversation's with a very helpful member, i got it to work thanks to his example.

I know it's not what you asked BUT it WILL solve your problem and make things easy for you.

See the thread HERE and read the reply's and look for his example he sent to me. Ill be happy to help you implement it further if needed, just message me.
 
W

Wild_West

Guest
Hello! Thanks for your answer.

I tried rounding it but read in the old forums some time ago that because of how game maker works the best idea was to do it that way and that sort of stuck with me. Still rounding it I have the same problem with the sprite not starting from the beginning.

All of that code happens in the step event, I can't imagine how to do the sprite change and assign it the speed I want if not on step event :(
Did you code all of that at once or step by step?
If not It might be beneficial to go back and redo everything from scratch and make sure each line is doing what it should be.
Or what I like to do when I'm stuck is just scribble out a little drawing of each action just so I don't get lost in line after line after line lol
But I have a bad memory so you might not have that issue to worry about.
 
Top