无效位图数据错误 #2015

发布于 2024-08-16 02:43:29 字数 1344 浏览 4 评论 0原文

        private static var tileDir:String;
        public static var tileImage:BitmapData;
        private static var loader:Loader;

        public static var tileReady:EventDispatcher = new EventDispatcher();
        public static var tileNum_perRow:Number = 3;
        public static var select:selector;

        public var tileNum:Number = 0;
        public var setBack:Number = 0;
        public var tileState:String;
        public var tCol:Number;
        public var tRow:Number;

        private var tWidth:int = 30;
        private var tHeight:int = 30;
        private var tImage:BitmapData;
        private var canvas:Bitmap;

        private var p:Point;
        private var r:Rectangle;    

        public function Tile():void
        {
            var tempImage:BitmapData = tileImage;
            r = new Rectangle(0,0,30,30);
            p = new Point(0,0);
            tImage = new BitmapData(30,30);
            tImage.copyPixels(tempImage,r,p);
        }

我收到以下错误:

ArgumentError: Error #2015: Invalid BitmapData.

当我复制像素时往往会发生这种情况。我不知道为什么。

tileImage;

tileImage 是有效的,我在下面的代码中使用了该变量并且它有效。但上面没有。不知道为什么。有人有任何线索吗?

this.graphics.beginBitmapFill(tileImage);
this.graphics.drawRect(60, 0,tWidth ,tHeight );
        private static var tileDir:String;
        public static var tileImage:BitmapData;
        private static var loader:Loader;

        public static var tileReady:EventDispatcher = new EventDispatcher();
        public static var tileNum_perRow:Number = 3;
        public static var select:selector;

        public var tileNum:Number = 0;
        public var setBack:Number = 0;
        public var tileState:String;
        public var tCol:Number;
        public var tRow:Number;

        private var tWidth:int = 30;
        private var tHeight:int = 30;
        private var tImage:BitmapData;
        private var canvas:Bitmap;

        private var p:Point;
        private var r:Rectangle;    

        public function Tile():void
        {
            var tempImage:BitmapData = tileImage;
            r = new Rectangle(0,0,30,30);
            p = new Point(0,0);
            tImage = new BitmapData(30,30);
            tImage.copyPixels(tempImage,r,p);
        }

And I get the following error:

ArgumentError: Error #2015: Invalid BitmapData.

It tends to happen when I copy the pixels. I dont know why.

tileImage;

tileImage is valid, I've used the variable in the code below and it works. But above doesnt. Don't know why. Anyone have any clues?

this.graphics.beginBitmapFill(tileImage);
this.graphics.drawRect(60, 0,tWidth ,tHeight );

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

殤城〤 2024-08-23 02:43:29

没关系,我认为使用 theMatrix.translates 的更好解决方案

                theMatrix.translate(30,0);
        this.graphics.beginBitmapFill(tileImage,theMatrix);
        //this.graphics.drawRect(0, 0,tWidth ,tHeight );
        this.graphics.endFill();

使您能够选择所需的图块部分,而不会影响精灵的位置

Nevermind, I figure a better solution

                theMatrix.translate(30,0);
        this.graphics.beginBitmapFill(tileImage,theMatrix);
        //this.graphics.drawRect(0, 0,tWidth ,tHeight );
        this.graphics.endFill();

using the theMatrix.translates give you the ability to choose what part of the tile you want, without effecting the position of the sprite

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文