Created
October 13, 2016 02:30
-
-
Save shuuki/983baad00728eb1a9421e0812b0e9950 to your computer and use it in GitHub Desktop.
wzXANm
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
#portal |
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
Crafty.init(500, 350, document.getElementById('portal')); | |
Crafty.timer.steptype('variable'); | |
Crafty.e('2D, Canvas, Collision, Color, Twoway, Gravity, solid') | |
.attr({ | |
x: 10, | |
y: 200, | |
w: 24, | |
h: 24 | |
}) | |
.color('red') | |
.twoway(20) | |
.gravity('platform') | |
.gravityConst(300) | |
.bind('EnterFrame', function(eventData) { | |
// Move to the right by 10 pixels per second | |
//console.log(eventData) | |
//this.x = this.x + 10 * (eventData.dt / 1000); | |
}) | |
.checkHits('solid') // check for collisions with entities that have the Solid component in each frame | |
.bind("HitOn", function(hitData) { | |
console.log("Collision with Solid entity occurred for the first time."); | |
}) | |
.bind("HitOff", function(comp) { | |
console.log("Collision with Solid entity ended."); | |
}) | |
;//this | |
Crafty.e('2D, Canvas, Color, Gravity, Collision,solid') | |
.attr({ | |
x: 200, | |
y: 200, | |
w: 24, | |
h: 24 | |
}) | |
.color('cyan') | |
.gravity('platform') | |
.gravityConst(300) | |
.bind('EnterFrame', function(eventData) { | |
// Move to the right by 10 pixels per second | |
//console.log(eventData) | |
this.x = this.x - 50 * (eventData.dt / 1000); | |
}) | |
.checkHits('solid') | |
.bind("HitOn", function(hitData) { | |
this.x = this.x + 50 * (eventData.dt / 1000); | |
}) | |
.bind("HitOff", function(comp) { | |
console.log("Collision with Solid entity ended."); | |
}); | |
Crafty.e('platform, 2D, Canvas, Color') | |
.attr({ | |
x: 0, | |
y: 250, | |
w: 250, | |
h: 100 | |
}) | |
.color('black') | |
.gravity('platform'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment