This project has moved and is read-only. For the latest updates, please go here.

Odd texturing

Topics: User Forum
May 20, 2011 at 2:32 PM

Hi everyone, im fairly new to Farseer Physics and i'm having trouble with textures. Whenever i try to place the texture over the player body, it seems to be offset randomly for no reason.

The player will always be in the middle of the screen (at the moment), but even when i try to hard code a screen position for the texture it gets offset. These 2 pics will show what i mean. I havent changed any code with the second picture, i've just moved right along the level.

This is the draw function for the player.


public void Draw(SpriteBatch batch)
      Vector2 texOrig = new Vector2(38, 68);

                0f, texOrig,  // origin of the texture
                0.495f, SpriteEffects.None,   // width of box is 1.2 meters. texture is 55 pixels wide. to make it 1.2 meters wide in world space: 1.2/55 = 0.1875f

And in case you're wondering where the debug numbers are coming from:
Vector2 temp1 = GameInstance.ConvertScreenToWorld(alien.texPos);
Vector2 temp2 = GameInstance.ConvertWorldToScreen(alien.texPos);

DebugView.DrawString(50, TextLine,"Texture Screen Pos: (" + alien.texPos.X + "," + alien.texPos.Y + ")");
DebugView.DrawString(50, TextLine,"Texture World Pos: (" + temp1.X + "," + temp1.Y + ")");
DebugView.DrawString(50, TextLine,"Texture screen Pos: (" + temp2.X + "," + temp2.Y + ")");
DebugView.DrawString(50, TextLine, "Alien vector: (" + alien.alien.Position.X + "," + (alien.alien.Position.Y - 1.5f) +")");

I have absolutely no idea why the texture is being off set so much, and would greatly appreciate any help on the matter.



May 20, 2011 at 6:44 PM

hmm shouldn't it be


and the other thing i see is that the texture is very big for 0.495 scale. i don't think the origin is right for this size (origin depens on the unscaled image size) try something like

Vector2 texOrig = new Vector2(alienTex.Width/2f, alienTex.Height/2f);

May 23, 2011 at 12:49 PM

I tried multiplying the texPos with the ViewZoom and got the exact same results, which suggests the texture is getting a new position vector from elsewhere, but i have no idea how or where.

The strange origin is because the texture has too much white background, 38,68 is centred on the players art, as the original texture is 100x100.