Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 制作flash国家地图_Actionscript 3_Map_Bitmap_Flex4_Flashdevelop - Fatal编程技术网

Actionscript 3 制作flash国家地图

Actionscript 3 制作flash国家地图,actionscript-3,map,bitmap,flex4,flashdevelop,Actionscript 3,Map,Bitmap,Flex4,Flashdevelop,您好,我想制作一张欧洲的闪光地图,当您将鼠标移到或移出每个国家时,会发生一些事情,比如改变国家的颜色 看到这张图了吗 如果我翻过挪威,然后翻过瑞典,瑞典将不会被设置为蓝色,因为挪威的边界框在瑞典的顶部,所以我必须稍微降低一点,翻过瑞典,因为它与挪威没有冲突 有没有更好的方法来实现相同的功能?喜欢使用位图像素 我有一张png格式的所有硬币的精灵表。我嵌入了这个精灵表,然后创建了精灵AS3类,它使用copyPixels()将精灵表中的内容复制到innet变量BitmapData中 这是我的班级

您好,我想制作一张欧洲的闪光地图,当您将鼠标移到或移出每个国家时,会发生一些事情,比如改变国家的颜色

看到这张图了吗

如果我翻过挪威,然后翻过瑞典,瑞典将不会被设置为蓝色,因为挪威的边界框在瑞典的顶部,所以我必须稍微降低一点,翻过瑞典,因为它与挪威没有冲突

有没有更好的方法来实现相同的功能?喜欢使用位图像素

我有一张png格式的所有硬币的精灵表。我嵌入了这个精灵表,然后创建了精灵AS3类,它使用copyPixels()将精灵表中的内容复制到innet变量BitmapData中

这是我的班级

  public class Country extends Sprite 
  {
    private var newBitmap:Bitmap;
    private var tintColor:Color = new Color();

    public function Country(bitmapData:BitmapData) 
    {
        newBitmap = new Bitmap(bitmapData);

        tintColor.setTint (0x0000ff, 0.6);

        this.useHandCursor = true;
        this.buttonMode = true;

        addEventListener(Event.ADDED_TO_STAGE, init);
    }
    private function init(e:Event):void
    {
        addChild(newBitmap);
        addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
        addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
    }

    private function onMouseOver(e:MouseEvent = null):void
    {
        newBitmap.transform.colorTransform = tintColor;
    }

    private function onMouseOut(e:MouseEvent = null):void
    {
        newBitmap.transform.colorTransform = new ColorTransform();
    }
   }
bitmapData是在运行时使用copyPixels()创建的,如下所示

 var countiresArray:Array = Resources.allCointriesJSON["frames"];
 var newX:Number = countiresArray[i]["frame"]["x"];
 var newY:Number = countiresArray[i]["frame"]["y"];
 var newW:Number = countiresArray[i]["frame"]["w"];
 var newH:Number = countiresArray[i]["frame"]["h"];
 bitmapData .copyPixels(Resources.allCountries.bitmapData, new Rectangle(newX, newY, newW, newH), new Point(0, 0));

如果newX、NewY、newW和newH是从使用TexturePacker时创建的导出JSON文件中获取的,而不将您的国家/地区图像转换为矢量,则需要检查鼠标下像素的alpha值以获得准确的交互。幸运的是,有人已经编写并开源了一个实用程序,可以完成这项工作:


您只需要将位图放在一个
InteractivePNG
实例中,而不是一个
Sprite

我遇到了一个类似的问题,但是有一个交互对象。解决方案是用一个图像作为点击的地图。这是OpenGL中用于检测3d对象和场景上的点击的技术

例如,在您的案例中,您将拥有所有国家的图像。此图像将不会加载到显示列表中。每个国家都有完全不同的颜色。例如,瑞典将是
0xff0000
,挪威将是
0x00ff00
,等等。我们将此图像称为
彩色地图。jpg

然后单击用户看到的
欧洲地图.jpg
,检查鼠标坐标,然后查看
彩色地图.jpg
,了解单击像素的颜色。然后你就知道用户点击了哪个国家,并且可以覆盖
Norway.png

这种技术在性能方面比在显示列表中有很多PNG要好得多。在任何时候,您都只能将
欧洲地图.jpg
,可能是选定国家的1个PNG,然后将
彩色地图.jpg
加载到
位图
对象中。如果您的目标是移动性能优化,那么它是必须的

检查此功能。这只是一个例子,让你去。。。这不是一个完整的实现

var countriesArray = [{color:0xff0000, image:"Norway.png"},{color:0x00ff00, image:"Sweden.png"}];

public function checkPoint(mouseX,mouseY):String {
    var testPixel:uint = coloredMap.bitmapData.getPixel(mouseX,mouseY);

    for (var country in countriesArray) {
        if( country.color == testPixel ) {
            return country.image;
        }
    }

    return null;
}

你们的国家是由单独的、透明的位图组成的吗?是的,每个国家都是png文件,但我使用TexturePacker将它们打包在一个png文件中。Hanks:)我刚刚将国家从Sprite扩展到InteractivePNG,它工作得非常完美。因此,我不会将我的小游戏移植到手机上,至少现在我对上述答案不满意。不过还是谢谢你。这看起来更简单。但我必须检查如何实现它,我已经在我的小游戏中添加了很多东西:)也许是Android的一个实践:)它很容易实现,而且你可以制作的PNG也会更少。您可以使用描述国家、颜色、PNG图像、覆盖PNG的坐标等的XML使解决方案100%动态。