01.06.2012, 21:37
|
#15
|
Бывалый
Регистрация: 22.12.2011
Сообщений: 844
Написано 150 полезных сообщений (для 275 пользователей)
|
Ответ: Вопросы по XNA.
Чем больше картинок, тем хуже.
Кидаю код.
Max:
Global R1=DesktopWidth()
Global R2=DesktopHeight()
Graphics R1,R2,32
Global lfps,tfps,fps
Global pic=LoadImage("01.jpg")
Global pic_x,pic_y
Function Update_pic()
If KeyDown(KEY_W) pic_y=pic_y-1
If KeyDown(KEY_S) pic_y=pic_y+1
If KeyDown(KEY_D) pic_x=pic_x+1
If KeyDown(KEY_A) pic_x=pic_x-1
DrawText pic_x+" "+pic_y,0,24
For i=0 To 10
For i1=0 To 10
DrawImage pic,pic_x+256*i,pic_y+256*i1
Next
Next
End Function
Function Update_fps()
lfps=lfps+1
If MilliSecs()-tfps>1000
tfps=MilliSecs()
fps=lfps
lfps=0
EndIf
DrawText fps,0,0
End Function
While Not KeyHit(KEY_ESCAPE)
Cls
Update_pic()
Update_fps()
Flip(0)
Wend
XNA:
using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media;
namespace WindowsGame1 { /// <summary> /// This is the main type for your game /// </summary> public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch;
public Game1() { graphics = new GraphicsDeviceManager(this);
graphics.IsFullScreen = true; IsFixedTimeStep = false; graphics.SynchronizeWithVerticalRetrace = false; graphics.PreferredBackBufferHeight = 1280; graphics.PreferredBackBufferWidth = 1024; Content.RootDirectory = "Content"; }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> /// Texture2D backgroundTexture; SpriteBatch sprites; Vector2 player_position = new Vector2(100, 100); SpriteFont Font1;
double elapsedTime; int fps; int l_fps;
protected override void Initialize() {
sprites = new SpriteBatch(graphics.GraphicsDevice);
// TODO: Add your initialization logic here
base.Initialize(); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here Font1 = Content.Load<SpriteFont>("arial"); backgroundTexture = Content.Load<Texture2D>("Gert"); }
/// <summary> /// UnloadContent will be called once per game and is the place to unload /// all content. /// </summary> protected override void UnloadContent() { // TODO: Unload any non ContentManager content here }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit();
if (Keyboard.GetState().IsKeyDown(Keys.Escape)) this.Exit();
if (Keyboard.GetState().IsKeyDown(Keys.W)) player_position.Y -= 1;
if (Keyboard.GetState().IsKeyDown(Keys.S)) player_position.Y += 1; if (Keyboard.GetState().IsKeyDown(Keys.A)) player_position.X -= 1;
if (Keyboard.GetState().IsKeyDown(Keys.D)) player_position.X += 1; elapsedTime+=gameTime.ElapsedGameTime.TotalMilliseconds; l_fps++;
if (elapsedTime >= 1000) { fps = l_fps; l_fps = 0; elapsedTime = 0; }
// TODO: Add your update logic here
base.Update(gameTime); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Black); sprites.Begin(); for (int i=0; i<11 ; i++) { for (int i1 = 0; i1 < 11; i1++) { sprites.Draw(backgroundTexture, new Vector2(player_position.X + i * 256, player_position.Y + i1 * 256), Color.White); } } sprites.DrawString(Font1, Convert.ToString(player_position.X) + " " + Convert.ToString(player_position.Y), Vector2.Zero, Color.White); sprites.DrawString(Font1, Convert.ToString(fps), new Vector2(0, 24), Color.White); sprites.End(); // TODO: Add your drawing code here
base.Draw(gameTime); } } }
Результаты этого теста:
Max - 2160
XNA - 1816
Не знаю почему, но меня это вообще в шок повергло. А с чем именно это связано? XNA использует DirectX, Max вроде бы тоже.
|
(Offline)
|
|