Jump to content


Photo

how to play sprite animation once?


  • Please log in to reply
17 replies to this topic

#1 Zhavens

Zhavens

    GMC Member

  • New Member
  • 16 posts
  • Version:GM8

Posted 24 April 2012 - 02:39 PM

I have a top down shooter with a few different sprites to animate the characters attacks. i need him to play through a sprite 1 time when i click the mouse,and return to walking or standing. the results im gettin are when i click mouse the animation just plays through. My walkin code works, but because of key_check so when i let off key it sets a variable to false telling him to stand. doin anything in end animation event screws up the whole thing(i probably dont understand how to use it)

description:
1 obj
3 sprites
3-8 sub images for each sprite

this code works for movement: Step event
var moving;
moving=false;

image_angle=point_direction(x,y,mouse_x,mouse_y);

if keyboard_check(ord("D")) && place_free(x+6,y) && x<room_width
{
    x+=6;
    moving=true;
}
if moving=true
{
    sprite_index=sprwalk image_speed=.3
}

this doesnt: Step event
if mouse_check_button(mb_left) &&  global.blast=1 && global.mana>=1 && global.chamber<=0
{
instance_create(x,y,objbullet)
global.mana-=5
global.chamber=10
sprite_index=sprcast image_speed=.3
}

so why doesnt the sprite go back to sprstand immedieatly,by logic you would think this code that when i clicked it would try to animate but on the next step just go back to sprstand(obviously not what im lookin for). instead the animation just loops over and over.

Edited by Zhavens, 24 April 2012 - 02:42 PM.

  • 0

#2 ChefDavid22

ChefDavid22

    No, YOU shut up!

  • GMC Member
  • 1193 posts
  • Version:GM:Studio

Posted 24 April 2012 - 02:41 PM

You need to change it back to the sprite you want but set the image speed to 0.

Then when the player clicks the button again it starts to play again.
  • 0

#3 Zhavens

Zhavens

    GMC Member

  • New Member
  • 16 posts
  • Version:GM8

Posted 24 April 2012 - 02:48 PM

ok i added if moving=false sprite index=sprstand. now my predicted problem occured it tries to animate but the step event of moving false = sprite_index sprstand overides. resulting in a quick flash of the first frame
  • 0

#4 ChefDavid22

ChefDavid22

    No, YOU shut up!

  • GMC Member
  • 1193 posts
  • Version:GM:Studio

Posted 24 April 2012 - 03:23 PM

While I cant say I understand completely what is happening (maybe upload your source) - it certainly sounds to me like the image_speed is not being set back to 0 on index=sprstand.

Because if it flashes to "index=sprstand" - then you know it is reaching it and then it is quickly going to the next sub frame (I am assuming).
  • 0

#5 Zhavens

Zhavens

    GMC Member

  • New Member
  • 16 posts
  • Version:GM8

Posted 24 April 2012 - 03:39 PM

sorry, its the animation of the attacks that arent animating im not havin a problem with the standing since there is no animation for it just one sprite with one sub image

ok so if moving=fasle then he stands still no prob. the step event is telling him he has to stand unless key_check_(any direction,a,s,w,d). that works fine.
so now i click the mouse button and you can see the animation try to play but since step says stand still that overides the animation. if i take away "if moving=false sprite_index=sprstand then the animation will play but over and over and over so. so i need a way to stop the step event from overiding untill the animation has completed.

whew. im sorry ima newb and im overcomplicating my explination i think

Edited by Zhavens, 24 April 2012 - 03:42 PM.

  • 0

#6 ChefDavid22

ChefDavid22

    No, YOU shut up!

  • GMC Member
  • 1193 posts
  • Version:GM:Studio

Posted 24 April 2012 - 09:36 PM

Sorry man I'll have to let someone else jump in. I wouldnt know what is going on.
  • 0

#7 ParodyKnaveBob

ParodyKnaveBob

    theUndiscovered

  • GMC Member
  • 1231 posts
  • Version:GM:Studio

Posted 25 April 2012 - 03:28 AM

hint hint:

Look into the "Animation End Event" ... $:^ ]

I hope this helps,
  • 0

#8 daro0196

daro0196

    GMC Member

  • GMC Member
  • 41 posts
  • Version:GM8

Posted 25 April 2012 - 04:49 AM

I am doing a game and i made a animation of my sprite swinging its sword, but i need that the animation only runs once, this is the code im using...please help me

if sprite_index==spr_thanatos_atk_1_sword_left
and image_index=8
{image_speed=0}
if sprite_index==spr_thanatos_atk_1_sword_right
and image_index=8
{image_speed=0}
  • 0

#9 ParodyKnaveBob

ParodyKnaveBob

    theUndiscovered

  • GMC Member
  • 1231 posts
  • Version:GM:Studio

Posted 25 April 2012 - 05:13 AM

I am doing a game and i made a animation of my sprite swinging its sword, but i need that the animation only runs once, this is the code im using...please help me

if sprite_index==spr_thanatos_atk_1_sword_left
and image_index=8
{image_speed=0}
if sprite_index==spr_thanatos_atk_1_sword_right
and image_index=8
{image_speed=0}

Howdy, daro0196,

You didn't explain what's going wrong; therefore, it's hard to help.
1. What's going right?
2. What's going wrong?
3. In what exact way is it going wrong?
(What do you expect to happen, and what is it doing instead?)

Meanwhile, here's a little tip for your code. It's not "fully optimized," but I just wanted you to see how to combine your conditions and so forth:

if ((sprite_index==spr_thanatos_atk_1_sword_left || sprite_index==spr_thanatos_atk_1_sword_right) && image_index==image_number-1) {
  image_speed=0;
}
Regards,
  • 0

#10 daro0196

daro0196

    GMC Member

  • GMC Member
  • 41 posts
  • Version:GM8

Posted 25 April 2012 - 02:19 PM

thanxs dude, my problem is that if i tap 'space' the animation keeps running, and that is my problem i need the animation to run only once
the animation is the character swinging his sword downwards

Edited by daro0196, 25 April 2012 - 02:25 PM.

  • 0

#11 ChefDavid22

ChefDavid22

    No, YOU shut up!

  • GMC Member
  • 1193 posts
  • Version:GM:Studio

Posted 25 April 2012 - 02:42 PM

Oh so lets start with the easy - did you add an OnKey Release for space bar?
  • 0

#12 Cpt Chuckles

Cpt Chuckles

    GMC Member

  • GMC Member
  • 323 posts
  • Version:GM8.1

Posted 25 April 2012 - 03:34 PM

you shouldn't need to add events for On Key Release. i made my first game that way and it was really convoluted. these days i check everything in the step event.
//step event
{
      if(keyboard_check_pressed(vk_space)) //if space was pressed
      {
            if(sprite_index != spr_attacking) //this prevents the sprite getting stuck on frame 1
                  sprite_index = spr_attacking;
      }
      if(sprite_index == spr_attacking && image_index == #) //# = the last frame of your attack animation
      {
            sprite_index = spr_standing; //change to standing
      }
}
well that's the gist of it, it's syntactically correct pseudocode.

Edited by Cpt Chuckles, 25 April 2012 - 03:35 PM.

  • 0

#13 ChefDavid22

ChefDavid22

    No, YOU shut up!

  • GMC Member
  • 1193 posts
  • Version:GM:Studio

Posted 25 April 2012 - 03:45 PM

Right I also use step event. Dont know what I was thinking. Hey I've only been here a month and a half ;-)
  • 0

#14 daro0196

daro0196

    GMC Member

  • GMC Member
  • 41 posts
  • Version:GM8

Posted 25 April 2012 - 04:09 PM

Another problem i have is that if i keep presing space the animation keeps running, what can i do?
  • 0

#15 ChefDavid22

ChefDavid22

    No, YOU shut up!

  • GMC Member
  • 1193 posts
  • Version:GM:Studio

Posted 25 April 2012 - 05:16 PM

What do you mean? As long as the code is in your on space bar press event it's going to happen every time you press space.

If you never want to see that animation again you're going to need to create a global variable.

globalvar dontplayanimationagain;
dontplayanimationagain = 0


On press space
If dontplayanimationagain = 0
{
PLAY ANIMATION;
}
global.dontplayanimationagain = 1;

Edited by ChefDavid22, 25 April 2012 - 05:16 PM.

  • 0

#16 daro0196

daro0196

    GMC Member

  • GMC Member
  • 41 posts
  • Version:GM8

Posted 25 April 2012 - 06:06 PM

the thing is that i need that every time i press space the animation only runs once, its because if i keep pressing it the character will be attacking all the time
  • 0

#17 Cpt Chuckles

Cpt Chuckles

    GMC Member

  • GMC Member
  • 323 posts
  • Version:GM8.1

Posted 25 April 2012 - 06:23 PM

did you try my method? it should work, making every press of the spacebar (whether you hold it or tap it) only play the animation once. that is, assuming your image_speed is a whole number no less than 1.

Edited by Cpt Chuckles, 25 April 2012 - 06:24 PM.

  • 0

#18 daro0196

daro0196

    GMC Member

  • GMC Member
  • 41 posts
  • Version:GM8

Posted 25 April 2012 - 07:59 PM

this is how i adapted your code
{
if(keyboard_check_pressed(vk_space))
{
if(sprite_index != spr_thanatos_atk_1_sword_right)
sprite_index = spr_thanatos_atk_1_sword_right;
}
if(sprite_index == spr_thanatos_atk_1_sword_right && image_index == 7)
{
sprite_index = spr_thanatos_stand_right;
}

{
if(keyboard_check_pressed(vk_space))
{
if(sprite_index != spr_thanatos_atk_1_sword_left)
sprite_index = spr_thanatos_atk_1_sword_left;
}
if(sprite_index == spr_thanatos_atk_1_sword_left && image_index == 7)
{
sprite_index = spr_thanatos_stand_left;
}}}
But the problem is that if i keep space pressed the animation keeps running

this is how i adapted your code
{
if(keyboard_check_pressed(vk_space))
{
if(sprite_index != spr_thanatos_atk_1_sword_right)
sprite_index = spr_thanatos_atk_1_sword_right;
}
if(sprite_index == spr_thanatos_atk_1_sword_right && image_index == 7)
{
sprite_index = spr_thanatos_stand_right;
}

{
if(keyboard_check_pressed(vk_space))
{
if(sprite_index != spr_thanatos_atk_1_sword_left)
sprite_index = spr_thanatos_atk_1_sword_left;
}
if(sprite_index == spr_thanatos_atk_1_sword_left && image_index == 7)
{
sprite_index = spr_thanatos_stand_left;
}}}
But the problem is that if i keep space pressed the animation keeps running


  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users