Você está na página 1de 11

Display Heelo Worls in Xna using using using using System; Microsoft.Xna.Framework; Microsoft.Xna.Framework.Graphics; Microsoft.Xna.Framework.

Input;

namespace XnaOrientableHelloPhone { public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; string text = "Hello, Windows Phone 7!"; SpriteFont segoe14; Vector2 textSize; Vector2 textPosition; public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; // Allow portrait mode as well graphics.SupportedOrientations = DisplayOrientation.Portrait | DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight; // Frame rate is 30 fps by default for Windows Phone. TargetElapsedTime = TimeSpan.FromTicks(333333); } protected override void Initialize() { base.Initialize(); } protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); segoe14 = this.Content.Load<SpriteFont>("Segoe14"); textSize = segoe14.MeasureString(text); } protected override void UnloadContent() { } protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit();

Viewport viewport = this.GraphicsDevice.Viewport; textPosition = new Vector2((viewport.Width - textSize.X) / 2, (viewport.Height - textSize.Y) / 2); base.Update(gameTime); }

protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Navy); spriteBatch.Begin(); spriteBatch.DrawString(segoe14, text, textPosition, Color.White); spriteBatch.End(); base.Draw(gameTime); } } } Wap to display clock using xna using System; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; namespace XnaSimpleClock { public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; SpriteFont segoe14; Viewport viewport; Vector2 textPosition; StringBuilder text = new StringBuilder(); DateTime lastDateTime; public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; // Frame rate is 30 fps by default for Windows Phone. TargetElapsedTime = TimeSpan.FromTicks(333333); } protected override void Initialize() {

base.Initialize(); } protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); segoe14 = this.Content.Load<SpriteFont>("Segoe14"); viewport = this.GraphicsDevice.Viewport; } protected override void UnloadContent() { } protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); DateTime dateTime = DateTime.Now; dateTime = dateTime - new TimeSpan(0, 0, 0, 0,dateTime.Millisecond);

if (dateTime != lastDateTime) { text.Remove(0, text.Length); text.Append(dateTime); Vector2 textSize = segoe14.MeasureString(text); textPosition = new Vector2((viewport.Width - textSize.X) / 2, (viewport.Height - textSize.Y) / 2); lastDateTime = dateTime; } else { SuppressDraw(); } base.Update(gameTime); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Navy); spriteBatch.Begin(); spriteBatch.DrawString(segoe14, text, textPosition, Color.White); spriteBatch.End(); base.Draw(gameTime); } } }

Xna touch hello using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input.Touch; namespace XnaTouchHello { public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; Random rand = new Random(); string text = "Hello, Windows Phone 7!"; SpriteFont segoe36; Vector2 textSize; Vector2 textPosition; Color textColor = Color.White; public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; // Frame rate is 30 fps by default for Windows Phone. TargetElapsedTime = TimeSpan.FromTicks(333333); } protected override void Initialize() { base.Initialize(); } protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); segoe36 = this.Content.Load<SpriteFont>("Segoe36"); textSize = segoe36.MeasureString(text); Viewport viewport = this.GraphicsDevice.Viewport; textPosition = new Vector2((viewport.Width - textSize.X) / 2, (viewport.Height - textSize.Y) / 2); } protected override void UnloadContent() { } protected override void Update(GameTime gameTime) { // Allows the game to exit

if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); TouchCollection touchLocations = TouchPanel.GetState(); foreach (TouchLocation touchLocation in touchLocations) { if (touchLocation.State == TouchLocationState.Pressed) { Vector2 touchPosition = touchLocation.Position; if (touchPosition.X touchPosition.X touchPosition.Y touchPosition.Y { textColor = new >= textPosition.X && < textPosition.X + textSize.X && >= textPosition.Y && < textPosition.Y + textSize.Y) Color((byte)rand.Next(256), (byte)rand.Next(256), (byte)rand.Next(256));

} else { textColor = Color.White; } } } base.Update(gameTime); } protected override void Draw(GameTime gameTime) { this.GraphicsDevice.Clear(Color.Navy); spriteBatch.Begin(); spriteBatch.DrawString(segoe36, text, textPosition, textColor); spriteBatch.End(); base.Draw(gameTime); } } } Xna tap hello using using using using using System; Microsoft.Xna.Framework; Microsoft.Xna.Framework.Graphics; Microsoft.Xna.Framework.Input; Microsoft.Xna.Framework.Input.Touch;

namespace XnaTapHello

{ public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; Random rand = new Random(); string text = "Hello, Windows Phone 7!"; SpriteFont segoe36; Vector2 textSize; Vector2 textPosition; Color textColor = Color.White; public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; // Frame rate is 30 fps by default for Windows Phone. TargetElapsedTime = TimeSpan.FromTicks(333333); } protected override void Initialize() { base.Initialize(); } protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); segoe36 = this.Content.Load<SpriteFont>("Segoe36"); textSize = segoe36.MeasureString(text); Viewport viewport = this.GraphicsDevice.Viewport; textPosition = new Vector2((viewport.Width - textSize.X) / 2, (viewport.Height - textSize.Y) / 2); TouchPanel.EnabledGestures = GestureType.Tap; } protected override void UnloadContent() { } protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); while (TouchPanel.IsGestureAvailable) {

GestureSample gestureSample = TouchPanel.ReadGesture(); if (gestureSample.GestureType == GestureType.Tap) { Vector2 touchPosition = gestureSample.Position; if (touchPosition.X touchPosition.X touchPosition.Y touchPosition.Y { textColor = new >= textPosition.X && < textPosition.X + textSize.X && >= textPosition.Y && < textPosition.Y + textSize.Y) Color((byte)rand.Next(256), (byte)rand.Next(256), (byte)rand.Next(256));

} else { textColor = Color.White; } } } base.Update(gameTime); } protected override void Draw(GameTime gameTime) { this.GraphicsDevice.Clear(Color.Navy); spriteBatch.Begin(); spriteBatch.DrawString(segoe36, text, textPosition, textColor); spriteBatch.End(); base.Draw(gameTime); } } }

Você também pode gostar