Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualmistervirtue

Posted 30 May 2013 - 04:06 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.


#2mistervirtue

Posted 30 May 2013 - 03:34 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();
            
        }

 

But this isn't working. 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.


#1mistervirtue

Posted 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.Red);
        }

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();
            
        }

 

But this isn't working. If i could get a nudge or a shove in the right direction, that would be awesome.


PARTNERS