【问题标题】:Why is there a "ghost" of the sprite stuck in the background? GMS 2为什么会有精灵的“幽灵”卡在背景中? GMS 2
【发布时间】:2017-11-16 22:59:27
【问题描述】:

所以我在游戏制作工作室 2 中制作游戏,它有点像足球,但有飞行功能。我刚刚完成了运动和喷气背包的控制,昨晚它正在工作,但是当我今天早上启动它时,发生了这种情况。通常,当您移动时,您只会看到一张图像(精灵),但它显示了它曾经在哪里并将图像留在那里。我不知道这是 RAM 错误还是我在代码中做错了什么。

代码: 播放器对象中的步骤事件

/// @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
        }
    }
//}

在播放器对象中创建事件

/// @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);

我认为代码应该涵盖它。

任何帮助表示赞赏!

【问题讨论】:

    标签: game-physics gml game-maker-studio-2


    【解决方案1】:

    如果有人遇到这个问题,我知道一个对我有用的解决方法。

    创建一个新的背景层并将其放在所有其他层的最底部。

    link to photo

    确保您在新的背景层上并进入属性房间

    link to photo

    然后转到视口和相机

    link to photo

    然后确保您检查了清晰的视口背景

    link to photo

    如果这对你不起作用,我很抱歉我帮不上忙

    【讨论】:

      【解决方案2】:

      您是否在当前绘制背景的房间中禁用了此复选框? 如果是这样,请重新检查。

      注意这是gm8,但应该是一样的。

      【讨论】:

      • 我发现每当我选择 spr_crowd 精灵时,它都会留下一个“幽灵”。我该如何解决这个问题?
      • 你提供的还不够我帮你,我至少需要截图。
      • 这是背景故障,图像没有填满屏幕,所以出现了“鬼”效果。感谢您的帮助!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-10
      相关资源
      最近更新 更多