//
這個方法在xbox 中能夠
//
vect = new Vector2(
//
(Window.ClientBounds.Width/2)-(user.Width/2),
//
(Window.ClientBounds.Height/2)-(user.Height/2)
//
);
//
Windows Phone 7 最好使用這個,用這個方法能夠精肯定位精靈到屏幕的中心點
vect
=
new
Vector2(
(graphics.GraphicsDevice.Viewport.Width
/
2
)
-
(user.Width
/
2
),
(graphics.GraphicsDevice.Viewport.Height
/
2
)
-
(user.Height
/
2
));
spriteBatch.Draw(user,
//
要繪製的紋理
vect
//
繪製圖像的左上角座標
,
null
//
容許您繪製原始圖像的一部分,這裏使用null
, Color.White
//
染色顏色
,
0
//
旋轉圖像,如今使用0
, Vector2.Zero
//
指定旋轉的參照點,如今使用Vector2.Zero
,
1.5f
//
綻開比例,使用1表明按照原始尺寸繪製,1.5f 表示放大圖像到150%
, SpriteEffects.FlipVertically,
//
使用SpriteEffects 枚舉來垂直或水平翻轉圖像
0
//
容許您指定圖像的層疊次序(哪張圖像在其它圖像之上),如今使用0
);
一個遊戲會有不少紋理圖像,若是當純以上篇所說的,控制畫的位置那是不現實的。而XNA 可讓您爲每一個圖像指定一個層深度,使圖像老是能有正確的Z次序。要修改層深度,須要使用SpriteBatch.Begin 方法的另外一個重載版本。其中它的重載參數爲以下:圖片
protected
override
void
Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
//
TODO: Add your drawing code here
spriteBatch.Begin(SpriteSortMode.FrontToBack,BlendState.AlphaBlend);
//
給spriteBatch下命令準備開始動做
//
畫背景圖
//
將user 按Vector2指定的位置開始畫圖
//
spriteBatch.Draw(user, vect, Color.White);
spriteBatch.Draw(user,
//
要繪製的紋理
vect
//
繪製圖像的左上角座標
,
null
//
容許您繪製原始圖像的一部分,這裏使用null
, Color.White
//
染色顏色
,
0
//
旋轉圖像,如今使用0
, Vector2.Zero
//
指定旋轉的參照點,如今使用Vector2.Zero
,
1.5f
//
綻開比例,使用1表明按照原始尺寸繪製,1.5f 表示放大圖像到150%
, SpriteEffects.FlipVertically,
//
使用SpriteEffects 枚舉來垂直或水平翻轉圖像
0
//
容許您指定圖像的層疊次序(哪張圖像在其它圖像之上),如今使用0
);
spriteBatch.Draw(background, rect, Color.White);
//
中止時打印出stop
spriteBatch.End();
//
給spriteBatch下命令結束動做
base
.Draw(gameTime);
}