所以我在游戏制作工作室 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);
我认为该代码应该涵盖它。
任何帮助表示赞赏!