Search code examples
game-physicsgmlgame-maker-studio-2

Why is there a "ghost" of the sprite stuck in the background? GMS 2


So I'm making a game in game maker studio 2 and it's kinda like football but with flying. I just made the movement and jetpack controls and last night it was working but when I booted it up this morning, this happened. Normally when you move, you only see one image (the sprite) but it was showing where it had been and leaving the image there. I don't know if it is a RAM error or I did something wrong in the code.

code: Step event in player object

/// @description Movement logic
// Get the input
var x_input = (keyboard_check(vk_right) - keyboard_check(vk_left)) * acceleration_;

// Vector variables
var vector2_x = 0;
var vector2_y = 1;

// Horizontal movement
velocity_[vector2_x] = clamp(velocity_[vector2_x]+x_input, -max_velocity_[vector2_x], max_velocity_[vector2_x]);
var on_ground = tile_collide_at_points(collision_tile_map_id_, [bbox_left, bbox_bottom], [bbox_right-1, bbox_bottom]);
if keyboard_check(vk_right){
    if on_ground {
    sprite_index = spr_player_ground_right
    direction_=0
    }
    else {
    sprite_index = spr_player_flying_right
    direction_=0
    }
}

if keyboard_check(vk_left){
    if on_ground {
    sprite_index = spr_player_ground_left
    direction_=1
    }
    else {
    sprite_index = spr_player_flying_left
    direction_=1
    }
}

// Friction
if x_input == 0 {
    velocity_[vector2_x] = lerp(velocity_[vector2_x], 0, .2);
}


// Gravity
velocity_[vector2_y] += gravity_;

// Move and contact tiles
move_and_contact_tiles(collision_tile_map_id_, 64, velocity_);

// Jumping
var on_ground = tile_collide_at_points(collision_tile_map_id_, [bbox_left, bbox_bottom], [bbox_right-1, bbox_bottom]);
//if on_ground {
    // Jumping
    if keyboard_check(vk_space) {
        velocity_[vector2_y] = -jump_speed_;
        if direction_=0 {
        sprite_index = spr_player_flying_right
        direction_=0
        }
        else {
        sprite_index = spr_player_flying_left
        direction_=1
        }
    }
//}

Create Event in player object

/// @description Movement variables
velocity_ = [0, 0];
gravity_ = 0.3;
jump_speed_ = 4;
max_velocity_ = [8, 32];
acceleration_ = 2.1;
direction_ = 0;

// Get the tilemap id
var layer_id = layer_get_id("CollisionTiles");
collision_tile_map_id_ = layer_tilemap_get_id(layer_id);

I think that code should cover it.

Any help appreciated!


Solution

  • Have you disabled this check box in the current room that draws the background? If so just recheck it.

    Note this is gm8 but it should be the same.

    Check Draw Backgrund