/
Collision.html
204 lines (191 loc) · 25.9 KB
/
Collision.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Crafty - Collision</title>
<link type="text/css" rel="stylesheet" href="/craftyjs-site.css" />
<link href='http://fonts.googleapis.com/css?family=Arvo:regular,bold' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300,600' rel='stylesheet' type='text/css'>
<link rel="shortcut icon" href="/favicon.ico">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js" type="text/javascript"></script>
<link rel="stylesheet" href="/github.css"/>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-23935213-2']);
_gaq.push(['_trackPageview']);
(function () {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<div id = "header-background"> </div>
<div id = "page-frame">
<div id="header">
<nav class="navbar">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="/"> <img class="logo" src="/images/text-logo.png" /> </a>
</div>
<div class="collapse navbar-collapse navbar-right" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li><a href="/">Home</a></li>
<li><a href="/getting-started/">Getting started</a></li>
<li><a href="/documentation/">Documentation</a></li>
<li><a href="/api/">API</a></li>
<li><a href="https://groups.google.com/forum/#!forum/craftyjs">Forum</a></li>
<li><a href="/components/">Components</a></li>
<li class="emph"><a href="/#install">Download</a></li>
</ul>
</div>
</div>
</nav>
</div>
<div id="main">
<div id="content" class="container">
<div id="docs"><div class="toc-holder" id="doc-nav"><ul id="doc-level-one"><li><a href="events.html">List of Events</a></li><li class="category">Core<ul class="category-list"><li><a href="Crafty.html">Crafty</a></li><li><a href="Crafty Core.html">Crafty Core</a></li><li><a href="Crafty-bind.html">Crafty.bind</a></li><li><a href="Crafty-c.html">Crafty.c</a></li><li><a href="Crafty-clone.html">Crafty.clone</a></li><li><a href="Crafty-e.html">Crafty.e</a></li><li><a href="Crafty-extend.html">Crafty.extend</a></li><li><a href="Crafty-frame.html">Crafty.frame</a></li><li><a href="Crafty-getVersion.html">Crafty.getVersion</a></li><li><a href="Crafty-init.html">Crafty.init</a></li><li><a href="Crafty-isPaused.html">Crafty.isPaused</a></li><li><a href="Crafty-one.html">Crafty.one</a></li><li><a href="Crafty-pause.html">Crafty.pause</a></li><li><a href="Crafty-settings.html">Crafty.settings</a></li><li><a href="Crafty-stage.html">Crafty.stage</a></li><li><a href="Crafty-stop.html">Crafty.stop</a></li><li><a href="Crafty-support.html">Crafty.support</a></li><li><a href="Crafty-trigger.html">Crafty.trigger</a></li><li><a href="Crafty-unbind.html">Crafty.unbind</a></li><li><a href="Crafty-uniqueBind.html">Crafty.uniqueBind</a></li></ul></li><li class="category">2D<ul class="category-list"><li><a href="2D.html">2D</a></li><li><a href="Collision.html">Collision</a></li><li><a href="Crafty-circle.html">Crafty.circle</a></li><li><a href="Crafty-diamondIso.html">Crafty.diamondIso</a></li><li><a href="Crafty-HashMap.html">Crafty.HashMap</a></li><li><a href="Crafty-isometric.html">Crafty.isometric</a></li><li><a href="Crafty-map.html">Crafty.map</a></li><li><a href="Crafty-math.html">Crafty.math</a></li><li><a href="Crafty-math-Matrix2D.html">Crafty.math.Matrix2D</a></li><li><a href="Crafty-math-Vector2D.html">Crafty.math.Vector2D</a></li><li><a href="Crafty-polygon.html">Crafty.polygon</a></li><li><a href="Gravity.html">Gravity</a></li></ul></li><li class="category">Animation<ul class="category-list"><li><a href="SpriteAnimation.html">SpriteAnimation</a></li><li><a href="Tween.html">Tween</a></li></ul></li><li class="category">Assets<ul class="category-list"><li><a href="Crafty-asset.html">Crafty.asset</a></li><li><a href="Crafty-assets.html">Crafty.assets</a></li><li><a href="Crafty-image_whitelist.html">Crafty.image_whitelist</a></li><li><a href="Crafty-loader.html">Crafty.loader</a></li><li><a href="Crafty-paths.html">Crafty.paths</a></li><li><a href="Crafty-removeAssets.html">Crafty.removeAssets</a></li></ul></li><li class="category">Audio<ul class="category-list"><li><a href="Crafty-audio.html">Crafty.audio</a></li></ul></li><li class="category">Debug<ul class="category-list"><li><a href="DebugCanvas.html">DebugCanvas</a></li><li><a href="DebugPolygon.html">DebugPolygon</a></li><li><a href="DebugRectangle.html">DebugRectangle</a></li><li><a href="SolidHitBox.html">SolidHitBox</a></li><li><a href="VisibleMBR.html">VisibleMBR</a></li><li><a href="WiredHitBox.html">WiredHitBox</a></li></ul></li><li class="category">Events<ul class="category-list"><li><a href="Crafty-addEvent.html">Crafty.addEvent</a></li><li><a href="Crafty-bind.html">Crafty.bind</a></li><li><a href="Crafty-one.html">Crafty.one</a></li><li><a href="Crafty-removeEvent.html">Crafty.removeEvent</a></li><li><a href="Crafty-trigger.html">Crafty.trigger</a></li><li><a href="Crafty-unbind.html">Crafty.unbind</a></li><li><a href="Crafty-uniqueBind.html">Crafty.uniqueBind</a></li></ul></li><li class="category">Game Loop<ul class="category-list"><li><a href="Crafty-timer.html">Crafty.timer</a></li></ul></li><li class="category">Graphics<ul class="category-list"><li><a href="Canvas.html">Canvas</a></li><li><a href="Color.html">Color</a></li><li><a href="Crafty-assignColor.html">Crafty.assignColor</a></li><li><a href="Crafty-background.html">Crafty.background</a></li><li><a href="Crafty-canvas.html">Crafty.canvas</a></li><li><a href="Crafty-DOM.html">Crafty.DOM</a></li><li><a href="Crafty-DrawManager.html">Crafty.DrawManager</a></li><li><a href="Crafty-pixelart.html">Crafty.pixelart</a></li><li><a href="Crafty-sprite.html">Crafty.sprite</a></li><li><a href="DOM.html">DOM</a></li><li><a href="HTML.html">HTML</a></li><li><a href="Image.html">Image</a></li><li><a href="Particles.html">Particles</a></li><li><a href="Sprite.html">Sprite</a></li><li><a href="Text.html">Text</a></li></ul></li><li class="category">Input<ul class="category-list"><li><a href="Crafty-eventObject.html">Crafty.eventObject</a></li><li><a href="Crafty-keydown.html">Crafty.keydown</a></li><li><a href="Crafty-keys.html">Crafty.keys</a></li><li><a href="Crafty-mouseButtons.html">Crafty.mouseButtons</a></li><li><a href="Crafty-mouseDispatch.html">Crafty.mouseDispatch</a></li><li><a href="Crafty-touchDispatch.html">Crafty.touchDispatch</a></li><li><a href="Draggable.html">Draggable</a></li><li><a href="Fourway.html">Fourway</a></li><li><a href="Keyboard.html">Keyboard</a></li><li><a href="KeyboardEvent.html">KeyboardEvent</a></li><li><a href="Mouse.html">Mouse</a></li><li><a href="Multiway.html">Multiway</a></li><li><a href="Twoway.html">Twoway</a></li></ul></li><li class="category">Misc<ul class="category-list"><li><a href="Crafty-addEvent.html">Crafty.addEvent</a></li><li><a href="Crafty-device.html">Crafty.device</a></li><li><a href="Crafty-removeEvent.html">Crafty.removeEvent</a></li><li><a href="Crafty-support.html">Crafty.support</a></li></ul></li><li class="category">Model<ul class="category-list"><li><a href="Model.html">Model</a></li></ul></li><li class="category">Scenes<ul class="category-list"><li><a href="Crafty-scene.html">Crafty.scene</a></li></ul></li><li class="category">Stage<ul class="category-list"><li><a href="Crafty-background.html">Crafty.background</a></li><li><a href="Crafty-scene.html">Crafty.scene</a></li><li><a href="Crafty-viewport.html">Crafty.viewport</a></li></ul></li><li class="category">Utilities<ul class="category-list"><li><a href="Delay.html">Delay</a></li><li><a href="Storage.html">Storage</a></li></ul></li></ul></div><div id="doc-content" class="doc-page-holder"><div class="doc-page"><h1>Collision</h1><div id="Collision"><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/b74c13c0cc74f8773bb2bf563009728113ac751c/src/collision.js#L5-23">src/collision.js#L5-23</a></div><div class="triggered-events"><h4>Events</h4><div class="trigger-list"><dl class="trigger"><dt>HitOn <span class="trigger-data">[ Data { { hitData } }]</span></dt><dd>Triggered when collisions occur. Will not trigger again until collisions of this type cease, or an event is requested once more (using `resetHitChecks(component)`).</dd></dl><dl class="trigger"><dt>HitOff <span class="trigger-data">[ Data { { componentName } }]</span></dt><dd>Triggered when collision with a specific component type ceases</dd></dl></div></div><span class="markdown"><p>Component to detect collision between any two convex polygons.</p>
<p>If collision checks are registered for multiple component and collisions with
multiple types occur simultaniously, each collision will cause an individual
event to fire.</p>
<p><strong>Note:</strong> All data received from events is only valid for the duration of the event's callback.
If you wish to preserve the data, make a copy of it.</p>
<p>For a description of collision event data (hitData above), see the documentation for
<code>.hit()</code>.</p>
</span><div><h4>See Also</h4><ul class="see-also-list"><li><a href="-hit.html">.hit</a></li><li><a href="-checkHits.html">.checkHits</a></li><li><a href="-onHit.html">.onHit</a></li></ul></div></div><div><h4>Methods and Properties</h4><ul class="page-toc"><li><a href="#-_createCollisionHandler">._createCollisionHandler</a></li><li><a href="#-checkHits">.checkHits</a></li><li><a href="#-collision">.collision</a></li><li><a href="#-hit">.hit</a></li><li><a href="#-ignoreHits">.ignoreHits</a></li><li><a href="#-init">.init</a></li><li><a href="#-onHit">.onHit</a></li><li><a href="#-resetHitChecks">.resetHitChecks</a></li></ul><div id="._createCollisionHandler"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">._createCollisionHandler</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/b74c13c0cc74f8773bb2bf563009728113ac751c/src/collision.js#L343-355">src/collision.js#L343-355</a></div><div class="crafty-method"><code class="signature">public void .checkHits(String component, Object collisionData)</code><dl class="parameter"><dt> component </dt><dd><span class="markdown"><p>The name of the component for which this handler</p>
</span></dd></dl><span class="markdown"><p>checks for collisions.</p>
</span><dl class="parameter"><dt> collisionData </dt><dd><span class="markdown"><p>Collision data object used to track collisions with</p>
</span></dd></dl></div><span class="markdown"><p>the specified component.</p>
<p>This is a helper method for creating collisions handlers set up by
<code>.checkHits(...)</code>. Do not call this directly.</p>
</span><div><h4>See Also</h4><ul class="see-also-list"><li><a href="-checkHits.html">.checkHits</a></li></ul></div></div><div id=".checkHits"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.checkHits</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/b74c13c0cc74f8773bb2bf563009728113ac751c/src/collision.js#L377-415">src/collision.js#L377-415</a></div><div class="crafty-method"><code class="signature">public this .checkHits(String componentList)</code><dl class="parameter"><dt> componentList </dt><dd><span class="markdown"><p>A comma seperated list of components to check for collisions with.</p>
</span></dd></dl></div><div class="crafty-method"><code class="signature">public this .checkHits(String component1[, .., String componentN])</code><dl class="parameter"><dt> component# </dt><dd><span class="markdown"><p>A component to check for collisions with.</p>
</span></dd></dl></div><span class="markdown"><p>Performs collision checks against all entities that have at least one of
the components specified when calling this method. If collisions occur,
a "HitOn" event containing the collision information will be fired for the
entity on which this method was invoked. See the documentation for <code>.hit()</code>
for a description of collision data contained in the event.
When a collision that was reported ends, a corresponding "HitOff" event
will be fired.</p>
<p>Calling this method more than once for the same component type will not
cause redundant hit checks.</p>
<p><strong>Note:</strong> Hit checks are performed upon entering each new frame (using
the <em>EnterFrame</em> event). It is entirely possible for object to move in
said frame after the checks were performed (even if the more is the
result of <em>EnterFrame</em>, as handlers run in no particular order). In such
a case, the hit events will not fire until the next check is performed in
the following frame.</p>
</span><div class="example"><h4>Example</h4><span class="markdown"><pre><code class="hljs ">Crafty.e(<span class="hljs-string">"2D, Collision"</span>)
.checkHits(<span class="hljs-string">'Solid'</span>) <span class="hljs-comment">// check for collisions with entities that have the Solid component in each frame</span>
.bind(<span class="hljs-string">"HitOn"</span>, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(hitData)</span> </span>{
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Collision with Solid entity occurred for the first time."</span>);
})
.bind(<span class="hljs-string">"HitOff"</span>, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(comp)</span> </span>{
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Collision with Solid entity ended."</span>);
});</code></pre></span></div><div><h4>See Also</h4><ul class="see-also-list"><li><a href="-hit.html">.hit</a></li></ul></div></div><div id=".collision"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.collision</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/b74c13c0cc74f8773bb2bf563009728113ac751c/src/collision.js#L51-81">src/collision.js#L51-81</a></div><span class="markdown"></span><div class="triggered-events"><h4>Events</h4><div class="trigger-list"><dl class="trigger"><dt>NewHitbox <span class="trigger-data">[ Data { Crafty.polygon }]</span></dt><dd>when a new hitbox is assigned</dd></dl></div></div><span class="markdown"></span><div class="crafty-method"><code class="signature">public this .collision([Crafty.polygon polygon])</code><dl class="parameter"><dt> polygon </dt><dd><span class="markdown"><p>Crafty.polygon object that will act as the hit area.</p>
</span></dd></dl></div><span class="markdown"></span><div class="crafty-method"><code class="signature">public this .collision(Array point1, .., Array pointN)</code><dl class="parameter"><dt> point# </dt><dd><span class="markdown"><p>Array of [x, y] coordinate pairs to generate a hit area polygon.</p>
</span></dd></dl></div><span class="markdown"><p>Constructor that takes a polygon or array of points to use as the hit area,
with points being relative to the object's position in its unrotated state.</p>
<p>The hit area must be a convex shape and not concave for collision detection to work properly.</p>
<p>If no parameter is passed, the x, y, w, h properties of the entity will be used, and the hitbox will be resized when the entity is.</p>
<p>If a hitbox is set that is outside of the bounds of the entity itself, there will be a small performance penalty as it is tracked separately.</p>
</span><div class="example"><h4>Example</h4><span class="markdown"><pre><code class="hljs ">Crafty.e(<span class="hljs-string">"2D, Collision"</span>).collision(
<span class="hljs-keyword">new</span> Crafty.polygon([<span class="hljs-number">50</span>,<span class="hljs-number">0</span>], [<span class="hljs-number">100</span>,<span class="hljs-number">100</span>], [<span class="hljs-number">0</span>,<span class="hljs-number">100</span>])
);
Crafty.e(<span class="hljs-string">"2D, Collision"</span>).collision([<span class="hljs-number">50</span>,<span class="hljs-number">0</span>], [<span class="hljs-number">100</span>,<span class="hljs-number">100</span>], [<span class="hljs-number">0</span>,<span class="hljs-number">100</span>]);</code></pre></span></div><div><h4>See Also</h4><ul class="see-also-list"><li><a href="Crafty-polygon.html">Crafty.polygon</a></li></ul></div></div><div id=".hit"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.hit</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/b74c13c0cc74f8773bb2bf563009728113ac751c/src/collision.js#L226-257">src/collision.js#L226-257</a></div><div class="crafty-method"><code class="signature">public Boolean/Array hit(String component)</code><dl class="parameter"><dt> component </dt><dd><span class="markdown"><p>Check collision with entities that have this component</p>
</span></dd></dl><span class="markdown"><p>applied to them.</p>
</span><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p><code>false</code> if there is no collision. If a collision is detected,</p>
</span></dd></dl></div><span class="markdown"><p>returns an Array of collision data objects (see below).</p>
<p>Tests for collisions with entities that have the specified component
applied to them.
If a collision is detected, data regarding the collision will be present in
the array returned by this method.
If no collisions occur, this method returns false.</p>
<p>Following is a description of a collision data object that this method may
return: The returned collision data will be an Array of Objects with the
type of collision used, the object collided and if the type used was SAT (a polygon was used as the hitbox) then an amount of overlap.</p>
<pre><code class="hljs ">[{
obj: [entity],
type: [<span class="hljs-string">"MBR"</span> or <span class="hljs-string">"SAT"</span>],
overlap: [number]
}]</code></pre><p><strong>obj:</strong> The entity with which the collision occured.
<strong>type:</strong> Collision detection method used. One of:</p>
<ul>
<li><em>MBR:</em> Standard axis aligned rectangle intersection (<code>.intersect</code> in the 2D component).</li>
<li><em>SAT:</em> Collision between any two convex polygons. Used when both colliding entities have the <code>Collision</code> component applied to them.
<strong>overlap:</strong> If SAT collision was used, this will signify the overlap percentage between the colliding entities.</li>
</ul>
</span><div><h4>See Also</h4><ul class="see-also-list"><li><a href="2D.html">2D</a></li></ul></div></div><div id=".ignoreHits"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.ignoreHits</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/b74c13c0cc74f8773bb2bf563009728113ac751c/src/collision.js#L443-468">src/collision.js#L443-468</a></div><div class="crafty-method"><code class="signature">public this .ignoreHits()</code></div><div class="crafty-method"><code class="signature">public this .ignoreHits(String componentList)</code><dl class="parameter"><dt> componentList </dt><dd><span class="markdown"><p>A comma seperated list of components to stop checking</p>
</span></dd></dl></div><span class="markdown"><p>for collisions with.</p>
</span><div class="crafty-method"><code class="signature">public this .ignoreHits(String component1[, .., String componentN])</code><dl class="parameter"><dt> component# </dt><dd><span class="markdown"><p>A component to stop checking for collisions with.</p>
</span></dd></dl></div><span class="markdown"><p>Stops checking for collisions with all, or certain, components. If called
without arguments, this method will cause all collision checks on the
entity to cease. To disable checks for collisions with specific
components, specify the components as a comma separated string or as
a set of arguments.</p>
<p>Calling this method with component names for which there are no collision
checks has no effect.</p>
</span><div class="example"><h4>Example</h4><span class="markdown"><pre><code class="hljs ">Crafty.e(<span class="hljs-string">"2D, Collision"</span>)
.checkHits(<span class="hljs-string">'Solid'</span>)
...
.ignoreHits(<span class="hljs-string">'Solid'</span>); <span class="hljs-comment">// stop checking for collisions with entities that have the Solid component</span></code></pre></span></div></div><div id=".init"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.init</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/b74c13c0cc74f8773bb2bf563009728113ac751c/src/collision.js#L26-34">src/collision.js#L26-34</a></div><span class="markdown"><p>Set up collision handling.</p>
<p>By default, the collision hitbox will match the dimensions (x, y, w, h) and rotation of the object.</p>
<p><strong>Note:</strong> If the entity this component is applied to does not have its
dimensions set the default hit area will not be set properly.</p>
</span></div><div id=".onHit"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.onHit</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/b74c13c0cc74f8773bb2bf563009728113ac751c/src/collision.js#L310-323">src/collision.js#L310-323</a></div><div class="crafty-method"><code class="signature">public this .onHit(String component, Function hit[, Function noHit])</code><dl class="parameter"><dt> component </dt><dd><span class="markdown"><p>Component to check collisions for.</p>
</span></dd></dl><dl class="parameter"><dt> hit </dt><dd><span class="markdown"><p>Callback method to execute upon collision with component. Will be passed the results of the collision check in the same format documented for hit().</p>
</span></dd></dl><dl class="parameter"><dt> noHit </dt><dd><span class="markdown"><p>Callback method executed once as soon as collision stops.</p>
</span></dd></dl></div><span class="markdown"><p>Creates an EnterFrame event calling .hit() each frame. When a collision is detected the callback will be invoked.
Note that the <code>hit</code> callback will be invoked every frame the collision is active, not just the first time the collision occurs.
If you want more fine-grained control consider using <code>.checkHits</code> or <code>.hit</code>.</p>
</span><div><h4>See Also</h4><ul class="see-also-list"><li><a href="-checkHits.html">.checkHits</a></li><li><a href="-hit.html">.hit</a></li></ul></div></div><div id=".resetHitChecks"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.resetHitChecks</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/b74c13c0cc74f8773bb2bf563009728113ac751c/src/collision.js#L502-532">src/collision.js#L502-532</a></div><div class="crafty-method"><code class="signature">public this .resetHitChecks()</code></div><div class="crafty-method"><code class="signature">public this .resetHitChecks(String componentList)</code><dl class="parameter"><dt> componentList </dt><dd><span class="markdown"><p>A comma seperated list of components to re-check</p>
</span></dd></dl></div><span class="markdown"><p>for collisions with.</p>
</span><div class="crafty-method"><code class="signature">public this .resetHitChecks(String component1[, .., String componentN])</code><dl class="parameter"><dt> component# </dt><dd><span class="markdown"><p>A component to re-check for collisions with.</p>
</span></dd></dl></div><span class="markdown"><p>Causes collision events to be received for collisions that are already
taking place (normally, an additional event would not fire before said
collisions cease and happen another time).
If called without arguments, this method will cause all collision checks on the
entity to fire events once more. To re-check for collisions with specific
components, specify the components as a comma separated string or as
a set of arguments.</p>
<p>Calling this method with component names for which there are no collision
checks has no effect.</p>
</span><div class="example"><h4>Example</h4><span class="markdown"><pre><code class="hljs "><span class="hljs-comment">// this example fires the HitOn event each frame the collision with the Solid entity is active, instead of just the first time the collision occurs.</span>
Crafty.e(<span class="hljs-string">"2D, Collision"</span>)
.checkHits(<span class="hljs-string">'Solid'</span>)
.bind(<span class="hljs-string">"HitOn"</span>, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(hitData)</span> </span>{
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Collision with Solid entity was reported in this frame again!"</span>);
<span class="hljs-keyword">this</span>.resetHitChecks(<span class="hljs-string">'Solid'</span>); <span class="hljs-comment">// fire the HitOn event in the next frame also, if the collision is still active.</span>
})</code></pre></span></div></div></div></div></div></div>
</div>
</div>
<div class="clearer"></div>
<div id="footer">
<div id="contact">
<a href="https://groups.google.com/forum/#!forum/craftyjs">
<img src="/images/google.png" />
google groups</a>
<a href="mailto:starwed@gmail.com">
<img src="/images/email.png" />
starwed@gmail.com</a>
<a href="https://github.com/craftyjs/Crafty">
<img src="/images/github.png" />
github</a>
</div>
<ul>
<li><a href="/">Home</a></li>
<li><a href="/getting-started/">Getting started</a></li>
<li><a href="/documentation/">Documentation</a></li>
<li><a href="/api/">API</a></li>
<li><a href="https://groups.google.com/forum/#!forum/craftyjs">Forum</a></li>
<li><a href="/modules/">Modules</a></li>
<li class="emph"><a href="/download/">Download</a></li>
</ul>
<p>
© Crafty 2010-2015. Crafty is distributed under the <a href="http://en.wikipedia.org/wiki/MIT_License">MIT</a> or <a href="http://en.wikipedia.org/wiki/GNU_General_Public_License">GPL</a>
license.
</p>
</div>
</div>
</body>
</html>