如何从SKSpriteNode或SKTexture获取像素颜色? [英] How to get pixel color from SKSpriteNode or from SKTexture?

查看:171
本文介绍了如何从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.

这篇关于如何从SKSpriteNode或SKTexture获取像素颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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