我已经创建了一个游戏,我试图获得敌人的形象,一旦他们被射杀到爆炸的gif之前,但我似乎不能让它工作,你可以看到下面的代码,它是打算改为gif,但当你支付游戏,只是游戏中没有显示的gif显示。
lasers.RemoveAll(laser => laser.isDisposed);
foreach (Laser laser in lasers)
{
laser.MoveLaser(this);
foreach (Invader ship in invaders)
{
if (laser.laser.Bounds.IntersectsWith(ship.ship.Bounds))
{
laser.isDisposed = true;
laser.laser.Dispose();
ship.ship.Image = SpaceInvaders.Properties.Resources.explosionGIF1;
ship.isDisposed = true;
ship.ship.Dispose();
score = score + 2; //adds 2 points to players score if enemy is hit
lblScore.Text = score.ToString(); //updates the score label发布于 2019-05-17 12:54:36
@jimi解释
好的,您将图像设置为对象的属性,然后释放应该显示它的对象。顺便说一句,不要试图设置object.isDisposed = true;它是只读的。在需要的时候只需要一个物体就可以了。Btw2,您需要将Properties.Resources.Some图像分配给可重用的图像对象:现在每次生成一个新的图像。
你在处理这艘船还有那个图像。
一个示例解决方案是创建一个新的GIF对象,该对象在被播放一次之后自我处理。当船被摧毁时,一个新的GIF对象将被创建在与船相同的位置。
https://stackoverflow.com/questions/56186675
复制相似问题