如何从SKSpriteNode或SKTexture获取像素颜色?
问题描述:
我希望在游戏地图上精确选择我的对象。对象是一个精灵,周围有一些透明像素,我想测试这些透明像素的触摸位置。
任何线索?
I want to get precise selection of my object on game map. Object is a sprite with which has some transparent pixels around and I want to test touch location for these transparent pixels. Any clue?
答
在Sprite Kit中,您无权访问纹理数据。
In Sprite Kit you don't have access to texture data.
相反,你必须从图像中创建一个位掩码,例如将图像加载为UIImage或CGImage并扫描所有非透明像素。
Instead you'd have to create a bit mask from the image, for example by loading the image as UIImage or CGImage and scanning for all non-transparent pixels.