• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Can't change sprite_index .. after changing room

R

Rhadamanthe

Guest
Hi everyone !

I post here, because I've a big and mysterious issue!

I want to change a sprite for a blood effect, according to my player orientation (left, right, up, down).
I have my sprites in arrays, because it changes according to ennemies.
So I tried two ways :

- I put my sprite attack of my character in the same order than the blood sprite in the arrays. So, when I create the instance of the blood effect, I call the 2D array, the first entry is an id of the ennemies, second is the sprite index of my character.

- I set a variable from 0 to 3, when I change my character sprite for attack. And it's suppose to be the same than the second entry of my 2D array.

Ok, so, it works, but only in my first room !! o_O
When I go to the second, in both ways, the value is 0. But nothing change between the first and second room ...


If someone has a magic trick to resolve that ... Thank you in advance :)
 

Relic

Member
If it works in one room but not the other, I'd be focusing on how you create these arrays. If your arrays are not global variables, moving to a new room will require the arrays to be created again.
 
R

Rhadamanthe

Guest
Thanks for the clue

Even if my array is in a persistent object ?
 
C

CedSharp

Guest
Well, is your player AND enemies persistent ?
Because if they aren't, their create event executes when the room start. Check if you are setting your variable to 0 there.
 
R

Rhadamanthe

Guest
Mmmmmh, thanks !
I don't want my ennemies to be persistent because I make them spawn randomly in each room.
The variable supposed to change according to my player orientation (0 to 3), doesn't depend to ennemies, and when I say "an id of the ennemy", it's a variable I created, which is the same for all instances of one ennemy object.

That's why I don't understand :(
 
C

CedSharp

Guest
So if I understand correctly, you have a persistent object which holds 2 arrays ( or a 2d array, same thing ) where you have, ordered by "direction id" ( 0 to 3 ), first the player attack sprite and second the blood sprite.
You want to display the correct blood sprite according to the player's orientation, if that's what I understand.

In that case, instead of all this really nice but unnecessary logic, you could simply have an object oBlood ( or obj_blood or whatever ) that checks the current direction of the player and change it's own sprite accordingly ( or image_angle, depending on how you do things ).

Code:
if( instance_exists( oPlayer ) ) {
    switch( oPlayer.dir ) { // I assume dir is the direction ( 0 to 3 )
        case 0: sprite_index = sBloodRight;
        case 1: sprite_index = sBloodTop;
        case 2: sprite_index = sBloodLeft;
        case 3: sprite_index = sBloodBottom;
        default: instance_destroy(); // should never happen
    }
}
else instance_destroy(); // show never happen

If this isn't what you're trying to do, then sorry for my misunderstanding.
 
R

Rhadamanthe

Guest
It's almost what I've done !
I have already an object oBlood, but I use an array in an object bestiary where there is blood fx sprites according to each monsters, like that :

Code:
fx[0,0] = spr_fx_blood_green_right;
fx[0,1] = spr_fx_blood_green_up;
fx[0,2] = spr_fx_blood_green_left;
fx[0,3] = spr_fx_blood_green_down;

So 1rst index 0 is the first monster, 1 the 2nd etc. And when I attack, I've an object damage where I create the oBlood and change the sprite :

Code:
instance_create(other.x,other.y, obj_fx_blood);
obj_fx_blood.sprite_index = obj_bestiaire.fx[other.car_id,creator.f]


car_id is a variable for each monsters, to call the right sprite in obj bestiary, creator is the player which create the obj damage and f is a variable that I change in a script attack :


Code:
switch (sprite_index) {

    case spr_player_down:
            sprite_index = spr_player_attack_down;
            self.f = 2
        break;
 
    case spr_player_left:
            sprite_index = spr_player_attack_left;
            self.f = 1;
        break;
 
   etc....

I tried to put a switch(creator.face) in the obj damage, and exactly the same : it works in first room, not in second, it let the face = RIGHT

Thank you again for your help


Edit : before switch(creator.face), I've tried to call a script which change the variable face according to round(dir/90), but actually just let at Right in first and second room
 
Last edited by a moderator:
Top