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

查看:19
本文介绍了如何从 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天全站免登陆