Sprite changing when movement problem

P

PopatoChisp

Guest
Hi, I have a little problem with changing the sprite when the object moves and changes direction.
the sprite changes to the walk sprite when moving and back to the static sprite when standing and also changes to the sprite for the right direction.

But it sometimes slides a bit or switches to the walk sprite for a moment then back to the static one.

It's controlled trough a mouse click
That's the code I used in the Player objekt for that

Code:
if(instance_exists(obj_MouseClick)){
mouseDistance = point_distance(x ,y, obj_MouseClick.x, obj_MouseClick.y);
move_towards_point(obj_MouseClick.x,obj_MouseClick.y, min(9, mouseDistance));
}
and

Code:
if(!instance_exists(obj_MouseClick)){
    instance_create(mouse_x,mouse_y,obj_MouseClick);
}
And that's the code I used on the player object to switch sprites:

Code:
if(instance_exists(obj_MouseClick)){
if obj_Playertest.x < obj_MouseClick.x {
if image_speed > 0 {
sprite_index = Clara_walk_right;
}}}

if(instance_exists(obj_MouseClick)){
if obj_Playertest.x > obj_MouseClick.x {
if image_speed > 0 {
sprite_index = Clara_walk_left;
}}}

if(place_meeting(x,y,obj_MouseClick)){
if sprite_index = Clara_walk_left{
sprite_index = Clara_static_left
}}

if(place_meeting(x,y,obj_MouseClick)){
if sprite_index = Clara_walk_right{
sprite_index = Clara_static_right
}}
I also have piece of code in the MouseClick object which makes it transparent when it comes in contact with the player object.

Code:
if(place_meeting(x,y,obj_Playertest)){
    image_alpha = 0;
} else {
    image_alpha = 1;
}
I put the origin in the static and walk sprites on the same spot, which helped a bit to reduce the sliding, but hasn't solved the problem completly. I could live with the static sprite sliding slightly 8even if I would love to remove that too), but the biggest problem is the sudden changing to the walk sprite and then back to the static sprite.
 

gmx0

Member
All I can think of is either put else's on this code or use a switch statement
Code:
if(instance_exists(obj_MouseClick)) //you only need one of this
{

if obj_Playertest.x < obj_MouseClick.x {
if image_speed > 0 {
sprite_index = Clara_walk_right;
}}
else
if obj_Playertest.x > obj_MouseClick.x {
if image_speed > 0 {
sprite_index = Clara_walk_left;
}}

if(place_meeting(x,y,obj_MouseClick)){ //you also only need one of this
if sprite_index = Clara_walk_left{
sprite_index = Clara_static_left
}
else
if sprite_index = Clara_walk_right{
sprite_index = Clara_static_right
}}

}
 
Not at pc to check, but wouldn't place meeting call the static sprite as soon as the masks overlap? Therefore you call the static sprite, but the x and y still aren't quite the same yet so the walk sprite gets called again - causing a flickering?
 
Top