【问题标题】:tweenlite not working with bitmaps?tweenlite 不能使用位图?
【发布时间】:2011-07-18 17:05:26
【问题描述】:

当我尝试使用带有位图的 TweenLite 时遇到以下问题:

将 TweenLite 应用于位图 (tempScore.bitmap) 时,我收到奇怪的错误消息。 GetBounds 有效。位图具有透明度。有谁知道为什么它不起作用?任何帮助表示赞赏。谢谢。:)

当使用 getBounds-Method 时,我得到这个:

tempScore.bitmap.getBounds(this)(x=2.35, y=-0.45, w=25, h=18)

这是错误信息:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.greensock.plugins::TransformAroundPointPlugin/onInitTween()
at com.greensock.plugins::TransformAroundCenterPlugin/onInitTween()
at com.greensock::TweenLite/init()
at com.greensock::TweenLite/renderTime()
at com.greensock.core::SimpleTimeline/renderTime()
at com.greensock::TweenLite$/updateAll()

我导入和激活的库如下所示:

import com.greensock.*;
import com.greensock.TweenLite;
import com.greensock.plugins.TweenPlugin;
import com.greensock.plugins.TransformAroundCenterPlugin;
import com.greensock.plugins.TransformAroundPointPlugin;
import com.greensock.easing.*;
import com.greensock.plugins.AutoAlphaPlugin;
import com.greensock.plugins.ColorTransformPlugin;
import com.greensock.plugins.ColorMatrixFilterPlugin;

TweenPlugin.activate([TransformAroundCenterPlugin, TransformAroundPointPlugin, ColorTransformPlugin,
ColorMatrixFilterPlugin]);

这是我尝试在我的 tempScore 上使用 TweenLite 的部分:

var scoreTextLength:int = scoreManager.scores.length - 1;
        for (var counter:int = scoreTextLength; counter >= 0; counter--)
        {

                tempScore = scoreManager.scores[counter];
                tempScore.startDelay = true;

                TweenLite.to(tempScore.bitmap, 2, {transformAroundCenter: {scale:2}});
                trace("tempScore.bitmap.getBounds(this)" + tempScore.bitmap.getBounds(this));

                if (tempScore.update())
                {

                    disposeScore(counter);

                }
        }

据我所知,getBounds-values 没问题。我的游戏基于游戏框架。它里面有一个渲染器。 如果我错了,请称我为白痴,但是框架的渲染器和 tweenlite 是否有可能相互妨碍??

TweenLite 与 tempAsteroid 等其他类似对象存在问题。使用 copyPixels(blitting-method)将许多对象绘制到画布上。

tempScore 是一个分数对象。 Score 对象基于 BasicBlitArrayObject。否则,此对象将扩展 EventDispatcher。我希望这些小信息对您有所帮助。

这是管理 tempScore 外观和属性的 scoreManager:

package com.cosmicward.src.classes 
{
import flash.display.*;
import flash.text.*;
import flash.geom.*;

import com.framework_mod.src.BlitArrayAsset;


public class ScoreManager 
{
    public var scoreBitmapData:BitmapData;
    public var scoreBitmap:Bitmap;

    public var scoreAnimationFrames:Array = [];

    public var scores:Array;
    public var tempScore:Score;     
    private var textfield:TextField = new TextField();
    private var textFormat:TextFormat = new TextFormat();
    private var $textWidth:int;
    private var $textHeight:int;


    private var rec:Rectangle;

    public var scoreCount:int;
    public var scoreCountTwo:int;
    public var scoreCountThree:int;

    private var drawingCanvas:Shape = new Shape();  

    private var point0:Point = new Point(0, 0);


    public function ScoreManager() 
    {

    }


    public function createScoreLook(textWidth:int, textHeight:int, text:String, textFormat:TextFormat):void {


        var tempBlitArrayAsset:BlitArrayAsset = new BlitArrayAsset();


        scoreBitmapData = new BitmapData(textWidth, textHeight, true, 0x00000000);

        var font:ArialBold = new ArialBold();
        textFormat.font = "ArialBold";
        textFormat.font = font.fontName;
        Font.registerFont(ArialBold);

        textfield.embedFonts = true;
        textfield.blendMode = BlendMode.LAYER;
        //textfield.autoSize = TextFieldAutoSize.LEFT;
        textfield.defaultTextFormat = textFormat;
        textfield.setTextFormat(textFormat);
        textfield.selectable = false;
        textfield.text = text;


        trace("drawingCanvas.height =" + drawingCanvas.height);
        trace("drawingCanvas.width =" + drawingCanvas.width);

        scoreBitmapData.draw(textfield);/



        $textWidth = textWidth;
        $textHeight = textHeight;

        //*** end look

    }



    public function createScores(xPos:Number, yPos:Number, stopAnimation:int = 5,
                                 scoreDelay:int = 10, scoreLife:int = 40):void {

            var tempScore:Score = new Score(5, 1315, 5, 995);

            tempScore.bitmapData = scoreBitmapData;

            scoreBitmap = new Bitmap(tempScore.bitmapData);

            tempScore.bitmap = scoreBitmap;


            tempScore.x = xPos;
            tempScore.y = yPos;

            tempScore.life = scoreLife;
            tempScore.lifeCount = 0;

            tempScore.widthObject = $textWidth;
            tempScore.heightObject = $textHeight;

            tempScore._delay = scoreDelay;
            tempScore.delayCount = 0;

            tempScore.nextX = tempScore.x;
            tempScore.nextY = tempScore.y;

            scores.push(tempScore);
            }
    }
}

这是 BasicBlitArrayObject 的一些代码(tempScore 依赖于此(即 Score-object):

package com.framework_mod.src
{
import flash.display.BitmapData;
import flash.geom.Point;
import flash.events.EventDispatcher;
import flash.geom.Rectangle;
import flash.display.Bitmap;

    public class BasicBlitArrayObject extends EventDispatcher{

    public var x:Number = 0;
    public var y:Number = 0;
    public var nextX:Number = 0;
    public var nextY:Number = 0;
    public var dx:Number = 0; 
    public var dy:Number = 0;
    public var frame:int = 0;
    public var bitmapData:BitmapData;
    public var bitmap:Bitmap;
    public var animationList:Array = [];
    public var testList:Array = [];

    public var point:Point = new Point(0, 0);
    public var speed:Number = 0;

    public var xMax:int = 0;
    public var yMax:int = 0;
    public var xMin:int = 0;
    public var yMin:int = 0;

    public var aniType:int = 1;

    public var health:int = 0;
    public var _size:int = 0;
    public var score:int = 0;
    public var _damage:int = 0;
    public var count:int = 0;
    public var bitmapSize:int = 0;
    public var life:int = 0;
    public var lifeCount:int = 0;
    public var startCount:Boolean;
    public var _delay:int = 0;
    public var delayCount:int = 0;
    public var startDelay:Boolean;
    public var _stop:int;
    public var stopAni:Boolean;
    public var stopAniCount:int = 0;
    public var _type:int = 0;
    public var shield:int = 0;
    public var healthPoints:int = 0;
    public var widthObject:int;
    public var heightObject:int;
    public var boost:Number;
    public var boostLfe:int;
    public var weaponLfe:int;
    public var _projXAdjust:Number;
    public var _projYAdjust:Number;
    public var number:int;
    public var _offset:int;
    public var marked:Boolean;
    public var objMove:Boolean;

    public var removeObj:Boolean;
    public var finished:Boolean;



    public function BasicBlitArrayObject(xMin:int, xMax:int, yMin:int, yMax:int) 
    {
        this.xMin = xMin;
        this.xMax = xMax;
        this.yMin = yMin;
        this.yMax = yMax;
        //trace("basicblittarrayobject");
    }



    public function updateFrame(inc:int, aniType:int = 1):void
    {
        frame += inc;
        switch (aniType) {
        case 1: 
                if (frame > animationList.length - 1){
                    frame = 0;
                }
                bitmapData = animationList[frame];                  
                break;


        case 2: 
                if (frame > animationList.length - 1){
                    frame = 0;
                }
                bitmapData = animationList[1][frame];


                break;
        }


    }   



    public function render(canvasBitmapData:BitmapData):void {
        x = nextX;
        y = nextY;
        point.x = x;
        point.y = y;            

        canvasBitmapData.copyPixels(bitmapData, bitmapData.rect, point);
    }


    public function dispose():void {
        bitmapData.dispose();
        bitmapData = null;
        bitmap = null;
        animationList = null;
        point = null;
    }

}

}

【问题讨论】:

  • 可能是一个愚蠢的问题,但scoreManager.scores 数组中的每个元素都肯定在显示树上吗?您是否尝试过在调试器中检查它以查看 null 值是什么?
  • disposeScore() 是做什么的?也许您正在删除仍在补间的内容?!
  • disposeScore 删除旧分数(垃圾收集)。我将使用分数数组(显示列表)进行检查,但基本上它只是针对已创建并为渲染过程做好准备的分数。
  • 我尽我所能在 wonder.fl 中重新创建了一些东西来测试场景,但现在感觉有点太复杂了,无法回答。如果游戏引擎开放供其他人使用,请告诉我们。列出的一些补间插件是付费插件,因此重新创建变得更加困难。
  • 我使用的游戏引擎是:8bitrocket.com/books/the-essential-guide-to-flash-games。您可以在那里下载框架和游戏示例(包含在一个文件中)。尝试在第 11 章(游戏称为 BlasterMines(第 11 章))中将 TweenLite(任何函数,例如 transformplugin、colormatrix 等)与 blitted 对象(称为 Mines)一起使用。如果有人能帮我解决这个讨厌的问题,那就太好了。

标签: actionscript-3


【解决方案1】:

我认为问题很简单,但解决方案并不简单。您尝试转换的对象是 blitted。所以他们没有被添加到舞台上。所以对象的舞台属性为空。 我怀疑 TransformAroundPoint 插件正在尝试使用对象的 stage 属性,这会引发您看到的空对象错误。 要查看一个简单的示例,请创建一个非常简单的文件。 创建两个位图,将一个添加到舞台,不添加另一个。 将补间应用于舞台实例,它将起作用。 然后将补间应用到后台实例,您应该会得到与游戏中相同的错误。

您需要做的是自己处理转换。与其使用 TweenLite 围绕一个点旋转,不如自己动手。 幸运的是,Stack Overflow 已经有关于该主题的精彩主题! Rotate around a point that is not (0,0)

【讨论】:

  • Greensock(TweenLite 的制造商)说它可以补间非显示对象,因为它可以补间任何对象的任何数字属性。有些插件需要一个显示对象,所以如果我想使用它们,我必须更改插件。但我用其他插件(如 colorMatrixFilter)对其进行了测试,但仍然无法正常工作(此插件不需要显示对象)。框架的渲染器通过 copyPixels 方法将 bitmapData 复制到画布。我认为这就是为什么它不起作用的问题。预渲染分数没有意义,因为它们是动态创建的。
  • TweenLite 确实可以补间非显示对象。但是 TranformAroundPoint 插件需要一个显示对象。 (例如,您不能围绕一个点转换 alpha 值) - 它似乎对显示对象的舞台属性进行了一些引用。因此,如果显示对象未添加到舞台,则会出现空对象错误。这有意义吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多