2013-05-09 31 views
1

我有一个随机和复杂的方式绘制的精灵。像素不是透明的就是不透明。现在我需要检查像素new Point(10, -5)是否透明。Actionscript 3 - 如何检查雪碧的随机像素

我该怎么做?


  • 这不是碰撞检测。
  • 我也画在精灵图形的负面区域。它不居中。

解决方案:

的主要问题是在负值区绘图。我自己想出来的:

var bitmapData: BitmapData = new BitmapData(sprite.width, sprite.height, true, 0x0); 
var rect: Rectangle = sprite.getBounds(sprite); 
var mat: Matrix = new Matrix(); 
mat.translate(-rect.left, -rect.top); 
bitmapData.draw(sprite, mat); 
bitmapData.getPixel32(xCoordToTest - rect.left, yCoordToTest - rect.top); 
// etc 

回答

0

创建新的BitmapData对象并将其绘制到它上面。然后检查所需的BitmapData像素。

var bitmapData:BitmapData = new BitmapData(mySprite.width,mySprite.height,true,0x00000000); 
bitmapData.draw(mySprite); 
bitmapData.getPixel32(10,5); 
0

就像SzRaPnEL说,绘制你的精灵与设置为true(启用透明)的第三个参数的BitmapData对象。 然后...

var pixelValue:uint = bitmapData.getPixel32(xCoordToTest, yCoordToTest); 
var alphaValue:uint = pixelValue >> 24 & 0xFF; 

据到BitmapData在线文档,这应该工作... http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html#getPixel32()

+0

你都错过了主要问题。 – n4pgamer 2013-05-09 16:01:05