首先,这是我的第一篇文章,欢迎这个社区的每个人。我已经找到了大量的信息,帮助我解决了迄今为止遇到的问题。现在我遇到了一个我无法解决的问题。我正在做一个“庞”类型的游戏,可能你们中的一些人已经看过或玩过某种变化。所以说到这一点。我目前正试图制作一个与一个类相关联的对象,在舞台上反弹。我决定尝试使用easeIn和easeOut补间。
我声明主文档类中的补间:
public static var upTween:Tween;
public static var downTween:Tween;
并使用for循环将其值分配给数组的所有对象:
public function bounce(event:Event):void
{
for (var i:uint = 0; i < bubbles1.length; i++)
{
upTween = new Tween(bubbles1[i], "y", Strong.easeOut, bubbles1[i].y, 250, 2, true);
downTween = new Tween(bubbles1[i], "y", Strong.easeIn, bubbles1[i].y, stage.stageHeight - 50 - bubbles1[i].height, 2, true);
}
}
现在,当我尝试从Bubble.as类中启动补间时,我得到一个空对象引用。
或许更多信息会有所帮助。我正在主类中的公共函数中实例化对象,如下所示:
public function makeBubble(size:Number, xCoordinate:Number, yCoordinate:Number, xDir:Number):void
{
if (size == 1)
{
bubble = new Bubble(stage);
bubble.x = xCoordinate;
bubble.y = yCoordinate;
bubble.xDirection = xDir;
bubbles1.push(bubble);
stage.addChild(bubble);
}
这是完整的Bubble.as类:
package com.zdravko.pong
{
import flash.display.MovieClip;
import flash.display.Stage;
import flash.events.Event;
public class Bubble extends MovieClip
{
private var stageRef:Stage;
var xDirection:Number;
var yDirection:Number;
var bubble2:Bubble2;
public function Bubble(stageRef:Stage)
{
// constructor code
this.stageRef = stageRef;
addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
}
function loop(event:Event):void
{
if(this.x >= stage.stageWidth - this.width)
{
this.x = stage.stageWidth - this.width - 5;
xDirection *= -1;
}
if(this.x <= 0)
{
this.x = 5;
xDirection *= -1;
}
if(this.y >= stage.stageHeight - 50 - this.height)
{
this.y = stage.stageHeight - 50 - this.height;
Engine.upTween.start();
}
if(this.y <= 250)
{
this.y = 250;
Engine.downTween.start();
}
this.x += xDirection;
if(hitTestObject(Engine.player) && Player.invul == false)
{
decreaseEnergy(.4);
Player.invul = true;
Player.invulTimer.start();
}
}
public function decreaseEnergy(dmg:Number):void
{
Engine.energy.scaleX -= dmg;
}
public function takeHit() : void
{
makeBubble(2, this.x + 50, this.y + 30, 8, 8);
makeBubble(2, this.x - 20, this.y - 30, -8, 8);
removeSelf();
Engine.playerScore += 500;
Engine.score.scoreBox.text = Engine.playerScore;
}
private function removeSelf() : void
{
removeEventListener(Event.ENTER_FRAME, loop);
if (stageRef.contains(this))
{
stageRef.removeChild(this);
}
}
private function makeBubble(size:Number, xCoordinate:Number, yCoordinate:Number, xDir:Number, yDir:Number):void
{
bubble2 = new Bubble2(stage);
bubble2.x = xCoordinate;
bubble2.y = yCoordinate;
bubble2.xDirection = xDir;
bubble2.yDirection = yDir;
Engine.bubbles2.push(bubble2);
stageRef.addChild(bubble2);
}
}
}
答案 0 :(得分:0)
据推测,bubbles数组返回一个空值。您是否尝试过追踪bubbles1数组中的值。
public function bounce(event:Event):void
{
for (var i:uint = 0; i < bubbles1.length; i++)
{
// log out the value from your array
trace("bubble " + bubbles1[i]);
}
}