6 Replies - 554 Views - Last Post: 07 October 2012 - 03:09 AM Rate Topic: -----

#1 mumbot  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 04-October 12

[Question] Color Collision.

Posted 04 October 2012 - 05:29 PM

Hello all C# coders i am have some trouble figuring out how to make my picturebox collide with colors in C#
my Picturebox is called spritebox so basically i want to know when the spritebox hits the color Cyan it moves to center screen iv already coded keys to move the spritebox but now the only thing im a bit stuck on is how to make the spritebox go to the center of the screen when collided with Cyan
Is This A Good Question/Topic? 0
  • +

Replies To: [Question] Color Collision.

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3631
  • View blog
  • Posts: 11,327
  • Joined: 05-May 12

Re: [Question] Color Collision.

Posted 04 October 2012 - 06:34 PM

If you are rendering the sprite yourself, then you'll know that you've collided with a cyan colored pixel because you need to get the background color anyway if you are doing transparencies or any alpha blending.

If you are using a prepackaged sprite rendering routine, then see if you there is an event or callback function that you can use.

If there is no such callback or event, then you'll have to simulate rendering the sprite yourself and inspect every background pixel before the sprite gets rendered otherwise your cyan colored pixel will not be cyan anymore.
Was This Post Helpful? 0
  • +
  • -

#3 mumbot  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 04-October 12

Re: [Question] Color Collision.

Posted 04 October 2012 - 06:45 PM

Ok so well this is what i added there is no error with the code it just does not work

 var C = Color.Cyan;

 if (BackColor == C)
            {
                spritebox.Location = new Point(310, 300);
            }

Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3631
  • View blog
  • Posts: 11,327
  • Joined: 05-May 12

Re: [Question] Color Collision.

Posted 04 October 2012 - 09:46 PM

There is not enough context in that bit of code. What is Backcolor? Is it a member of a form? Is it the color at a particular location on screen? What is spritebox?

I'm not seeing anywhere in that code that checks for what the colors of the individual pixels are that are underneath the sprite.
Was This Post Helpful? 0
  • +
  • -

#5 mumbot  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 04-October 12

Re: [Question] Color Collision.

Posted 05 October 2012 - 03:36 AM

Ok i have this now

 if (spritebox.BackColor == C)
            {
                spritebox.Location = new Point(310, 300);
            }


but it still does not work

the spritebox is the picture box i just renamed it
Was This Post Helpful? 0
  • +
  • -

#6 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3631
  • View blog
  • Posts: 11,327
  • Joined: 05-May 12

Re: [Question] Color Collision.

Posted 05 October 2012 - 06:46 AM

The PictureBox class does no collision detection on its own. It'll just draw the image that you put in it at the location that you set for the PictureBox. You'll need to get the pixels that will will overwritten by the PictureBox and see if there will be a collision.
Was This Post Helpful? 0
  • +
  • -

#7 mumbot  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 04-October 12

Re: [Question] Color Collision.

Posted 07 October 2012 - 03:09 AM

Im sorry but i am not sure how to do that can you please show me some code its easy for me to study it and learn if you can that would be great cheers :D
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1