我怎样才能在斯塔林纹理的像素值? [英] How can I get pixel values of a texture in Starling?

查看:173
本文介绍了我怎样才能在斯塔林纹理的像素值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要测试一些图像加载code,我写在AS3采用传统的显示层次,我将确保像素的颜色是正确的价值观。

To test some image-loading code I wrote in AS3 using the traditional display hierarchy, I would ensure that pixel colors were the right values.

现在我已经开始端口code交给八哥,我注意到纹理■不要有一个简单的方法来获得的像素值。这是不幸的,因为这意味着我不得不折腾了很多很好的测试。

Now I've started to port that code over to Starling, I've noticed that Textures don't have an easy way to get pixel values. This is unfortunate, because it means I'd have to toss a lot of good tests.

有没有我可以做到这一点任何可能的方式?就像,我可以转换一个纹理的BitmapData 不知何故?还是你们有其他建议如何进行测试,以确保我正确地加载的形象呢?

Is there any possible way I could do this? Like, could I convert a Texture to BitmapData somehow? Or do you guys have any other suggestions for how to test to ensure that I've properly loaded an image?

推荐答案

其实,这是有可能的情况下的有限子集(但我需要的!)。下面code是HAXE,但希望任何人的AS3背景的应该可以用最小的困难翻译。

In fact, this is possible in a limited subset of cases (but the ones that I needed!). The following code is Haxe, but hopefully anyone coming from an AS3 background should be able to translate it with minimal difficulty.

public function getPixel(x:Int, y:Int, sprite: Starling.display.Sprite) : UInt {
    var sw: Int = stage.stageWidth;
    var sh: Int = stage.stageHeight;

    var support:RenderSupport = new RenderSupport();
    RenderSupport.clear(flash.Lib.current.stage.color, 1.0);
    support.setOrthographicProjection(0, 0, sw, sh);
    Fathom.starling.stage.render(support, 1.0);
    support.finishQuadBatch();

    var result:BitmapData = new BitmapData(sw, sh, true);
    Starling.context.drawToBitmapData(result);

    return result.getPixel(Std.int(sprite.x) + x, Std.int(sprite.y) + y);
}

这是什么code的作用是渲染正在被显示在3D方面的结果的BitmapData每个对象。然后,我们抓住一个像素从该BitmapData在那里的精灵是位置。

What this code does is render every object that's being displayed in a 3D context to the result BitmapData. Then, we grab a pixel from that BitmapData at the location where the sprite is.

这是不完美的 - 它并没有考虑像旋转,缩放等,此外,如果精灵不具有最高的深度不考虑。然而,对于测试有帮助的,它也可能派上用场,如果你需要的应用程序/游戏的当前状态的屏幕截图。

This isn't perfect - it doesn't consider things like rotations, scales, etc. It also doesn't consider if sprite does not have the highest depth. However it is helpful for testing, and it might also come in handy if you need to take a screenshot of the current state of the app/game.

这篇关于我怎样才能在斯塔林纹理的像素值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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