drpelz
drpelz

Reputation: 811

tweenlite not working with bitmaps?

I have the following problem when I try to use TweenLite with a Bitmap:

I get strange error messages when applying TweenLite to a Bitmap (tempScore.bitmap). GetBounds works. The bitmap has transparency. Does anyone have an idea why it doesn't work? Any help appreciated. Thanks.:)

When using a getBounds-Method I get this:

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

This is the error message:

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()

My imported and activated libraries look like this:

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]);

This is the part where I try to use TweenLite on my tempScore:

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);

                }
        }

So far as I can see the getBounds-values are ok. My game is based on a gameframework. There's a renderer inside of it. Call me an idiot if I'm wrong but is it possible that the renderer of the framework and tweenlite are getting in each other's way??

TweenLite has problems with other similar objects like tempAsteroid. A lot of objects are drawn onto a canvas with copyPixels (blitting-method).

tempScore is a Score-object. The Score object is based on a BasicBlitArrayObject. Otherwise this object extends an EventDispatcher. I hope this little info helps.

This is the scoreManager which manages the look and properties of tempScore:

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);
            }
    }
}

Here is some code of the BasicBlitArrayObject (tempScore rests upon that (i.e. 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;
    }

}

}

Upvotes: 1

Views: 897

Answers (1)

Plastic Sturgeon
Plastic Sturgeon

Reputation: 12527

I think the problem is simple, but the resolution is not. The objects you are trying to transform are blitted. So they are not added to the stage. So the object's stage property is null. I suspect that the TransformAroundPoint plugin is trying to use the object's stage property, and that is throwing a null object error your are seeing. To see a simple example of this, make a very simple file. Create two bitmaps, add one to the stage, and don't add the other. Apply the tween to the stage instance, it will work. Then apply the tween to the off-stage instance, and you should get the same error you get in the game.

What you will need to do instead is handle the transform yourself. Instead of using TweenLite to rotate around a point, do it yourself. Fortunately Stack Overflow already has a great thread on that topic! Rotate around a point that is not (0,0)

Upvotes: 1

Related Questions