108 lines
4.4 KiB
HTML
108 lines
4.4 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
|
|
<html>
|
|
<head>
|
|
<title>Deactivating instances</title>
|
|
<link href="style.css" rel="stylesheet" type="text/css">
|
|
</head>
|
|
<body background="images/back.gif">
|
|
<!--START-->
|
|
|
|
<h3>Deactivating instances</h3>
|
|
|
|
<b><i>Please be aware that deactivating and activating instances can sometimes lead to
|
|
unexpected problems. So you are strongly advised not to use this feature except for
|
|
very simple situation like the ones described below.
|
|
The feature is mainly left in for backward compatibility.</i></b>
|
|
|
|
<p>
|
|
When you create large room, for example in platform games, with a small view,
|
|
many instances lie outside the view. Such instances though are still active
|
|
and will execute their events. Also when performing collision checks
|
|
these instances are taken into account. This can cost a lot of time, which
|
|
is often not necessary. (For example, often it is not important whether
|
|
instances outside the view move.) To solve this problem <i>Game Maker</i>
|
|
contains some functions to deactivate and activate instances. Before using
|
|
them you must though clearly understand how they work.
|
|
|
|
<p>
|
|
When you deactivate instances they are in some sense removed from the game.
|
|
They are not visible anymore nor are any events executed for them. So for
|
|
all actions and functions they don't exist anymore. This saves a lot of time
|
|
but you have to be careful. For example, when you delete all instances of a
|
|
particular type, deactivated instances are not deleted (because they don't
|
|
exist). So don't think that a key a player picks up can unlock a deactivated door.
|
|
Also persistent deactivated instances are <b>not</b> moved over to the next room (even
|
|
though they are persistent). Also make sure that after you deactivate an instance that
|
|
you no longer execute code for it. This can in particular happen when an instance
|
|
deactivates itself. In general you better never have an instance deactivate itself.
|
|
|
|
<p>
|
|
The most crucial mistake you can make is to deactivate the instance that is
|
|
responsible for the activation. To avoid this some of the routines below allow
|
|
you to insist that the calling instance should not be deactivated itself.
|
|
|
|
<p>
|
|
Here are the available routines:
|
|
|
|
<p>
|
|
<blockquote>
|
|
<tt><b>instance_deactivate_all(notme)</b></tt>
|
|
Deactivates all instances in the room. If notme is true the calling instance
|
|
is not deactivated (which is normally what you want).<br>
|
|
<tt><b>instance_deactivate_object(obj)</b></tt>
|
|
Deactivates all instances in the room of the given object. You can also use all
|
|
to indicate that all instances must be deactivated or the id of an instance to
|
|
deactivate an individual instance.<br>
|
|
<tt><b>instance_deactivate_region(left,top,width,height,inside,notme)</b></tt>
|
|
Deactivates all instances in the indicated region (that is, those whose
|
|
bounding box lies partially inside the region). If inside is false the
|
|
instances completely outside the region are deactivated. If notme is
|
|
true the calling instance is not deactivated (which is normally what you want).<br>
|
|
<tt><b>instance_activate_all()</b></tt>
|
|
Activates all instances in the room.<br>
|
|
<tt><b>instance_activate_object(obj)</b></tt>
|
|
Activates all instances in the room of the given object. You can also
|
|
use all to indicate that all instances must be activated or the id of
|
|
an instance to activate an individual instance.<br>
|
|
<tt><b>instance_activate_region(left,top,width,height,inside)</b></tt>
|
|
Activates all instances in the indicated region. If inside is false the
|
|
instances completely outside the region are activated.<br>
|
|
</blockquote>
|
|
|
|
<p>
|
|
For example, to deactivate all instances outside the view and activate the ones
|
|
inside the view, you could place the following code in the step event of the moving
|
|
character:
|
|
|
|
<p>
|
|
<blockquote>
|
|
<pre>
|
|
{
|
|
instance_activate_all();
|
|
instance_deactivate_region(view_xview[0],view_yview[0],
|
|
view_wview[0],view_hview[0],false,true);
|
|
}
|
|
</pre>
|
|
</blockquote>
|
|
|
|
<p>
|
|
In practice you might want to use a region slightly larger than the view.
|
|
|
|
|
|
<!--END-->
|
|
</body>
|
|
</html>
|
|
|
|
<!-- KEYWORDS
|
|
activating instances
|
|
deactivating instances
|
|
|
|
instance_deactivate_all()
|
|
instance_deactivate_object()
|
|
instance_deactivate_region()
|
|
instance_activate_all()
|
|
instance_activate_object()
|
|
instance_activate_region()
|
|
|
|
--> |