Windows Phone開發(fā)工具初體驗


既然把Windows Phone Emulator起來了,我們就順便參觀下Windows Phone的新界面吧。點左邊的Back鍵,會將應(yīng)用程序的Debugger斷掉,不知道程序是否退出了。點中間的Win Button,會回到主界面。
不過主界面上只有IE一個圖標。Windows Phone模擬器中還沒有包括其他的系統(tǒng)功能,比如電話、電子郵件、搜索等。模擬器也沒有辦法模擬重力感應(yīng)、Location定位服務(wù)。希望到Windows Phone開發(fā)工具正式發(fā)布時,這些系統(tǒng)功能都可以被支持。



IE的用戶體驗非常好,一開始新手發(fā)蒙,沒找到地址欄,后邊就非常順利了。無論是頁面縮放時的平滑動畫,還是輸入時切換到適當大小的設(shè)計,都非常順手。特別是Multi-Tab的設(shè)計,感覺非常舒服。特意試了Google Map,顯示一切正常。智能手機時代,有一個好的瀏覽器,其實就成功了一半。
哦,還有一點,我在Windows Phone Emulator里沒有做任何配置,就可以上網(wǎng)了。
XNA 4.0
在移動開發(fā)界,XNA還不是一個響亮的名字,但是在游戲開發(fā)界,Xbox 360上的XNA則是泰山北斗級的開發(fā)技術(shù)。XNA不僅僅是一個.NET的游戲開發(fā)平臺,還包括了很多支持Xbox Live服務(wù)的功能,比如,Avatars技術(shù)支持在游戲中顯示用戶設(shè)計的形象。希望這項技術(shù)能夠和同名電影一樣,改變移動游戲開發(fā)的歷史。
Windows Phone支持的是XNA 4.0,與Zune HD上的XNA 3.1有啥區(qū)別?支持3D游戲!目前我們看到的這個XNA 4.0預(yù)覽版只支持Windows Phone開發(fā),不支持Windows和Xbox 360的游戲開發(fā)。
Silverlight for Windows Phone是典型的事件驅(qū)動型應(yīng)用程序。而XNA是由時間驅(qū)動的應(yīng)用程序,這也是游戲開發(fā)技術(shù)的典型特點。每隔固定時間,系統(tǒng)會觸發(fā)Update事件,使程序得以更新。
不那么多廢話了,創(chuàng)建個XNA 4.0的新工程吧!

選擇Windows Phone Game就好了。IDE環(huán)境下沒有界面編輯器,需要程序員通過代碼來實現(xiàn)UI。XNA程序的結(jié)構(gòu)非常簡單,程序員只需要實現(xiàn)幾個簡單的方法,就可以實現(xiàn)一個簡單的XNA程序了。這些方法包括Initialize初始化方法、LoadContent加載文件、Update更新內(nèi)容和Draw繪制等方法。下面是示例代碼片段:
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
texture1 = Content.Load
texture2 = Content.Load
soundEffect = Content.Load
spritePosition1.X = 0;
spritePosition1.Y = 0;
spritePosition2.X = graphics.GraphicsDevice.Viewport.Width - texture1.Width;
spritePosition2.Y = graphics.GraphicsDevice.Viewport.Height - texture1.Height;
sprite1Height = texture1.Bounds.Height;
sprite1Width = texture1.Bounds.Width;
sprite2Height = texture2.Bounds.Height;
sprite2Width = texture2.Bounds.Width;
}
LoadContent方法中使用Content.Load方法來加載資源文件,這些文件也是作為資源被加載到XNA程序中的。
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
// Move the sprite around.
UpdateSprite(gameTime, ref spritePosition1, ref spriteSpeed1);
UpdateSprite(gameTime, ref spritePosition2, ref spriteSpeed2);
CheckForCollision();
base.Update(gameTime);
}
Update方法負責更新元素的位置,進行碰撞檢測。如果后退鍵被按下,則退出程序。
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
// TODO: Add your drawing code here
// Draw the sprite.
spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);
spriteBatch.Draw(texture1, spritePosition1, Color.White);
spriteBatch.End();
spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.Opaque);
spriteBatch.Draw(texture2, spritePosition2, Color.AliceBlue);
spriteBatch.End();
base.Draw(gameTime);
}
Draw方法對更新后的元素進行繪制。
我們的第一個XNA程序會顯示兩張圖片,這兩張圖片會在屏幕中運行,運行到邊緣時,會反彈回來。

評論