GameMaker Attack animation problem help

lolKanra

Member
Hi im trying to make an action platformer game where your character can throw knives, now i tried making the animation play every time the left mouse button is pressed down but i seem to be having issues.

When i stand still, the animation only stays on the first frame, it only plays when i walk around while attacking. it also doesnt play when im in the air (even while moving, as shown in the video). im also wondering how i can get it to play the whole animation without being interrupted if you catch my drift, as well as play only once if you pressed the LMB once.

anyway here's the problem and my code, im a beginner and im watching Shaun Spalding's tutorial so please bear with my dirty code lmao. (note: im not spamming the LMB in the clip, im holding it down.)

Note:
[i unlisted video and uploaded it on my yt instead bc gif is too big for forum]



Thanks in advance!!
 

Attachments

Nidoking

Member
Presumably, you're setting the sprite to something else somewhere. You need to tell it not to do that if you don't want it to.
 

lolKanra

Member
Well, you have image_index = sPlayerStand right in the screenshot. sPlayerStand appears to be a sprite, but you're using it as a frame number.
hmmm, thanks for pointing that out, although even after removing that segment, or turning it to sprite_index, the problem still occurs
 

Nidoking

Member
Then you will need to find where the problem is and fix it. I don't know what more information you want. You're either setting image_speed to zero somewhere, or you're setting image_index every step, or maybe you've got a draw event that's not using the image_index value properly. I don't know which of those things is the case, and you haven't provided the information necessary to determine that.
 

lolKanra

Member
well my goal is to have the attack animation (sThrow2) play once and in full whenever i click the LMB, same even in the air, but it only plays when im walking on the ground while clicking LMB. i'll analyze my code and see what i can do though.
 

TheouAegis

Member
First off, you want mouse_check_button_pressed().

When that check passes, change the sprite to your attack sprite. Don't forget to set image_index to 0 when you change the sprite.

Use the Animation End event to change your sprite back if the sprite_index is your attack sprite.

Anything you don't want to happen when attacking, you could encapsulate inside a conditional that checks if sprite_index is not the attack sprite.

(That's just one way.)
 

lolKanra

Member
1603873529410.pngi've removed the useless code i put and tried changing it to mouse_check_button_pressed, but now the attack animation only shows 1 frame and ends instantly.
 

Nidoking

Member
Okay, this part that I quoted only you can't see it because that's a screenshot, not a nice, sensible CODE block, is redundant because you know that attackanim is true because you just set it to true. The problem, clearly, is that you're setting the sprite to something else in another place. I can't tell you what place that is because you haven't told us what place that is.
 

TheouAegis

Member
The original issue (not attacking in air) was probably something like
Code:
if !place_meeting(x,y+1,obj_block)
    sprite_index = sPlayerJump;
And now the issue is that AND probably something like
Code:
if hspd == 0
    sprite_index = sPlayerStand;
Going off of what I can recall from other Spalding threads.
 
Top