javascript - Crafty element with 2 gravity's -


i'm trying understand crafty. here's code.

crafty.init(500,300, document.getelementbyid('game'));  crafty.e('floor, 2d, canvas, color')   .attr({x: 0, y: 250, w: 200, h: 10})   .color('green');  crafty.e('secondfloor, 2d, canvas, color')   .attr({x: 250, y: 230, w: 200, h: 10})   .color('red')  crafty.background('#ffffff url(http://samenvattingleren.nl/img/img2.jpg) no-repeat center center');  crafty.e('2d, canvas, color, fourway, gravity')   .attr({x: 25, y: 5, w: 50, h: 50})   .color('orange')   .fourway(4)   .gravity("floor")   .bind('keydown', function(e) {     if(e.key == crafty.keys.left_arrow) {     this.x = this.x - 1;     } else if (e.key == crafty.keys.right_arrow) {         this.x = this.x + 1;     } else if (e.key == crafty.keys.up_arrow) {     this.y = this.y - 1;     } else if (e.key == crafty.keys.down_arrow) {     this.y = this.y + 1;     } else if (e.key == crafty.keys.esc) {         this.x = 0;     }   }) 

i want add

crafty.e('2d, canvas, color, fourway, gravity')       .attr({x: 25, y: 5, w: 50, h: 50})       .color('orange')       .fourway(4)       .gravity("floor")       .gravity("secondfloor") //this want add 

but doesnt work. square still goes trough secondfloor

the "floor" component should thought of kind of tag, you'll add entity should act floor. in example code, there doesn't seem need distinguish between "floor" , "secondfloor", change latter "floor".

if have 2 custom components want act floor, solution have them require "floor" component automatically. instance

crafty.c("iceplatform", {     init: function(){ this.requires("floor"); }     // stuff specific "iceplatform" };  crafty.c("movingplatform", {     init: function(){ this.requires("floor"); }     // stuff specific "movingplatform" }; 

then whenever entity has "movingplatform" or "iceplatform" act "floor", , interact appropriately gravity.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -