Jump to content

  • Log In with Google      Sign In   
  • Create Account

genjihl

Member Since 06 May 2012
Offline Last Active Nov 24 2012 08:00 PM

Topics I've Started

Any benefits to drawing textures in one spritebatch.Begin() & End() call?

18 November 2012 - 10:22 PM

Hello. I was wondering if there were any optimization benefits with drawing textures with only calling spritebatch.Begin() and spritebatch.End() once, as opposed to calling .Begin() and .End() for each texture.

I understand there are limitations to using this approach, such as not being able to change the SpriteSortMode and BlendState, but I am not worried about that. I am only curious about whether or not designing a drawing system like this would have a significant affect on a game's performance.

An explanation regarding the "expense" of calling a spritebatch's .Begin() and .End() functions would be appreciated!

Thanks!

Mouse collision: new Rectangle or move Rectangle?

10 May 2012 - 11:19 PM

Hello, please let me know if I'm being way too nit picky or paranoid about my game's performance with my query:

To see if my mouse intersecting a Rectangle (in XNA), I've thought of two ways:

1. Check if the object's Rectangle intersects with a new Rectangle created at the mouse's position.
Or 2. Initialize a rectangle to follow the mouse around, and update its position every time Update() is called, and when the check occurs, simply provide the mouse's Rectangle.

Assuming the check is called very frequently (whenever other classes want to know if the mouse is hitting anything important), which method would be the most efficient? And, is this difference even significant?

If you'd like to see what I mean in code:

//Option #1
class MouseInput
{

MouseState lastState;

MouseState currentState;


public bool Intersects(Rectangle rect)

{

return rect.Intersects ( new Rectangle ( currentState.X, currentState.Y, 1, 1) );

}

public void Update()

{

lastState = currentState;

currentState = Mouse.GetState();

}

}

//Option #2
class MouseInput
{

MouseState lastState;

MouseState currentState;

Rectangle mouseRectangle;


public void Initialize()

{

mouseRectangle = new Rectangle ( currentState.X, currentState.Y, 1, 1);

}


public bool Intersects(Rectangle rect)

{

return rect.Intersects ( mouseRectangle );

}


public void Update()

{

lastState = currentState;

currentState = Mouse.GetState();

mouseRectangle.X = currentState.X;

mouseRectangle.Y = currentState.Y;

}

}


Thanks in advance for the help!

Creating a subclass in place of instantiating...

06 May 2012 - 11:16 PM

I'm working on a game where I will manually construct a large number of Ship objects (100+), each with their own unique stats, but, of course, sharing the same properties and methods.

Someone suggested I should create a sub-class for each different ship to accomplish this, but this goes against my intuition. However, I don't know what would be bad about this approach either. This approach is tempting because I would be able to quickly access a particular subclass object with my IDE's auto-fill feature when I begin typing its name.

Is there a performance cost or disadvantage to creating sub-classes in this manner, where I could just create instances of the same class instead?

PARTNERS