Tag Info

Hot answers tagged

8

You need to use SpriteFont.MeasureString. Vector2 textSize = mySpriteFont.MeasureString("Hello World"); Vector2 center = textSize / 2; The x component of textSize represents the width of the measured string while the y component represents the height.


6

The usual way to handle this is that every time a bullet is fired you set some variable to your cooldown time. Every frame you decrement that variable by the frame time. If you try to fire and that value is greater than 0, you just ignore the fire input event. If that feels bad, a next step is to queue up a "they want to fire" action if they try to ...


3

You check for input in your Update method. Update is where you'll respond to input, move entities around, do collision detection, update counters, update and data that needs updating. Draw is where you draw everything... Initialize is where you set initialize whatever data structures you're using. LoadContent is where you load save states, load ...


2

In most games, bullets are removed from the game once they hit something, so they don't have this problem. There are two situations where this problem crops up: When bullets can hit many different objects at different times. Maybe the bullet travels through objects to hit more objects behind it; maybe the bullet bounces around and hits anything in its ...


2

If I understand you correctly, the coordinates you are getting from Mouse.GetState() always fall within the bounds of the screen (ie: 0 < x < 1680 and 0 < y < 1050). This is normal. The transformation matrix you are using is taking coordinates in "world space" and putting them in "client space" (which is the space that SpriteBatch then uses to ...


2

In the overload of SpriteBatch.Draw that you are using, which you call like so: SpriteRect = new Rectangle((int)Position.X, (int)Position.Y, mSpriteTexture.Width, mSpriteTexture.Height); theSpriteBatch.Draw(mSpriteTexture, Position,SpriteRect, Color.White, 0.0f, Vector2.UnitX, 1f, SpriteEffects.None, 0); You are passing SpriteRect into the method ...


2

you change value of the variables - ep1, ep2, ep3, but you dont change objects coords. For moving from right side to left side you can try anything like this (also you can use foreah): for (int i=0; i<3; i++) { if (enemyPosition[i].X > 0) { enemyPosition[i].X--; } } P.S. Sorry for my bad English.


2

Since I am not familiar with shaders at all - I recommend this approach: Create a texture in your favorite editor whether it be GIMP or Photoshop. Leave some sort of radial transparency in the center of the image so the player can actually see what he/she is doing amidst the red bordering the edges of the screen. Add that image to your XNA project, and ...


1

Despite this being just a proof-of-concept, you should still follow correct programming practices. Create a new class that has the texture, position, and TTL (time-to-live). This will make it much easier for you and others to debug and work with. Your object class: public class TapMarker { public TapMarker(Vector2 position) { Position = ...


1

Jesse Emond is correct. As for how to orient your code correctly; My best suggestion to solve your problem is to take a more class-oriented approach, even if just by a little bit. Rather than maintain a list of each enemy's position, maintain a list of enemies, each of which has a position. That way you could add other attributes to enemies too. Most ...


1

In C#, there are two situations that might happen when you copy something, for example Vector2 position = positions[0];: If the object is a struct, it will copy the entire object. float is a structure, int is a structure, double is a structure. Basically, this quote from msdn sums it well: Structs are copied on assignment. When a struct is assigned to a ...


1

You are assuming that each frame will take exactly 3 milliseconds to execute, but if it's less or higher then it will continue to chip away the health. Additionally you are not using a cumulative value for the elapsed time but instead using the one in ElapsedTime instance which will only relay the time elapsed since the last frame. var isInvulnerable = ...


1

It sounds like you already conceived of using planes to define arbitrarily shaped regions. It's not necessarily the most efficient method, but you can use them for collision detection. The planes can represent half-spaces, informally meaning that one half of space is on one side of the plane. An axis-aligned bounding box is a specific case of using six ...


1

Ok so I finally managed to work out what I was doing wrong. The issue was how I was applying the rotation vector to the quaternion. Basically rather than use Quaternion.CreateFromAxisAngle() I now create a rotation change Quaternion using my angular velocity as the X,Y,Z components and 0 for the scalar. So just for clarity here is my new update code for ...



Only top voted, non community-wiki answers of a minimum length are eligible