Gamemaker Studio 2:我的角色不会在房间中过渡 [英] Gamemaker Studio 2: My character won’t transition through rooms

查看:219
本文介绍了Gamemaker Studio 2:我的角色不会在房间中过渡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用从Udemy课程中学到的过渡代码,但是我游戏中的角色只会过渡到第一扇门,而没有其他角色.

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.

我正在使用相同的对象,但是更改了对象的创建代码.我使用变量room_start_.我用这些来选择不同的房间并在创建代码中开始位置.点击链接以查看视频游戏-( https://drive.google.com/open?id = 1jCWIM3hYymgspW54EPbnUDrNQVZbY_4B ).

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).

推荐答案

我在项目中摆弄了些小东西,我明白了你遇到的错误,当角色穿过第一扇门后,他甚至都不能回去尽管在r_sworld中具有相同类型的门,它们都具有防碰撞罩,都具有变量...我不知道为什么您的代码不起作用,但是我找到了解决方案!

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!

将代码从o_player :: o_door移至o_player :: step .
通常不建议在GMS中使用碰撞事件,您应该尽可能地在step事件中尝试做.您可以通过在步骤事件的末尾添加o_door来替换碰撞事件:

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;
}

这是一个陷阱.如果global.player_start_position指示的新位置使玩家出现在目标房间的另一扇门上,您将立即被传送回第一个房间.确保door.start_中的坐标永远不要太靠近其他门.

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.

希望这会有所帮助!

这篇关于Gamemaker Studio 2:我的角色不会在房间中过渡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆