PictureBox在微小的游戏问题中闪烁 [英] PictureBox flickering in tiny game problem

查看:108
本文介绍了PictureBox在微小的游戏问题中闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在开发一个小型的2D平台游戏,在代码中,我正在检查玩家是否已经使用表格控件上的foreach循环与我的平台发生碰撞并更新其位置,如下所示。当我运行游戏时,图片框希望上下
并继续快速闪烁。这是为什么?


我尝试将此事件更改为一个名为onPlatform的布尔值为true而不是更新位置而只是使gravityForce女巫是什么是地面0的玩家,但随后它没有碰到
i在表格上的第二个相同但更小的平台。如果需要更多信息,请告诉我。

 

private void checkForCollition_Tick(object sender,EventArgs e)
{
foreach(控制c in this.Controls)
{
if(c是PictureBox&& c.Tag ==" platform")
{
if(player.Bounds。 IntersectsWith(c.Bounds))
{
player.Top = c.Top - player.Width;
}
}
}
}

解决方案

也许它应该是'player.Top = c.Top - player.Height'


So I'm working on a tiny 2d platform game and in the code I'm checking if the player has collided with my platform using a foreach loop ont the forms controlls and updating its position as shown below. When i run the game the picturebox hopes up and down and keeps on flickering fast. Why is this?

I tried making this event change a boolean called onPlatform to true instead of updating the position and just making gravityForce witch is what is the player to the ground 0, but then it didn't collide with the second identical but smaller platform that i have on the form. If more info is needed then just tell me.

private void checkForCollition_Tick(object sender, EventArgs e) { foreach (Control c in this.Controls) { if (c is PictureBox && c.Tag == "platform") { if (player.Bounds.IntersectsWith(c.Bounds)) { player.Top = c.Top - player.Width; } } } }

解决方案

Maybe it should be ‘player.Top = c.Top - player.Height’?


这篇关于PictureBox在微小的游戏问题中闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆