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
[Question] Color Collision.
Page 1 of 16 Replies - 257 Views - Last Post: 07 October 2012 - 03:09 AM
Replies To: [Question] Color Collision.
#2
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.
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.
#3
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);
}
#4
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.
I'm not seeing anywhere in that code that checks for what the colors of the individual pixels are that are underneath the sprite.
#5
Re: [Question] Color Collision.
Posted 05 October 2012 - 03:36 AM
Ok i have this now
but it still does not work
the spritebox is the picture box i just renamed it
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
#6
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.
#7
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
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|