all.
We’re trying to get some intersect collisions working, but the problem experience is that the Rectangle does not overlay correcting on the texture.
The texture is a 20×340 pixel image. In the class (Net) for the texture we have a Rectangle to use as the collision box (SetCollisionBox method). We define the following in the Game class (under LoadContent() method).
g_Net = new Net("Net1");
g_scene.Place(g_Net, new Vector3(8, 100, 1));
g_Net.SetCollisionBox(new Rectangle((int)g_Net.Position.X, (int)g_Net.Position.Y, 20, 340));
The problem we have is that the Rectangle is drawn above the texture (the Net) and adjusting the height does make it line up more, but then only the above is collidable with the ball object with a g_Ball.ballRectIntersect(g_Net.netRect). netRect being a public member Rectangle in the Net class and ballRect being the equivalent for the Ball class.
So my question is how can I get the Rectangle overlay to properly appear over the texture so that collision are corresponds with the entire net texture? Is there better way to place this overlay?
Thank you very much in advance.
Cheers.
- Sam.
I’m assuming your texture is 2D, since you said Texture and you’re using a Rectangle instead of a BoundingBox.
In that case, this is very simple to answer.
To set your collision properties, here’s how you do it. Let’s assume position is our texture position and texture is our loaded texture.
Also, if your game is a 2D game, you shouldn’t use a Vector3 to store position unless you’re forced to. Try to use a Vector2, it’ll save you some memory.
Cheers!