Legacy GM Problem with Attack Animation

M

MagicFool64

Guest
I'm making an action platform game (I have a lot of project), and want to make my character attacking with a melee weapon. But my character doesn't attack. Instead of attacking, he plays the walk animation (because the stand sprite is the first image of the walk sprite). Here is the classis

//Step Event
if(place_meeting(x,y+1,obj_wall)){
grounded = true
}else{
grounded = false
}

if(grounded){
sprite_index = spr_walk
} else {
if(vspeed<0){
sprite_index = spr_jump
}else{
sprite_index = spr_jump //I'm using the jump sprite even for the fall
}
}

//Pressing Space Bar
if sprite_index = spr_walk
{
if image_index = 0
{
sprite_index = spr_attack
image_speed = .2
}
}
else if sprite_index = spr_jump
{
if image_index = 0
{
sprite_index = spr_attack_jump
image_speed = .2
}
}

//Animation End
if sprite_index = spr_attack
{
sprite_index = spr_walk
image_speed = 0
}
else if sprite_index = spr_attack_jump
{
sprite_index = spr_jump
image_speed = 0
}

Can you help me?
 
L

lvls3dx

Guest
I'm making an action platform game (I have a lot of project), and want to make my character attacking with a melee weapon. But my character doesn't attack. Instead of attacking, he plays the walk animation (because the stand sprite is the first image of the walk sprite). Here is the classis

//Step Event
if(place_meeting(x,y+1,obj_wall)){
grounded = true
}else{
grounded = false
}

if(grounded){
sprite_index = spr_walk
} else {
if(vspeed<0){
sprite_index = spr_jump
}else{
sprite_index = spr_jump //I'm using the jump sprite even for the fall
}
}

//Pressing Space Bar
if sprite_index = spr_walk
{
if image_index = 0
{
sprite_index = spr_attack
image_speed = .2
}
}
else if sprite_index = spr_jump
{
if image_index = 0
{
sprite_index = spr_attack_jump
image_speed = .2
}
}

//Animation End
if sprite_index = spr_attack
{
sprite_index = spr_walk
image_speed = 0
}
else if sprite_index = spr_attack_jump
{
sprite_index = spr_jump
image_speed = 0
}

Can you help me?
Hi, I assume everything is put together in your Step Event just like that; am I correct?

If so, seems to me you made a kind of a loop, since at the moment your spr_index changes to spr_attack it will change again right away to spr_walk index before the step event finishes. To my understanding this is due to the lack of an alarm system/ timer system/ or some kind of animation hit end function (which I ignore if it's present in GM 1.4).

In any case I don't know if my insight is fully accurate or not since I never gave a try to platforms. I don't know if there are some coding tricks for that genre; so I hope someone a bit more experienced also answers. Good luck
 
M

MagicFool64

Guest
Hi, I assume everything is put together in your Step Event just like that; am I correct?

If so, seems to me you made a kind of a loop, since at the moment your spr_index changes to spr_attack it will change again right away to spr_walk index before the step event finishes. To my understanding this is due to the lack of an alarm system/ timer system/ or some kind of animation hit end function (which I ignore if it's present in GM 1.4).

In any case I don't know if my insight is fully accurate or not since I never gave a try to platforms. I don't know if there are some coding tricks for that genre; so I hope someone a bit more experienced also answers. Good luck
I make this wave: when I press the button for attacking, the sprite have to change to spr_attack (and spr_attack_jump when is jumping). In the Animation End Step, the scripts say that if the attack animation ends, according to the sprite it changes to spr_walk or spr_jump. But it doesn't work. Instead of attacking, it plays the walk animation. But when I remove the jump animation script, the attack works. How can I fix it?
 

JasonTomLee

Member
Id recommend using separate variables to distinguish the player sprite states. Its pretty hard to properly read & understand the flow of logic if it's based on sprite_indexes and image speeds.
Here's how I approach it:

Code:
/// Set a variable based on the input/logic of the game. These variables determine the sprite index/speeds of the object.

Example: if ( keyboard_check( vk_space )) sprite_index = spr_jump; jump = true; else if (!place_meeting( x,y+1, oBlock )) jump = false
if ( keyboard_check_pressed( "your attack button" )) sprite_index = ____ attack = true;

// Set the animations based on states or variables
if ( jump ) sprite_index = ___
else if ( attack ) sprite_index = ____
else if .....

OR you could set states to prevent any overlapping on the sprites- I'd use this method any day of the week!

///////////////// Create
state = 0;
idle = 1;
jump = 2;
attack = 3;
//////////////// Step
switch( state ){
case idle:

break;
case jump:

break;
case attack:

break;
}
//////////////////End Animation
if ( attack ) attack = false;
 
M

MagicFool64

Guest
Id recommend using separate variables to distinguish the player sprite states. Its pretty hard to properly read & understand the flow of logic if it's based on sprite_indexes and image speeds.
Here's how I approach it:

Code:
/// Set a variable based on the input/logic of the game. These variables determine the sprite index/speeds of the object.

Example: if ( keyboard_check( vk_space )) sprite_index = spr_jump; jump = true; else if (!place_meeting( x,y+1, oBlock )) jump = false
if ( keyboard_check_pressed( "your attack button" )) sprite_index = ____ attack = true;

// Set the animations based on states or variables
if ( jump ) sprite_index = ___
else if ( attack ) sprite_index = ____
else if .....

OR you could set states to prevent any overlapping on the sprites- I'd use this method any day of the week!

///////////////// Create
state = 0;
idle = 1;
jump = 2;
attack = 3;
//////////////// Step
switch( state ){
case idle:

break;
case jump:

break;
case attack:

break;
}
//////////////////End Animation
if ( attack ) attack = false;
It doesn't work very well
 
V

VeSo

Guest
As a general rule, I don't do any "animating" in the step event. You can get all kinds of glitches because of the 30-steps per second (or 60 depending on your FPS). Most of my success when animating and switching animations is done in the Animation End event.
 
M

MagicFool64

Guest
Here is the other problem:
when the character is on the floor and attack, the animation works well, but when is jumping and attack, the jumping attack sprite isn't animated. Here is the script:
Code:
Code:
//Create Event
image_speed = 0
image_index = 0

attack = 0

//Step Event
if(place_meeting(x,y+1,obj_wall)){
   grounded = true
}else{
   grounded = false
}

if(grounded){                   
   sprite_index = spr_walk
} else {
   if(vspeed<0){               
       sprite_index = spr_jump
   }else{                     
       sprite_index = spr_jump
   }
}

if attack = 1
   if grounded = true
       {
       sprite_index = spr_attack
       image_speed = .2
       }
   else if grounded = false
       {
       sprite_index = spr_attack_jump
       image_speed = .2
       }

//Animation End Step
if sprite_index = spr_attack
   {
   attack = 0
   image_speed = 0
   }
else if sprite_index = spr_attack_jump
   {
   attack = 0
   image_speed = 0
   }

/Press Space Event
attack = 1
How can I fix it?
 
Top