Jump to content
  • Advertisement
Sign in to follow this  
Ninja_Mouse

Texture wrapping

This topic is 3161 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello! I'm using XNA and would like to create a class that can display a wrapped/tiled texture. It isn't the actual wrapping that is an issue for me, it is that I won't be using 1:1 pixel mapping and can foresee it jumping around! public virtual void Draw(GameTime gameTime, SpriteBatch spriteBatch) { if (this.Texture == null) return; // Number of tiles that will be shown. Vector2 tileCount = new Vector2( this.Size.X / this.Texture.Size.X; this.Size.Y / this.Texture.Size.Y); // Wrapping value for source. int wrapStartX = (int)this.TileStart.X; int wrapStartY = (int)this.TileStart.Y; int wrapWidth = (int)(this.Texture.Width * tileCount.X); int wrapHeight = (int)(this.Texture.Height * tileCount.Y); // Final wrapped texture source. Rectangle wrappedSource = new Rectangle( wrapStartX, wrapStartY, wrapStartX + wrapWidth, wrapStartY + wrapHeight); // Draw wrapped tiles. spriteBatch(this.Texture, this.Position, wrappedSource, this.Colour, this.Rotation, this.Origin, this.Scale, null, 0); } What I can see happening here is that, although my destination size will be correct, it won't set the texture's source correctly because it set as an integer rather than a float. This means the source will jump whole numbers and look weird. e.g. I might need to start with a texture source of (10.4,12.8) but can't so, as the position of the drawing moves using a float, the source texture jumps from pixel to pixel. I haven't tried this code yet as I can't get to my home computer right now. I'm pretty sure I'm going to get slight jumping because of the texture source though. Any ideas on how I could get around it will be gratefully accepted! Thanks, Farran

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!