Jump to content

Collision


lars
 Share

Recommended Posts

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();        },    });}); //body

Any help would be so kind :-)

 

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...