Gamemaker Studio 2: My character won’t transition through rooms

旧街凉风 提交于 2021-01-29 08:30:53

问题


I use transition code that I learned through a Udemy course, but the character in my game will only transition through the first door, and no others.

I am using the same object but changing the creation code of the object. I use variables room_, start_. I use these to select different rooms and start positions within the creation code. Click the link to view video game - (https://drive.google.com/open?id=1jCWIM3hYymgspW54EPbnUDrNQVZbY_4B).


回答1:


I fiddled with the project a bit, I understand the error you're getting, after the character goes through the first door, he can't go back even though in r_sworld there's the same type of doors, they all have collision masks, they all have variables... I don't know why your code wasn't working, but I found a solution!

Move the code from o_player::o_door to o_player::step.
Using collision events in GMS is generally not advised, you should try to do as much in the step event as you can. You can replace your collision event with o_door by adding this at the end of your step event:

if (place_meeting(x, y, o_door)) {
    var door = instance_place(x, y, o_door);
    room_goto(door.room_);
    global.player_start_position = door.start_;
    persistent = true;
}

Here's a catch. If the new position dictated by global.player_start_position makes the player appear on top of some other door in the destination room, you will be immediately teleported back to the first room. Make sure the coordinates in door.start_ are never too close to other doors.

Hope this helps!



来源:https://stackoverflow.com/questions/53647606/gamemaker-studio-2-my-character-won-t-transition-through-rooms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!