【发布时间】:2012-04-28 16:39:49
【问题描述】:
我在 XNA 中使用 spritesheet 动画,我想使用像素完美碰撞。我的问题是像素完美碰撞检查精灵表上的当前像素是否透明,而不是检查我正在使用的精灵表部分。这是我的代码:
blockTextureData = new Color[shot.texture.Width * shot.texture.Height];
shot.texture.GetData(blockTextureData);
personTextureData = new Color[player2.texture.Width * player2.texture.Height];
player2.texture.GetData(personTextureData);
if (IntersectPixels(player2.CollissionBox, personTextureData, shot.CollissionBox, blockTextureData))
我想知道如何选择 spritesheet 的特定部分并检查与它的碰撞。我用this MSDN guide。
编辑: 我设法弄明白了,我用这个代替了
src = new Rectangle(frame, 0, 87, 100);
player.texture.GetData<Color>(0, src, personTextureData,0, 87*100);
框架是你启动它,例如0 用于第一个,87 用于第二个,因为我使用带有 2 张图片的精灵表,宽度为 2*87,高度为 100。
编辑2: 现在的问题是,一旦你点击了 pixelperfect 就会停止工作,所以它只适用于 1 次点击。
【问题讨论】:
标签: c# animation xna sprite-sheet pixel-perfect