lars Posted October 26, 2015 Share Posted October 26, 2015 Simple ... cant make this work game.module( 'game.main').body(function() { game.addAsset('_ninja_1.png', 'ninja'); game.addAsset('pumkings.png', 'pumkings'); //game.addAsset('ninja.json'); game.addAudio('swipe.mp3', 'swipe'); game.createClass('Alien', { speed: 500, init: function() { this.sprite = new game.Sprite('ninja'); this.sprite.anchor.set(0.5, 0.5); this.body = new game.Body({ position: { x: game.system.width / 2, y: game.system.height - this.sprite.height / 2 }, //velocityLimit: { x: 150, y: 150 }, velocity: { x: 0, y: 0 }, collisionGroup: 1, collideAgainst: [0], mass: 0 }); this.body.collide = this.collide.bind(this); this.body.addShape(new game.Rectangle(this.sprite.width, this.sprite.height)); game.scene.addObject(this); game.scene.world.addBody(this.body); game.scene.stage.addChild(this.sprite); }, //init collide: function(opponent) { console.log("Collision!"); }, update: function() { if (this.body.position.x > game.system.width) this.body.position.x = game.system.width; if (this.body.position.x < 0) this.body.position.x = 0; if (game.keyboard.down('LEFT')) this.body.velocity.x = -this.speed; else if (game.keyboard.down('RIGHT')) this.body.velocity.x = this.speed; else this.body.velocity.x = 0; this.sprite.position.x = this.body.position.x; this.sprite.position.y = this.body.position.y; }, }); game.createClass('Pumpkins', { init: function() { this.radius = 40; this.sprite = new game.Sprite('pumkings'); this.sprite.anchor.set(0.5, 0.5); this.body = new game.Body({ position: { x: 100, y: game.system.height - this.sprite.height + 50 }, velocity: { x: 0, y: 0 }, collisionGroup: 0, collideAgainst: [1], mass: 0 }); this.body.collide = this.collide.bind(this); this.body.addShape(new game.Circle(this.radius)); game.scene.addObject(this); game.scene.world.addBody(this.body); game.scene.stage.addChild(this.sprite); }, collide: function(opponent) { console.log('Collision!') }, update: function() { this.sprite.position.x = this.body.position.x; this.sprite.position.y = this.body.position.y; //this.body.position.x += 50 * game.system.delta; } }); game.createScene('Main', { backgroundColor: 0x630909, init: function() { console.log("Scene"); this.world = new game.World(0, 0); this.initGame(); }, initGame: function() { pumkings = new game.Pumpkins(); player = new game.Alien(); }, });}); //bodyAny help would be so kind :-) Quote Link to comment Share on other sites More sharing options...
Stephan Posted October 27, 2015 Share Posted October 27, 2015 Hi Lars,collision detection between a circle and a ractangle is not support yet. Try two circles and it will probably work like a charm! Quote Link to comment Share on other sites More sharing options...
lars Posted October 28, 2015 Author Share Posted October 28, 2015 Thank´s that did it :-) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.