GMS 2 I have problems with animation and keeping my item persistent

S

Sroft

Guest
Ok so I have two problems and decided to post it to one thread
My first and most important problem is I have my player pick up a gun by colliding with it that works perfectly fine BUT when i leave that room and go to the next the gun is no longer with my player I already tried making the object persistent but still failed
My second problem is i have s script here
if (!place_meeting(x,y+1,WObject)) and WEAPONS_MODE.HANDS
{
sprite_index = PlayerA;
image_speed = 20;
if (sign(vsp) > 20) image_index = 1; else image_index = 1;
}
else
{
image_speed = 1;
if (hsp == 0)
{
sprite_index = Player;
}
else
{
sprite_index = PlayerR;
}
}
if (hsp != 0) image_xscale = sign(hsp);
for when my player is unarmed but the problem is when i jump(PlayerA) it dosent do the animation it is jumps but my player looks like she is just running in mid air but when I have a gun like my gun script here
if (!place_meeting(x,y+1,WObject)) and WEAPONS_MODE.PLASMA
{
sprite_index = sPGunPlasmaA;
image_speed = 20;
if (sign(vsp) > 20) image_index = 1; else image_index = 1;
}
else
{
image_speed = 1;
if (hsp == 0)
{
sprite_index = sPGunPlasma;
}
else
{
sprite_index = sPGunPlasmaR;
}
}
if (hsp != 0) image_xscale = sign(hsp);
the jump animation works fine
plz help and thank you
 

arirish

Member
If the gun is a separate object it'll need to be persistent too, unless you have some code to recreate the current weapon at the start of each room.
 
S

Sroft

Guest
If the gun is a separate object it'll need to be persistent too, unless you have some code to recreate the current weapon at the start of each room.
Ok so what i do is I just switch sprite animations when I pick up the gun is that correct to do because that might be the problem.
 

MirthCastle

Member
If your player is persistent, you need to have a variable on him that says he has a gun... then the correct animations when has_gun is true.

The weapons mode doesn't look like it is a variable on the player himself. Which is the problem.

you could say -
if (has_gun) {
weapons_mode.plasma

}

or you could even set has_gun to a sprite or a number other than zero that defines the weapons mode and make it a switch statement -
 
S

Sroft

Guest
If your player is persistent, you need to have a variable on him that says he has a gun... then the correct animations when has_gun is true.

The weapons mode doesn't look like it is a variable on the player himself. Which is the problem.

you could say -
if (has_gun) {
weapons_mode.plasma

}

or you could even set has_gun to a sprite or a number other than zero that defines the weapons mode and make it a switch statement -
Oh is this what your talking about sry I didnt post this
Create
//weapons
enum WEAPONS_MODE
{
HANDS,
PLASMA
}
weapons = WEAPONS_MODE.HANDS
Step
//Animation
switch (weapons)
{
case WEAPONS_MODE.HANDS:
{
Unarmed();
break;
}
case WEAPONS_MODE.PLASMA:
{
weapons = WEAPONS_MODE.PLASMA
Plasmagun();
break;
}
}
if so I already have that
 
S

Sroft

Guest
If the gun is a separate object it'll need to be persistent too, unless you have some code to recreate the current weapon at the start of each room.
Its not an object its a sprite
im now wondering should I change the sprite to be its own object and then swicth objects?
 
Top