Spritebatch 绘图位置错误
Spritebatch drawing in wrong position
当我的 wizardPos 变量清楚地把它放在屏幕中间时,为什么我的 sprite 绘制到左上角?
//in load content
wizardPos = new Vector2(graphics.PreferredBackBufferWidth /2, 700);
wizardChar = new Characters.Wizard(this, spriteBatch, wizardPos, wizardWalk1);
//in Draw method
this.spriteBatch.Draw(tempWizard, wizardPos, null, Color.White, 0f, wizardPos, 1f, SpriteEffects.None, 0f);
试试这个:
this.spriteBatch.Draw(tempWizard, wizardPos, null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
你精灵的position
其实就是你精灵origin
的位置。因此,当您将 origin
设置为 wizardPos
时,origin
是相对于精灵设置的,而不是屏幕。因此,将 origin
和 position
设置为相同的值可以有效地相互抵消。
origin
通常会在您的 sprite 边界内的某个地方,因为它也用于计算诸如旋转之类的东西
当我的 wizardPos 变量清楚地把它放在屏幕中间时,为什么我的 sprite 绘制到左上角?
//in load content
wizardPos = new Vector2(graphics.PreferredBackBufferWidth /2, 700);
wizardChar = new Characters.Wizard(this, spriteBatch, wizardPos, wizardWalk1);
//in Draw method
this.spriteBatch.Draw(tempWizard, wizardPos, null, Color.White, 0f, wizardPos, 1f, SpriteEffects.None, 0f);
试试这个:
this.spriteBatch.Draw(tempWizard, wizardPos, null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
你精灵的position
其实就是你精灵origin
的位置。因此,当您将 origin
设置为 wizardPos
时,origin
是相对于精灵设置的,而不是屏幕。因此,将 origin
和 position
设置为相同的值可以有效地相互抵消。
origin
通常会在您的 sprite 边界内的某个地方,因为它也用于计算诸如旋转之类的东西