Per-pixel collision problem in C#

后端 未结 3 1540
猫巷女王i
猫巷女王i 2021-01-16 05:33

I am writing a small 2d game engine in C# for my own purposes, and it works fine except for the sprite collision detection. I\'ve decided to make it a per-pixel detection (e

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-16 06:22

    I doubt this is the actual problem, but LockBits doesn't guarantee that the bits data is aligned to the image's Width.

    I.e., there may be some padding. You need to access the image using data[x + y * stride] and not data[x + y * width]. The Stride is also part of the BitmapData.

提交回复
热议问题