Jump to content

  • Log In with Google      Sign In   
  • Create Account


mistervirtue

Member Since 26 Aug 2009
Offline Last Active Mar 16 2014 02:01 PM
-----

Topics I've Started

XNA - Making A Sprite Fire A Projectile

03 June 2013 - 08:34 AM

Hello Fellow GameDev'ers,

 

I am working on my personal project and I have hit a serious road block. I am trying to making the player fire projectiles, but I can't really make it work. I have searched online for tutorials, but I can't seem to find any that make use of SpriteManager like I am doing. I am trying to make it as Object-Oriented as possible but I don't really know what to do.

 

I currently have a base Sprite.cs, a UserControlled.cs, and now a ProjectileSprite.cs, and a game component called SpriteManager.cs. I figure should model my ProjectileSprite.cs similarly to my other sprites and then add it to the SpriteManager.cs. But I also don't know how to make it interact with the UserControlled.cs so it will shoot when you want it to.

 

Does GameDev.net have any resources on this kind of problem? If anyone can give me any hints/points/shoves in the right direction that would be awesome.


Drawing A 2D Texture Border

30 May 2013 - 03:29 PM

Hello Fellow Gamedev'ers,

 

I need assistance drawing a border around my a texture for collision testing purposes. I have a Base Sprite class, a subclass UserSprite, and a game Component called SpriteManager. I am trying to draw a border around all of my textures so i can test collision, but I don't really know how. I have tried some stuff on my own but I can't really get anything to work.

 

My current plan of attack is as follows. I have the base Sprite Class get the collisionRectangle

//This is under the base Sprite Class. I get the collision Rectangle here.
        
public Rectangle collisionRect
        {
            get
            {
                return new Rectangle(
                    (int)position.X + collisionOffset,
                    (int)position.Y + collisionOffset,
                    frameSize.X - (collisionOffset * 2),
                    frameSize.Y - (collisionOffset * 2));
            }
        }

 

I then have the draw method draw the sprite and the border

        public virtual void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(textureImage, position,
                new Rectangle(currentFrame.X * frameSize.X, currentFrame.Y * frameSize.Y,
                    frameSize.X, frameSize.Y),Color.White,0,Vector2.Zero,1f,myEffect,0);

//I am trying have it draw both the sprite itself and the border around it. 

            spriteBatch.Draw(testingRecTexture, collisionRect, Color.Green);
        }

 

and I then Load the files for sprite and the border in my spriteManager

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(Game.GraphicsDevice);

            player = new UserControlledSprite(Game.Content.Load<Texture2D>(@"images/Warlock"),
                Vector2.Zero,new Point(378,413), 10, new Point(0,0),new Point(1,1), new Vector2 (3,3));

            testingRec = Game.Content.Load<Texture2D>(@"images/testRec");
         
            base.LoadContent();
            
        }

 

The code runs, but the border does not a apper. I am just trying have each texture have a green border around it. If i could get a nudge or a shove in the right direction, that would be awesome.


XNA Code Help - Drawing Collision Rectangle

07 May 2013 - 03:07 PM

Hello fellow gamedev'ers,

 

I have question about drawing collision rectangles. For testing purposes i want to draw a thin rectangle around my sprite (like an overlay), but i am not sure how. Would i use a primative, or would i have to put a texutre around the collisionRect itself? 

 

Any help would be appericated.


XNA Code Help - Animation Error

24 April 2013 - 11:27 PM

I have a animation error.

 

I have a spritesheet(400*215px) and it contains two frames. One frame (198*215) with a characters eyes open and one frame with the charaters eyes closed. My problem is whenever I attempt to animate this sheet, my code makes the whole sheet appear. Could I please get some help?

---------------------------------------------------------------

Global Variables

Point frameSize = new Point(198, 215); // The Size of an Indivsual Frame
Point currentFrame = new Point (0,0); // Start in the first in the squence
Point sheetSize = new Point(2,1); // Number of Rows and Columns of the Sprite Sheet

----------------------------------------------------------------

Update()

timeSinceLastFrame += gameTime.ElapsedGameTime.Milliseconds;
            if (timeSinceLastFrame > millisecondsPerFrame)
            {
                //Animate the Knight
                timeSinceLastFrame -= millisecondsPerFrame;
                ++currentFrame.X;
                if (currentFrame.X >= sheetSize.X)
                {
                    currentFrame.X = 0;
                    ++currentFrame.Y;
                    if (currentFrame.Y >= sheetSize.Y)
                    {
                        currentFrame.Y = 0;
                    }
                }

--------------------------------------------------------

Draw()

  spriteBatch.Draw(texture,
                 new Rectangle ((currentFrame.X * frameSize.X), (currentFrame.Y*frameSize.Y),
                    frameSize.X, frameSize.Y),Color.White);

----------------------------------------------------------

 

I am not sure what my problem is. I think it lies in the use of the point structs because it is drawing the whole texture file. But then again it could be in the draw but it seems pretty straight forward. Could I get some help?


A Few Words of Encouragement

17 December 2012 - 02:03 PM

I talked to my CIS professor a few days ago and she gave me a real nugget of wisdom I want to share with all of my fellow beginners here on gamedev. This is a quote from her e-mail she sent me.

"Programming is just like any other skill, if you want to be good at it you have to do it a lot. That being said you have to willing to be really bad it for awhile before you can see the fruits of you labor. Don't feel bad because you haven't made Baulder's Gate in one semester. Build upon small realistic goals. Just do the basics and gain a real understanding of the foundational skills. Work hard and work consistently and you will be great at whatever you want."

So I just want to say to everyone out there to keep trying and stay in good cheer, even when things get hard. Push through your obstacles and you will become the programmer you want to be. Keep working hard, you will be rewarded for it!

PARTNERS