moto0000 Posted December 19, 2014 Share Posted December 19, 2014 Hi everyone, I have a question, how to do player collision with world bounds ?! Quote Link to comment Share on other sites More sharing options...
PixelPicoSean Posted December 20, 2014 Share Posted December 20, 2014 The world does not have any "bounds" thing, it's an unlimited space. But you can place some "bounds" body to simulate it. Quote Link to comment Share on other sites More sharing options...
moto0000 Posted December 20, 2014 Author Share Posted December 20, 2014 I mean collision with "frame" or "screen" bounds Quote Link to comment Share on other sites More sharing options...
moto0000 Posted December 23, 2014 Author Share Posted December 23, 2014 I wrote a small "plugin" to collide sprite with World Boundsgame.module( 'plugins.worldbounds').body(function() {game.collideWorldBounds = { add: function(sprite, body) { this.sprite = sprite; this.body = body; game.scene.addObject(this); }, update: function() { var width = Math.max( this.sprite.width * (1 - this.sprite.anchor.x), this.body.shape.width / 2 ), height = Math.max( this.sprite.height * (1 - this.sprite.anchor.y), this.body.shape.height / 2 ); // top if(this.body.position.y - height < 0) { this.body.position.y -= this.body.position.y - height; this.body.velocity.y = 0; } // right if(this.body.position.x + width > game.system.width) { this.body.position.x += game.system.width - this.body.position.x - width; this.body.velocity.x = 0; } // bottom if(this.body.position.y + height > game.system.height) { this.body.position.y += game.system.height - this.body.position.y - height; this.body.velocity.y = 0; } // left if(this.body.position.x - width < 0) { this.body.position.x -= this.body.position.x - width; this.body.velocity.x = 0; } }};}); 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.