Joss Posted May 14, 2013 Share Posted May 14, 2013 Hi, I've knocked up a simple game using js and pixi.js, very basic but want to include collision detection, I realise pixi.js doesn't do that, but can anyone recommend a simple but effective way to handle that which work with pixi.js? I want to know when two sprites touch on the screen for my game 'stab the crab'! Thanks Joss Quote Link to comment Share on other sites More sharing options...
Mat Groves Posted May 14, 2013 Share Posted May 14, 2013 Stap the crab! Sounds ace For most of the games I usually keep collision down to its simplest form.. either using rectangle collision or circle collision. Run Pixie Run uses rectangle collision detection as its super fast (which means its great for mobile). GAME.CollisionManager.prototype.playerVsPickup = function(){ var pickups = this.engine.pickupManager.pickups; var steve = this.engine.steve; // yes, he is called steve for (var i = 0; i < pickups.length; i++) { var pickup = pickups[i] var xdist = pickup.position.x - steve.position.x; if(xdist > -pickup.width/2 && xdist < pickup.width/2) { var ydist = pickup.position.y - steve.position.y; if(ydist > -pickup.height/2 && ydist < pickup.height/2) { // HIT CODE!! } } }} hope that helps! jaevelgames 1 Quote Link to comment Share on other sites More sharing options...
Joss Posted May 15, 2013 Author Share Posted May 15, 2013 Thanks for that bit of code, although I'm totally new to developing games of any sort, so not really sure what to do with it, presumably I need to include a JS file for a gaming engine? My current game is purely straight JS and pixi.js Quote Link to comment Share on other sites More sharing options...
Joss Posted May 16, 2013 Author Share Posted May 16, 2013 Actually figured out how to modify it, and it works great, thanks. Once I realised pickups were the things colliding with my crab, which in this code is steve. Quote Link to comment Share on other sites More sharing options...
Mat Groves Posted May 17, 2013 Share Posted May 17, 2013 great to hear 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.