Jump to content

Check collision with bitmap?


The_dude8080
 Share

Recommended Posts

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

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

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

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...