GML 1.4.9999 sprite facing troubles

woods

Member
having an issue with my player sprite not changing properly. the image changes when i have a collision with the selection ship.. however, all but the first image is offset by -90degrees .
ive tried several approaches to changing the image_angle.. in the selection ship's sprite.. in the creation code of the instance placed in the room.. in the step event where the player collides with the ship..


obj_player create event
Code:
/// initialize vars

image_index = spr_P1 // default sprit no ship
turn_spd = 1; // image_angle
thrust = 0.01; // motion_add
spd = 2; // speed clamp


obj_player step event
Code:
/// select ship

var inst;
inst = instance_place(x, y, obj_ship_select_P1);
if inst != noone
   
    if (inst.image_index = 0)
    {
        sprite_index = spr_ship_0;
        turn_spd = 3;
        thrust = 0.03;
        spd = 3;
    }

else
    
    if (inst.image_index = 1)
    {
        sprite_index = spr_ship_1;
        turn_spd = 2;
        thrust = 0.02;
        spd = 2;
    }

else
  
    if (inst.image_index = 2)
    {
        sprite_index = spr_ship_2;
        turn_spd = 4;
        thrust = 0.04;
        spd = 4;
    }

else
  
    if (inst.image_index = 3)
    {
        sprite_index = spr_ship_3;
        turn_spd = 5;
        thrust = 0.05;
        spd = 5;
    }
also i have a handful of instances of obj_ship_select_P1 placed in the room editor with creation code
Code:
image_index = 0
image_speed = 0
image_index is increased for each instance in the room to designate the different ships the player can select


i am completely stumped as to why it works fine with the first one but not the rest.
the sprite is offset by -90degrees in all but the first ship (index 0)
 

Nidoking

Member
Where are you actually drawing the sprites/setting the image_angle for them? You've got a comment, but no actual uses of image_angle.
 

woods

Member
WASD to move player1 and arrow keys to move player2
A and D rotate player1-change the image_angle


obj_player step event
Code:
/// movment


if(keyboard_check(ord("A"))){
    image_angle = image_angle + obj_P1.turn_spd;
}

if(keyboard_check(ord("D"))){
    image_angle = image_angle - obj_P1.turn_spd;
}


if(keyboard_check(ord("S"))){
        motion_add (image_angle, + obj_P1.thrust)
}

if(keyboard_check(ord("W"))){
    {
        motion_add (image_angle, - obj_P1.thrust);
    }
}

speed = clamp(speed, -obj_P1.spd, obj_P1.spd); 

// screen wrap
move_wrap(true, true, sprite_width);
the first image.. the one with index 0.. works exactly how its supposed to. so i copied that bit of code and changed the index and ship number for each of the other ships.
since the first one worked just fine, i dont see why it rotates the others by 90degrees.

i tried putting image_angel = -90 //to offset the sprite .. no effect still rotated goofy
also tried image_angle = image_angle +90 // this made it spin like mad

obj_player step event -select ship script
Code:
else
    
    if (inst.image_index = 1)
    {
        sprite_index = spr_ship_1;
        turn_spd = 2;
        thrust = 0.02;
        spd = 2;
       image_angle = -90 // to offset sprite rotated weird (removed since it didnt work)
    }
i also tried to manually change the sprite sub image .. when i goto the game, no effect.. the sprite is pointed up

(shot in the dark prayer here)
also tried in obj_P1 step event -drawself() script
image_angle = -90

the sprite didnt change once i ran the game
 

woods

Member
edit:

got things mashed out by using individual objects for the selector ships instead of image_index of one ship with all the sprites

sometimes simple is better ;o)
 
Top