private void GamePage_Loaded(object sender, RoutedEventArgs e) { if (!pageLoaded) { manager = SharedGraphicsDeviceManager.Current; manager.PreferredBackBufferWidth = (int)this.ActualWidth; manager.PreferredBackBufferHeight = (int)this.ActualHeight; manager.SwapChainPanel = this; manager.ApplyChanges(); gameTimer = new GameTimer(); gameTimer.UpdateInterval = TimeSpan.FromTicks(166666); gameTimer.Update += Update; gameTimer.Draw += Draw; this.SizeChanged += GamePage_SizeChanged; // Le contenu est chargé une fois LoadContent(); pageLoaded = true; } // L'initialisation doit se faire à chaque rechargement Initialize(); }
public void Dispose() { if (_timer != null) { _timer.Dispose(); _timer = null; } if (GraphicsDevice != null) { GraphicsDevice.Dispose(); GraphicsDevice = null; } Current = null; }
//static GameTime gameTimer; //static public ParticleEffects(GraphicsDeviceManager graphics, Camera2D cam, GraphicsDevice graphicsDevice) //{ // myRenderer = new SpriteBatchRenderer // { // GraphicsDeviceService = graphics, // Transformation = Matrix.CreateTranslation(0f, 0f, 0f) // //Transformation = cam.get_transformation(graphicsDevice) // }; // World = Matrix.Identity; // Projection = Matrix.Identity; // View = Matrix.Identity; //} //static public ParticleEffects() //{ //} static public void Initialize(SharedGraphicsDeviceManager graphics, GraphicsDevice graphicsDevice) { myRenderer = new SpriteBatchRenderer { GraphicsDeviceService = graphics, //Transformation = Matrix.CreateTranslation(0f, 0f, 0f) }; View = Matrix.Identity; World = Matrix.Identity; Projection = Matrix.Identity; //Projection = Matrix.CreateOrthographicOffCenter(0, 800, 480, 0, 0, 2000); //View = new Matrix(1.0f, 0.0f, 0.0f, 0.0f, // 0.0f, -1.0f, 0.0f, 0.0f, // 0.0f, 0.0f, -1.0f, 0.0f, // 0.0f, 0.0f, 0.0f, 1.0f); }
/* CONSTRUCTOR */ // Draws the UI public Create() { InitializeComponent(); // Get the content manager from the application contentManager = (Application.Current as App).Content; // Create a timer for this page timer = new GameTimer(); timer.UpdateInterval = TimeSpan.FromTicks(333333); timer.Update += OnUpdate; timer.Draw += OnDraw; // Configuration and management of shared graphics device graphics = SharedGraphicsDeviceManager.Current; graphics.PreferredBackBufferWidth = 480; graphics.PreferredBackBufferHeight = 800; }
public void Dispose() { if (_timer != null) { _timer.Dispose(); _timer = null; } if ( GraphicsDevice != null ) { GraphicsDevice.Dispose(); GraphicsDevice = null; } Current = null; }
public void Update(GameTime gameTime, SharedGraphicsDeviceManager graphics, Vector2 souris) { if (_retournement < -10 || _retournement > 10) { Retournement(); } else { List<Rectangle> tmpRectangle; List<Rectangle> tmp2Rectangle; if ((_position.X > souris.X + 2 || _position.X < souris.X - 2) || (_position.Y > souris.Y + 4 || _position.Y <= souris.Y - 4)) { if (fixe) fixe = false; if (_retournement == 0) { if (_effect == SpriteEffects.FlipHorizontally) { if (souris.X > _destinationRectangle.First().X - _texture.Width / (_maxIndex + 1) + _destinationRectangle.First().Width - 1 && souris.X < (_destinationRectangle.First().X + _destinationRectangle.First().Width + 1)) { if (flip) souris.X += _texture.Width / (_maxIndex + 1) + 1; else souris.X -= (_texture.Width / (_maxIndex + 1) + 1); } else if (souris.X < _position.X) { _retournement = 200; Retournement(); //_effect = SpriteEffects.None; } } else { if (souris.X > _destinationRectangle.First().X - 1 && souris.X < (_destinationRectangle.First().X + _texture.Width / (_maxIndex + 1) + 1)) { if (flip) souris.X += _texture.Width / (_maxIndex + 1) + 1; else souris.X -= (_texture.Width / (_maxIndex + 1) + 1); } else if (souris.X > _position.X) { _retournement = -200; Retournement(); //_effect = SpriteEffects.None; } } } else { Retournement(); if (_effect == SpriteEffects.FlipHorizontally && flip == false) { flip = true; tmpRectangle = new List<Rectangle>(); foreach (var destination in _destinationRectangle) { tmpRectangle.Add(new Rectangle(_texture.Width / (_maxIndex + 1) - destination.Width - destination.X + (int)_position.X + (int)_position.X, destination.Y, destination.Width, destination.Height)); } _destinationRectangle = tmpRectangle; int cpt = 0; tmp2Rectangle = new List<Rectangle>(); foreach (var destination in _destinationRectangleDisguise) { tmp2Rectangle.Add(new Rectangle((int)_position.X + _texture.Width / (_maxIndex + 1) - (int)_positionDisguise.ElementAt(cpt).Width - (int)_positionDisguise.ElementAt(cpt).X, destination.Y, destination.Width, destination.Height)); cpt++; } _destinationRectangleDisguise = tmp2Rectangle; } else { if (_effect == SpriteEffects.None && flip == true) { flip = false; tmpRectangle = new List<Rectangle>(); int cpt = 0; foreach (var destination in _destinationRectangle) { tmpRectangle.Add(new Rectangle(destination.X - _texture.Width / (_maxIndex + 1) + 2 * (int)_positionRectangle.ElementAt(cpt).X + destination.Width, destination.Y, destination.Width, destination.Height)); cpt++; } _destinationRectangle = tmpRectangle; tmp2Rectangle = new List<Rectangle>(); cpt = 0; foreach (Rectangle destination in _destinationRectangleDisguise) { tmp2Rectangle.Add(new Rectangle((int)_position.X + (int)_positionDisguise.ElementAt(cpt).X - _texture.Width / (_maxIndex + 1) + 2, destination.Y, destination.Width, destination.Height)); cpt++; } _destinationRectangleDisguise = tmp2Rectangle; } } } if (_retournement == 0) { _direction.X = souris.X - _position.X; _direction.Y = souris.Y - _position.Y; if (_direction.X == _direction.Y) { if (_direction.X < 0) { _direction.X = -1; _direction.Y = -1; } else { _direction.X = 1; _direction.Y = 1; } } else { if (_direction.X * _direction.X > _direction.Y * _direction.Y) { if (_direction.X < 0) { _direction.Y = _direction.Y / _direction.X * -1; _direction.X = -1; } else { _direction.Y = _direction.Y / _direction.X; _direction.X = 1; } } else { if (_direction.Y < 0) { _direction.X = _direction.X / _direction.Y * -1; _direction.Y = -1; } else { _direction.X = _direction.X / _direction.Y; _direction.Y = 1; } } } tmpRectangle = new List<Rectangle>(); foreach (var position in _destinationRectangle) { tmpRectangle.Add(new Rectangle((int)position.X + 3 * (int)_direction.X, position.Y + (int)(3 * _direction.Y), position.Width, position.Height)); } _destinationRectangle = tmpRectangle; tmp2Rectangle = new List<Rectangle>(); foreach (var position in _destinationRectangleDisguise) { tmp2Rectangle.Add(new Rectangle((int)position.X + 3 * (int)_direction.X, position.Y + (int)(3 * _direction.Y), position.Width, position.Height)); } _destinationRectangleDisguise = tmp2Rectangle; _elapsedGameTime += gameTime.ElapsedGameTime; if (_elapsedGameTime.TotalMilliseconds >= 50) { _elapsedGameTime = TimeSpan.Zero; _currentIndex++; if (_currentIndex > _maxIndex) _currentIndex = 0; tmpRectangle = new List<Rectangle>(); int cpt = 0; foreach (var source in _sourceRectangle) { tmpRectangle.Add(new Rectangle(_currentIndex * _texture.Width / (_maxIndex + 1) + (int)_positionRectangle.ElementAt(cpt).X, source.Y, source.Width, source.Height)); cpt++; } _sourceRectangle = tmpRectangle; } } } else { if (!fixe) { _currentIndex = 0; int cpt = 0; tmpRectangle = new List<Rectangle>(); foreach (var source in _sourceRectangle) { tmpRectangle.Add(new Rectangle(_currentIndex * _texture.Width / (_maxIndex + 1) + (int)_positionRectangle.ElementAt(cpt).X, source.Y, source.Width, source.Height)); cpt++; } _sourceRectangle = tmpRectangle; fixe = true; } } if (flip) _position.X = _destinationRectangle.First().X + _destinationRectangle.First().Width; else _position.X = _destinationRectangle.First().X; _position.Y = _destinationRectangle.First().Y; } }
public void Update(GameTime gameTime, SharedGraphicsDeviceManager graphics) { if (_retournement < -10 || _retournement > 10) { Retournement(); } else { List<Rectangle> tmpRectangle; List<Rectangle> tmp2Rectangle; if (_retournement != 0) Retournement(); else { if (_destinationRectangle.First().X <= 0 || _destinationRectangle.First().X + _destinationRectangle.First().Width >= graphics.PreferredBackBufferHeight) { _direction.X *= -1; if (_effect == SpriteEffects.FlipHorizontally) { _retournement = 200; Retournement(); //_effect = SpriteEffects.None; } else { if (_effect == SpriteEffects.None) { _retournement = -200; Retournement(); //_effect = SpriteEffects.FlipHorizontally; } } } } if (_effect == SpriteEffects.FlipHorizontally && flip == false) { flip = true; tmpRectangle = new List<Rectangle>(); foreach (var destination in _destinationRectangle) { tmpRectangle.Add(new Rectangle(_texture.Width / (_maxIndex + 1) - destination.Width - destination.X + (int)_position.X + (int)_position.X , destination.Y, destination.Width, destination.Height)); } _destinationRectangle = tmpRectangle; int cpt = 0; tmp2Rectangle = new List<Rectangle>(); foreach (var destination in _destinationRectangleDisguise) { tmp2Rectangle.Add(new Rectangle((int)_position.X + _texture.Width / (_maxIndex + 1) - (int)_positionDisguise.ElementAt(cpt).Width - (int)_positionDisguise.ElementAt(cpt).X, destination.Y, destination.Width, destination.Height)); cpt++; } _destinationRectangleDisguise = tmp2Rectangle; } else { if (_effect == SpriteEffects.None && flip == true) { flip = false; tmpRectangle = new List<Rectangle>(); int cpt = 0; foreach (var destination in _destinationRectangle) { tmpRectangle.Add(new Rectangle(destination.X - _texture.Width / (_maxIndex + 1) + 2 * (int)_positionRectangle.ElementAt(cpt).X + destination.Width, destination.Y, destination.Width, destination.Height)); cpt++; } _destinationRectangle = tmpRectangle; tmp2Rectangle = new List<Rectangle>(); cpt = 0; foreach (Rectangle destination in _destinationRectangleDisguise) { tmp2Rectangle.Add(new Rectangle((int)_position.X + (int)_positionDisguise.ElementAt(cpt).X - _texture.Width / (_maxIndex + 1) + 2, destination.Y, destination.Width, destination.Height)); cpt++; } _destinationRectangleDisguise = tmp2Rectangle; } } tmpRectangle = new List<Rectangle>(); foreach (var position in _destinationRectangle) { tmpRectangle.Add(new Rectangle((int)position.X + 3 * (int)_direction.X, position.Y, position.Width, position.Height)); } _destinationRectangle = tmpRectangle; tmp2Rectangle = new List<Rectangle>(); foreach (var position in _destinationRectangleDisguise) { tmp2Rectangle.Add(new Rectangle((int)position.X + 3 * (int)_direction.X, position.Y, position.Width, position.Height)); } _destinationRectangleDisguise = tmp2Rectangle; _elapsedGameTime += gameTime.ElapsedGameTime; if (_elapsedGameTime.TotalMilliseconds >= 50) { _elapsedGameTime = TimeSpan.Zero; _currentIndex++; if (_currentIndex > _maxIndex) _currentIndex = 0; tmpRectangle = new List<Rectangle>(); int cpt = 0; foreach (var source in _sourceRectangle) { tmpRectangle.Add(new Rectangle(_currentIndex * _texture.Width / (_maxIndex + 1) + (int)_positionRectangle.ElementAt(cpt).X, source.Y, source.Width, source.Height)); cpt++; } _sourceRectangle = tmpRectangle; } if (flip) _position.X = _destinationRectangle.First().X + _destinationRectangle.First().Width; else _position.X = _destinationRectangle.First().X; _position.Y = _destinationRectangle.First().Y; } }
private void InitializeXnaApplication() { this.deviceManager = new SharedGraphicsDeviceManager(); }
/// <summary> /// ����XNAͼ����Դ������ /// </summary> private void XNA_Graphics_Loading() { this.graphics = SharedGraphicsDeviceManager.Current; this.timer = new SystemTimer(); }