The_dude8080 Posted October 26, 2016 Share Posted October 26, 2016 Greetings. I am working on a game where the player needs to able to collide with a bitmap. The way to check for collision would be using the bmd method "getPixel()". To simplify things lets imagine the player as a 2d square. I think the best approach would be to create 4 collision rects around the player that would constantly check for a pixel inside of them that has certain properties. In that case activate collision. However I don't know how I can implement this in a good way. Do I need to check for every pixel between rect.X + rect.width for example? Link to comment Share on other sites More sharing options...
squilibob Posted October 26, 2016 Share Posted October 26, 2016 Simply, you can add bitmap data to a sprite and check collision that way var mySprite = game.add.sprite(0, 0, null); var myBitmap = game.add.bitmapData(0, 0); myBitmap.context.fillRect(0,0,length,height); mySprite.loadTexture(myBitmap); or var myBitmap = game.make.bitmapData(800, 600); myBitmap.rect(110, 40, 64, 120, 'rgba(255,255,255,0.8)'); var mySprite = game.add.sprite(0, 0, myBitmap); Link to comment Share on other sites More sharing options...
The_dude8080 Posted October 27, 2016 Author Share Posted October 27, 2016 21 hours ago, squilibob said: Simply, you can add bitmap data to a sprite and check collision that way var mySprite = game.add.sprite(0, 0, null); var myBitmap = game.add.bitmapData(0, 0); myBitmap.context.fillRect(0,0,length,height); mySprite.loadTexture(myBitmap); or var myBitmap = game.make.bitmapData(800, 600); myBitmap.rect(110, 40, 64, 120, 'rgba(255,255,255,0.8)'); var mySprite = game.add.sprite(0, 0, myBitmap); I think that won't work since my bitmap is destroyable which makes it not rect or squared after some destruction Link to comment Share on other sites More sharing options...
Recommended Posts