[SOLVED]sprite_index not actually changing sprite

K

KitKatarine

Guest
So, my problem is this:

I want to approach a tree, and I want the code to determine whether the tree is to the left or to the right, and with that, display the right chopping animation(left or right). I read that sprite_index can do this for me, but all it does is change the numerical value for sprite index and not the actual sprite. I did do sprite_assign, and THAT works, with the exception I cannot change back to my static player sprite again.

Create Event:
Code:
countdown = room_speed*10 // ten second timer
countdown_start = 0;               // returns 1(true) or 0 (false)
Essentially, create the variables countdown and countdown start.

Step Event:
Code:
var tree_nearest_id = instance_nearest(obj_player.x, obj_player.y, obj_tree);

if countdown_start = 1
{
    countdown --
    if countdown > 0 //&& countdown_start = 1
    {
        if tree_nearest_id.x > obj_player.x
        {
            with (obj_player)
            {
                sprite_index = sp_lumchopRight
            }
        }
        else if tree_nearest_id.x <= obj_player.x
        {
            with(obj_player)
            {
                sprite_index = sp_lumchop
            }
        }
    }

    if countdown = 0
    {
        with (tree_nearest_id)
        {
        instance_change(obj_stump, true)
        }
        countdown = room_speed*10;
        countdown_start = 0;
    }
}  

else if countdown_start = 0
{
    with(obj_player)
    {
       sprite_index = sp_player
    }
}
Which, in short, /SHOULD/ change the sprites while I am cutting trees, but it actually does nothing. All it does is change the value of sprite_index (I know this through a draw event I wrote up)

However, when I use sprite_assign, it works up until I have to change it back.

Can anyone tell me what I'm doing wrong??

Note: sp_lumchop & sp_lumchopRight are both animated with several subimages, but I don't think this should matter too much.
 
K

KitKatarine

Guest
Do you have any code in the draw event for the player?
Oh yes sorry, I forgot that.

Code:
///Draw player + mouseclick(target)


// Draw target
if target_active
draw_sprite(sp_mouseclick, subimage, target_x, target_y);

// Draw player
if target_active
{
    if direction <= 180
    draw_sprite(sp_walk90, subimage, x, y);
    else
    draw_sprite(sp_walk270, subimage, x, y);
}
else
draw_sprite(sp_player, subimage, x, y);
but this deals with a different mouse click all together, and is used for moving the sprite.
 
K

KitKatarine

Guest
So I looked at it again and changed some things around. Had to add it into the draw event after all. It works nicely now.
 
Top