该语句破坏了正在执行代码instance_destroy()
的当前实例。self
您必须使用with (<objectID>) {instance_destroy()}
语法来销毁另一个实例。
只要portal
房间里只有一个实例,这段代码就可以工作:
if object_exists(portal)
{
with (portal) instance_destroy(); //you should also need a semicolon here to separate
//this statement from the next, it is good practice
//to do this after all statements as I have done.
action_create_object(portal,Spr_player.x,Spr_player.y);
}
else
{
action_create_object(portal,Spr_player.x,Spr_player.y);
}
如果有多个实例,portal
只会破坏第一个。要销毁所有内容,您必须使用for
循环来遍历它们。在我脑海中,我不记得获取id
对象所有实例的 s 的函数,但看起来这不是问题,因为每次创建一个对象时,现有的对象都会被销毁,因此您将只有一次一个。
另一种方法是将现有门户移动到新位置。这里唯一的区别是不会执行门户的创建事件,也不会重置任何警报。
portal.x=Spr_player.x
portal.y=Spr_player.y
同样,如果有多个门户,这只会移动第一个门户。