airpower58 Posted May 3, 2014 Share Posted May 3, 2014 I am having trouble adding a sprite to this code instead of having an invisible shape that gives you points I would like to have a coin to collect which gives you points but I cant seem to get it to work could someone tell me what the code should look like if i want to add a sprite to collect this.goalBody = new game.Body({ position: {x: game.system.width + this.width / 2 + this.width + game.scene.player.body.shape.width, y: topHeight + this.height / 2}, velocity: {x: this.speed}, collisionGroup: 1, collideAgainst: 1 }); this.goalBody.collide = function() { game.scene.world.removeBody(this); game.scene.addScore(); return false; }; var goalShape = new game.Sprite('media/powerup.png', this.width, this.height + game.scene.player.body.shape.height); this.sprite.anchor.x = this.sprite.anchor.y = 0.5; this.goalBody.addShape(goalShape); game.scene.world.addChild(this.Sprite); game.scene.world.addBody(this.goalBody); }, Thanks for any help Quote Link to comment Share on other sites More sharing options...
maho125 Posted May 3, 2014 Share Posted May 3, 2014 Hi @airpower58, look at this. Maybe it helps you http://www.demos.tomasmahrik.com/physicsdemo1/ Quote Link to comment Share on other sites More sharing options...
airpower58 Posted May 4, 2014 Author Share Posted May 4, 2014 Thanks this helped me out a lot I managed to do what I wanted to do 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.