妙なことが起こった C#
Discussion
解決したいこと
this.ProcessControls();を含めると画面が4分の1サイズで表示されるように成る。
問題のコードを入れなければ、正常に表示される
発生している問題・エラー
有りません
該当するソースコード
public partial class FormPrincipal : Form
{
DispatcherTimer gameLoopTimer { get; set; }
DispatcherTimer enemySpawnTimer { get; set; }
Bitmap screenBuffer { get; set; }
Graphics screenPainter { get; set; }
BackGround backGround { get; set; }
Player player { get; set; }
List<GameObject> gameObjects { get; set; }
public Random random { get; set; }
public FormPrincipal()
{
InitializeComponent();
this.random = new Random();
this.ClientSize = Media.BackGround.Size;
this.screenBuffer = new Bitmap(Media.BackGround.Width, Media.BackGround.Height);
this.screenPainter = Graphics.FromImage(this.screenBuffer);
this.gameObjects = new List<GameObject>();
this.backGround = new BackGround(this.screenBuffer.Size, this.screenPainter);
this.player = new Player(this.screenBuffer.Size, this.screenPainter);
this.gameLoopTimer = new DispatcherTimer(DispatcherPriority.Render);
this.gameLoopTimer.Interval = TimeSpan.FromMilliseconds(16.66666);
this.gameLoopTimer.Tick += GameLoop;
this.enemySpawnTimer = new DispatcherTimer(DispatcherPriority.Render);
this.enemySpawnTimer.Interval = TimeSpan.FromMilliseconds(1000);
this.enemySpawnTimer.Tick += SpawnEnemy;
this.gameObjects.Add(backGround);
this.gameObjects.Add(player);
StartGame();
}
public void StartGame()
{
this.gameLoopTimer.Start();
this.enemySpawnTimer.Start();
}
public void SpawnEnemy(object sender, EventArgs e)
{
Point enemyPosition = new Point(this.random.Next(74, this.screenBuffer.Width - 10) - 62);
Enemy enemy = new Enemy(this.screenBuffer.Size, this.screenPainter, enemyPosition);
this.gameObjects.Add(enemy);
}
public void GameLoop(object sender, EventArgs e)
{
this.gameObjects.RemoveAll(x => !x.Active);
this.ProcessControls();
foreach (GameObject go in this.gameObjects)
{
go.UpDateObject();
if (go.IsOutOfBounds())
{
go.Destroy();
}
}
this.Invalidate();
}
private void FormPrincipal_Paint(object sender, PaintEventArgs e)
{
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
e.Graphics.DrawImage(this.screenBuffer, 0, 0);
}
private void ProcessControls()
{
if (Keyboard.IsKeyDown(Key.Left)) player.MoveLeft();
if (Keyboard.IsKeyDown(Key.Right)) player.MoveRight();
if (Keyboard.IsKeyDown(Key.Up)) player.MoveUp();
if (Keyboard.IsKeyDown(Key.Down)) player.MoveDown();
}
private void FormPrincipal_Load(object sender, EventArgs e)
{
}
}
自分で試したこと
いろいろ試しても覚えてない