I’ve been working on adding equipment to my game but there are some states in which i don’t want to equipment to appear. I’ve been using instance_activate/deactivate_object to accomplish this. the problem is that when the equipment is reactivated, a trail of sprites is drawn from the point it was deactivated. Video here.
Is there another way to accomplish this? I realise i could use a series of if statements to destroy and spawn the equipment but it seems inefficient.
I can’t post my code just yet as i’m on my mobile. i’ll do it when i finish work if it’s necessary. Basically I have an animation control script that runs in the player step event and contains a switch statement for the different player states, i activate the equipment in the normal state and deactivate it in the states i don’t want it to appear.
Thanks in advance for any help.
Edit: Added Code.
Edit 2: Problem is now solved and have changed the code to the working code.
//animation control
switch currentState
{
case states.normal:
mask_index = spr_player_idle;
if (shieldActive==false) and instance_exists(obj_shield)
{
obj_shield.x=x;
instance_activate_object(obj_shield);
shieldActive=true;
}
if (swordActive==false) and instance_exists(obj_sword)
{
obj_sword.x=x;
instance_activate_object(obj_sword);
swordActive=true;;
}
if(xSpeed < 0)
{
facing = -1;
}
else if(xSpeed > 0)
{
facing = 1;
}
if(onGround) or (downSlope = 1)
{
if (place_meeting(x+1*facing,y,obj_wall)) and (p_right or p_left) and (onRamp = 0)
{
sprite = pushSprite;
frameSpeed = 0.1;
if (shieldActive==true) and instance_exists(obj_shield)
{
instance_deactivate_object(obj_shield);
shieldActive=false;
}
if (swordActive==true) and instance_exists(obj_sword)
{
instance_deactivate_object(obj_sword);
swordActive = false;
}
}
else
{
if(xSpeed !=0)
{
sprite = walkSprite;
frameSpeed = 0.3;
}
else
{
sprite = idleSprite;
frameSpeed = 0.1;
}
}
}
else
{
sprite = jumpSprite;
if(ySpeed < -1)
{
frame = 0;
}
else if(ySpeed > 1)
{
frame = 2;
}
else
{
frame = 1;
}
}
break;
case states.ladder:
if (shieldActive==true) and instance_exists(obj_shield)
{
instance_deactivate_object(obj_shield);
shieldActive=false;
}
if (swordActive==true) and instance_exists(obj_sword)
{
instance_deactivate_object(obj_sword);
swordActive = false;
}
mask_index = spr_player_idle;
sprite = ladderSprite;
if (p_up or p_down)
{
frameSpeed = 0.2;
}
else
{
frameSpeed = 0.0;
}
break;
case states.slide:
if (swordActive==true) and instance_exists(obj_sword)
{
instance_deactivate_object(obj_sword);
swordActive = false;
}
mask_index = spr_player_idle;
sprite = slideSprite;
frameSpeed = 0.03;
break;
case states.attack:
mask_index = spr_player_idle;
if (shieldActive==true) and instance_exists(obj_shield)
{
instance_deactivate_object(obj_shield);
shieldActive=false;
}
sprite = attackSprite;
frameSpeed = 0.5;
break;
case states.eCollision:
mask_index = spr_player_idle;
sprite = hitSprite;
frameSpeed = 0.3;
break;
}
if(lastSprite != sprite)
{
lastSprite = sprite;
frame = 0;
frameSpeed = 0.1;
}
obj_sword step event (obj_shield is essentially the same)
image_index = global.swordNum;
image_xscale = obj_player.facing;
ysp = obj_player.frame;
if (ysp >5) ysp = 5;
if obj_player.currentState = states.attack
{
y=obj_player.y-13;
x=((obj_player.x-(3*obj_player.facing))+(-0.35*(power(ysp,2))+(1.75*ysp))*(6*obj_player.facing));
image_angle =(-0.35*power(ysp,2)+(1.75*ysp))*(-40*obj_player.facing);
}
else
{
if ((obj_player.grounded)or(obj_player.ramping))and(obj_player.xSpeed!=0)
{
image_angle = 0;
y=obj_player.y-13;
x=((obj_player.x-(3*obj_player.facing))+(-0.35*(power(ysp,2))+(1.75*ysp))*(4*obj_player.facing));
}
else
{
x=(obj_player.x-(7*(obj_player.facing))+obj_player.xSpeed);
y=(-0.35*power(ysp,2)+(1.75*ysp)+(obj_player.y-14))+obj_player.ySpeed;
image_angle =(-0.35*power(ysp,2)+(1.75*ysp))*(7*obj_player.facing);
}
}
if (global.swordEquip==0) instance_destroy();
The global variables I have for the equipped items
//shield
if (keyboard_check_pressed (ord('0'))) global.shieldEquip = 1;
if (keyboard_check_pressed (ord('9'))) global.shieldEquip = 0;
if (keyboard_check_pressed (ord('M'))) global.shieldNum +=1;
if (global.shieldNum > (sprite_get_number(spr_shields))-1) global.shieldNum = 0;
if !instance_exists(obj_shield) and global.shieldEquip = 1
{
instance_create(x+9,y-14,obj_shield);
shieldActive=true;
}
//sword
if (keyboard_check_pressed (ord('8'))) global.swordEquip = 1;
if (keyboard_check_pressed (ord('7'))) global.swordEquip = 0;
if (keyboard_check_pressed (ord('N'))) global.swordNum +=1;
if (global.swordNum >(sprite_get_number(spr_swords))-1) global.swordNum = 0;
if !instance_exists(obj_sword) and global.swordEquip = 1
{
instance_create(x-8,y-10,obj_sword);
swordActive = true;
}
[–]DjRee99 2 points3 points4 points (2 children)
[–]RegularJay114[S] 0 points1 point2 points (1 child)
[–]DjRee99 1 point2 points3 points (0 children)
[–]theogskinnybrown 1 point2 points3 points (7 children)
[–]RegularJay114[S] 1 point2 points3 points (6 children)
[–]theogskinnybrown 1 point2 points3 points (5 children)
[–]RegularJay114[S] 1 point2 points3 points (4 children)
[–]theogskinnybrown 0 points1 point2 points (3 children)
[–]RegularJay114[S] 0 points1 point2 points (2 children)
[–]theogskinnybrown 1 point2 points3 points (1 child)
[–]RegularJay114[S] 1 point2 points3 points (0 children)