<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wikidot="http://www.wikidot.com/rss-namespace">

	<channel>
		<title>Help Collision Detection XnA 4.0 C# (Noob Programmer)</title>
		<link>http://rbwhitaker.wikidot.com/forum/t-1032233/help-collision-detection-xna-4-0-c-noob-programmer</link>
		<description>Posts in the discussion thread &quot;Help Collision Detection XnA 4.0 C# (Noob Programmer)&quot; - I&#039;m currently studying programming I&#039;m using XNA4.0, C#, Visual Studio 10. I&#039;m trying to simply remove the sprite from the screen after they collide and the user to get points</description>
				<copyright></copyright>
		<lastBuildDate>Wed, 13 May 2026 19:34:33 +0000</lastBuildDate>
		
					<item>
				<guid>http://rbwhitaker.wikidot.com/forum/t-1032233#post-2120538</guid>
				<title>Re: Help Collision Detection XnA 4.0 C# (Noob Programmer)</title>
				<link>http://rbwhitaker.wikidot.com/forum/t-1032233/help-collision-detection-xna-4-0-c-noob-programmer#post-2120538</link>
				<description></description>
				<pubDate>Sun, 28 Sep 2014 18:34:53 +0000</pubDate>
				<wikidot:authorName>Cerberus666</wikidot:authorName>				<wikidot:authorUserId>1985321</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Thanks you helped alot, but when the main sprite hovers over that area the points go up even when the image is gone</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://rbwhitaker.wikidot.com/forum/t-1032233#post-2119943</guid>
				<title>Re: Help Collision Detection XnA 4.0 C# (Noob Programmer)</title>
				<link>http://rbwhitaker.wikidot.com/forum/t-1032233/help-collision-detection-xna-4-0-c-noob-programmer#post-2119943</link>
				<description></description>
				<pubDate>Sat, 27 Sep 2014 21:47:53 +0000</pubDate>
				<wikidot:authorName>Emblis</wikidot:authorName>				<wikidot:authorUserId>1671135</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Hello Cerberus666!</p> <p>First of all, stick with either 2D or 3D, do not mix them unless you have reason to. I am guessing you are doing a 2D game, so change all Vector3 to Vector2. Do not use volume checks (Bounding Sphere) in 2D worlds. Stick with rectangles, triangles and circles.</p> <p>The 2DTexture is essentially a rectangle, so you can use it just as any other.</p> <div class="code"> <pre><code>YourTexture.Contains(SomePoint) //Or YourTexture.Intersect(OtherRectangle)</code></pre></div> <p>Here are some additional ideas:<br /> -I strongly recommend you to rename your Sprite class, the name is very confusing for someone reading your code.<br /> -Do not show the score in the window title. Use a SpriteFont instead.<br /> -You can use a list to keep all the game´s entities in and simply iterate trough the list every game update.</p> <p>Good luck!</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://rbwhitaker.wikidot.com/forum/t-1032233#post-2119927</guid>
				<title>Re: Help Collision Detection XnA 4.0 C# (Noob Programmer)</title>
				<link>http://rbwhitaker.wikidot.com/forum/t-1032233/help-collision-detection-xna-4-0-c-noob-programmer#post-2119927</link>
				<description></description>
				<pubDate>Sat, 27 Sep 2014 21:28:37 +0000</pubDate>
				<wikidot:authorName>PiscesMike</wikidot:authorName>				<wikidot:authorUserId>1721619</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>You'll need to add a bool which tracks if the secondary sprite (Sprite2?) is visible.<br /> Something like:</p> <div class="code"> <pre><code>Bool isVisible=true; //start out so it IS visible</code></pre></div> <p>then, in your rendering code, change the third render call to:</p> <div class="code"> <pre><code>if(isVisible) {spriteBatch.Draw(Sprite2.image, Sprite2.rect, null, Color.DarkSlateBlue, Sprite2.rotation, Sprite2.origin, SpriteEffects.None, 0);}</code></pre></div> <p>then it's simply a matter of setting isVisible to false when you detect a collision!</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://rbwhitaker.wikidot.com/forum/t-1032233#post-2119820</guid>
				<title>Help Collision Detection XnA 4.0 C# (Noob Programmer)</title>
				<link>http://rbwhitaker.wikidot.com/forum/t-1032233/help-collision-detection-xna-4-0-c-noob-programmer#post-2119820</link>
				<description></description>
				<pubDate>Sat, 27 Sep 2014 18:23:51 +0000</pubDate>
				<wikidot:authorName>Cerberus666</wikidot:authorName>				<wikidot:authorUserId>1985321</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <div class="code"> <pre><code>{ /// &lt;summary&gt; /// Alan Carstairs /// 26/9/14 /// &lt;/summary&gt; public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; int DisplayWidth; int DisplayHeight; const float speed = 2.4f; //speed of image int PlayerScore = 0; // //structure for 2D graphics struct graphic2D { public Texture2D image; public Rectangle rect; } //structure for moving 2D graphics struct sprite2D { public Texture2D image; //Texture to hold the image public Vector3 position; //Position on screen public Rectangle rect; //Size &amp; position public Vector2 origin; //Center point public float size; //Size ratio public float rotation;//Amount of rotation public Vector3 velocity; //Sprite speed and direction public float thrust; //Amount of thrust applied public BoundingSphere bsphere;//Bounding sphere //public int spriteNum = 1; //public int maxSpriteNum; //public bool alive; //public Enemy(Texture2D Texture, Vector3 position, Vector3 velocity, } sprite2D Sprite, Sprite2; graphic2D BackGround; Boolean GameOver; public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = &quot;Content&quot;; } /// &lt;summary&gt; /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// &lt;/summary&gt; protected override void Initialize() { // TODO: Add your initialization logic here DisplayWidth = graphics.GraphicsDevice.Viewport.Width; DisplayHeight = graphics.GraphicsDevice.Viewport.Height; base.Initialize(); } /// &lt;summary&gt; /// LoadContent will be called once per game and is the place to load /// all of your content. /// &lt;/summary&gt; protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); //Load BackGround BackGround.image = Content.Load&lt;Texture2D&gt;(&quot;fullmoon&quot;); // work out the ratio for image depending on screen size float ratio = ((float)DisplayWidth / BackGround.image.Width); BackGround.rect.Width = DisplayWidth; BackGround.rect.Height = (int)(BackGround.image.Height * ratio); BackGround.rect.X = 0; BackGround.rect.Y = (DisplayHeight - BackGround.rect.Height) / 2; //Sprite Sprite.image = Content.Load&lt;Texture2D&gt;(&quot;raptor&quot;); //Sprite2 Sprite2.image = Content.Load&lt;Texture2D&gt;(&quot;raptor2&quot;); reset(); // TODO: use this.Content to load your game content here } void reset() { //sprite // Set initial position Sprite.position = new Vector3(DisplayWidth / 2, DisplayHeight / 2, 0); Sprite.size = 0.2f; // set size of sprite Sprite.origin.X = Sprite.image.Width / 2; Sprite.origin.Y = Sprite.image.Height / 2; Sprite.rect.Width = (int)(Sprite.image.Width * Sprite.size); Sprite.rect.Height = (int)(Sprite.image.Height * Sprite.size); Sprite.rotation = 0;//speed of rotation //sprite2 // Set initial position Sprite2.position = new Vector3(DisplayWidth / 2, DisplayHeight / 4, 0); Sprite2.size = 0.2f; // set size of sprite Sprite2.origin.X = Sprite2.image.Width / 2; Sprite2.origin.Y = Sprite2.image.Height / 2; Sprite2.rect.Width = (int)(Sprite2.image.Width * Sprite2.size); Sprite2.rect.Height = (int)(Sprite2.image.Height * Sprite2.size); Sprite2.rotation = 0;//speed of rotation GameOver = false; } /// &lt;summary&gt; /// UnloadContent will be called once per game and is the place to unload /// all content. /// &lt;/summary&gt; protected override void UnloadContent() { // TODO: Unload any non ContentManager content here } /// &lt;summary&gt; /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// &lt;/summary&gt; /// &lt;param name=&quot;gameTime&quot;&gt;Provides a snapshot of timing values.&lt;/param&gt; protected override void Update(GameTime gameTime) { GamePadState pad_P1 = GamePad.GetState(PlayerIndex.One);//reads gamepad 1 KeyboardState keys = Keyboard.GetState(); // reads keyboard // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); if (!GameOver) { //collision detection if (Sprite.bsphere.Intersects(Sprite2.bsphere)) { Sprite.image = null; PlayerScore++;// increase Points } //Display score in top lefthand side of the screen this.Window.Title = &quot;Score: &quot; + PlayerScore.ToString(); //sprite Sprite.thrust = (speed * (pad_P1.Triggers.Right + 2));// calculate the amount of thrust based on speen and right trigger Sprite.velocity.X = pad_P1.ThumbSticks.Right.X; Sprite.velocity.Y = -pad_P1.ThumbSticks.Right.Y; Sprite.velocity *= Sprite.thrust;//multi velocity from the thumb stick Sprite.position += Sprite.velocity; //add current velocity to pos of thr // check if ball hits any of the four sides and bounce it off them if ((Sprite.position.X + Sprite.rect.Width / 2) &gt;= DisplayWidth) //RHS Sprite.position.X = DisplayWidth - (Sprite.rect.Width / 2); if ((Sprite.position.X - Sprite.rect.Width / 2) &lt;= 0)//LHS Sprite.position.X = (Sprite.rect.Width / 2); if ((Sprite.position.Y + Sprite.rect.Height / 2) &gt;= DisplayHeight) //bottom Sprite.position.Y = DisplayHeight - (Sprite.rect.Height / 2); if ((Sprite.position.Y - Sprite.rect.Height / 2) &lt;= 0) //Top Sprite.position.Y = (Sprite.rect.Height / 2); // set position of Sprite into the rectangle from the position property Sprite.rect.X = (int)Sprite.position.X; Sprite.rect.Y = (int)Sprite.position.Y; //set bounding sphere Sprite.bsphere = new BoundingSphere(Sprite.position, Sprite.rect.Width / 2); //sprite2 Sprite2.thrust = speed * (pad_P1.Triggers.Left + 2);// calculate the amount of thrust based on speen and right trigger Sprite2.velocity.X = pad_P1.ThumbSticks.Left.X; Sprite2.velocity.Y = -pad_P1.ThumbSticks.Left.Y; Sprite2.velocity *= Sprite2.thrust;//multi velocity from the thumb stick Sprite2.position += Sprite2.velocity; //add current velocity to pos of thr // check if ball hits any of the four sides and bounce it off them if ((Sprite2.position.X + Sprite2.rect.Width / 2) &gt;= DisplayWidth) //RHS Sprite2.position.X = DisplayWidth - (Sprite2.rect.Width / 2); if ((Sprite2.position.X - Sprite2.rect.Width / 2) &lt;= 0)//LHS Sprite2.position.X = (Sprite2.rect.Width / 2); if ((Sprite2.position.Y + Sprite2.rect.Height / 2) &gt;= DisplayHeight) //bottom Sprite2.position.Y = DisplayHeight - (Sprite2.rect.Height / 2); if ((Sprite2.position.Y - Sprite2.rect.Height / 2) &lt;= 0) //Top Sprite2.position.Y = (Sprite2.rect.Height / 2); // set position of Sprite into the rectangle from the position property Sprite2.rect.X = (int)Sprite2.position.X; Sprite2.rect.Y = (int)Sprite2.position.Y; //set bounding sphere Sprite2.bsphere = new BoundingSphere(Sprite2.position, Sprite2.rect.Width / 2); // user presses X game is over if (pad_P1.Buttons.X == ButtonState.Pressed) GameOver = true; } else { if (pad_P1.Buttons.Start == ButtonState.Pressed || keys.IsKeyDown(Keys.Enter)) reset(); } // TODO: Add your update logic here base.Update(gameTime); } /// &lt;summary&gt; /// This is called when the game should draw itself. /// &lt;/summary&gt; /// &lt;param name=&quot;gameTime&quot;&gt;Provides a snapshot of timing values.&lt;/param&gt; protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); // TODO: Add your drawing code here //Draw ship spriteBatch.Begin(); spriteBatch.Draw(BackGround.image, BackGround.rect, Color.White); //sprite spriteBatch.Draw(Sprite.image, Sprite.rect, null, Color.DarkSeaGreen, Sprite.rotation, Sprite.origin, SpriteEffects.None, 0); //sprite2 spriteBatch.Draw(Sprite2.image, Sprite2.rect, null, Color.DarkSlateBlue, Sprite2.rotation, Sprite2.origin, SpriteEffects.None, 0); spriteBatch.End(); base.Draw(gameTime); } } }</code></pre></div> 
				 	]]>
				</content:encoded>							</item>
				</channel>
</rss>