-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add permeability example and doc entry
- Loading branch information
Showing
3 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
(function() { | ||
|
||
var World = Matter.World, | ||
Bodies = Matter.Bodies, | ||
Common = Matter.Common, | ||
Events = Matter.Events; | ||
|
||
Example.permeableObjects = function(demo) { | ||
var engine = demo.engine, | ||
world = engine.world, | ||
sceneEvents = demo.sceneEvents; | ||
|
||
var redColor = '#C44D58', | ||
greenColor = '#C7F464'; | ||
|
||
var collider = Bodies.rectangle(400, 300, 500, 50, { | ||
isPermeable: true, | ||
isStatic: true, | ||
render: { | ||
strokeStyle: redColor, | ||
fillStyle: 'transparent' | ||
} | ||
}); | ||
|
||
World.add(world, collider); | ||
|
||
World.add(world, | ||
Bodies.circle(400, 40, 30, { | ||
render: { | ||
strokeStyle: greenColor, | ||
fillStyle: 'transparent' | ||
} | ||
}) | ||
); | ||
|
||
sceneEvents.push( | ||
Events.on(engine, 'collisionStart', function(event) { | ||
var pairs = event.pairs; | ||
|
||
for (var i = 0, j = pairs.length; i != j; ++i) { | ||
var pair = pairs[i]; | ||
|
||
if (pair.bodyA === collider) { | ||
pair.bodyB.render.strokeStyle = redColor; | ||
} else if (pair.bodyB === collider) { | ||
pair.bodyA.render.strokeStyle = redColor; | ||
} | ||
} | ||
}), | ||
Events.on(engine, 'collisionEnd', function(event) { | ||
var pairs = event.pairs; | ||
|
||
for (var i = 0, j = pairs.length; i != j; ++i) { | ||
var pair = pairs[i]; | ||
|
||
if (pair.bodyA === collider) { | ||
pair.bodyB.render.strokeStyle = greenColor; | ||
} else if (pair.bodyB === collider) { | ||
pair.bodyA.render.strokeStyle = greenColor; | ||
} | ||
} | ||
}) | ||
); | ||
|
||
var renderOptions = engine.render.options; | ||
renderOptions.wireframes = false; | ||
renderOptions.background = '#222'; | ||
renderOptions.showAngleIndicator = false; | ||
}; | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters