Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.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 为每个级别的相同电影剪辑对象更改变量_Actionscript 3_Function_Movieclip - Fatal编程技术网

Actionscript 3 为每个级别的相同电影剪辑对象更改变量

Actionscript 3 为每个级别的相同电影剪辑对象更改变量,actionscript-3,function,movieclip,Actionscript 3,Function,Movieclip,嘿,伙计们,我想知道怎么做有点困难。我有一个名为mcGoal_1的电影剪辑对象,在它的类中,我使用TweenLite使它在舞台上垂直上下移动。在级别_1上,它从底部开始,但在启动级别_2时,我希望它从顶部开始,但无法确定如何更改每个级别的值以实现此目的。下面是我用于从底部开始的代码: private function init():void { TweenMax.to(this, 4, { y:40, repeat: -1, yoyo:true, ease:Power0

嘿,伙计们,我想知道怎么做有点困难。我有一个名为mcGoal_1的电影剪辑对象,在它的类中,我使用TweenLite使它在舞台上垂直上下移动。在级别_1上,它从底部开始,但在启动级别_2时,我希望它从顶部开始,但无法确定如何更改每个级别的值以实现此目的。下面是我用于从底部开始的代码:

private function init():void 
    {
        TweenMax.to(this, 4, { y:40, repeat: -1, yoyo:true, ease:Power0.easeInOut } );
        TweenLite.from(this, 2, {autoAlpha:0});       
    }
然后在我的引擎类中,我使用以下代码将其添加到阶段:

   mcGoal_1 = new goal_1();
stage.addChild(mcGoal_1);
mcGoal_1.x = (stage.stageWidth / 2) + 350;
mcGoal_1.y = (stage.stageHeight) - 35;
所以一切都很好,但我想完成的是在每个新级别开始时改变mcGoal_1的位置。因此,在2级中,我希望我的mcGoal_1位置从顶部开始,而不是从底部开始这里是从顶部开始的代码:

mcGoal_1级:

private function init():void 
    {

        TweenMax.to(this, 2.8, { y:445, repeat: -1, yoyo:true, ease:Power0.easeInOut } );
        TweenLite.from(this, 2, {delay:2,autoAlpha:0}); 

    }
然后在发动机类中:

mcGoal_1 = new goal_1();
        mcGoal_1.x = (stage.stageWidth / 2) + 350;
        mcGoal_1.y = (stage.stageHeight) - 445;
Private Function startAtTop():void
    {
  mcGoal_1 = new goal_1();
        stage.addChild(mcGoal_1);
        mcGoal_1.x = (stage.stageWidth / 2) + 350;
        mcGoal_1.y = (stage.stageHeight) - 35;

  TweenMax.to(mcGoal_1, 4, { y:40, repeat: -1, yoyo:true, ease:Power0.easeInOut } );

    }




Private Function startAtBottom():void
{
  mcGoal_1 = new goal_1();
        mcGoal_1.x = (stage.stageWidth / 2) + 350;
        mcGoal_1.y = (stage.stageHeight) - 445;

 TweenMax.to(mcGoal_1, 2.8, { y:445, repeat: -1, yoyo:true, ease:Power0.easeInOut } );

}
现在从顶部开始

我现在是如何做到这一点的,我正在创建多个mcgoal。我每个级别都有一个新的目标,所以现在我有大约10个目标。但是我在想,如果我能在每一个新的关卡上更改mcGoal_1的值,而不是创建一个全新的电影剪辑,从顶部开始,而不是从底部开始,那会容易得多。我在想,也许我需要创建两个单独的函数,一个函数用于舞台顶部,另一个用于舞台底部。所以我会从我的mcGoal_1类中取出Tweens并将它们添加到Engine类中,这样我就可以正确地更改值了

发动机类中可能会出现类似的情况:

mcGoal_1 = new goal_1();
        mcGoal_1.x = (stage.stageWidth / 2) + 350;
        mcGoal_1.y = (stage.stageHeight) - 445;
Private Function startAtTop():void
    {
  mcGoal_1 = new goal_1();
        stage.addChild(mcGoal_1);
        mcGoal_1.x = (stage.stageWidth / 2) + 350;
        mcGoal_1.y = (stage.stageHeight) - 35;

  TweenMax.to(mcGoal_1, 4, { y:40, repeat: -1, yoyo:true, ease:Power0.easeInOut } );

    }




Private Function startAtBottom():void
{
  mcGoal_1 = new goal_1();
        mcGoal_1.x = (stage.stageWidth / 2) + 350;
        mcGoal_1.y = (stage.stageHeight) - 445;

 TweenMax.to(mcGoal_1, 2.8, { y:445, repeat: -1, yoyo:true, ease:Power0.easeInOut } );

}
然后,我将只调用每个新级别中的任何函数。但这并不能完全起作用,因为该函数每秒调用一帧,这导致TweenLite无法正常工作


如果您有任何帮助,我们将不胜感激

在我看来,你只需要一门课。您有一个init方法。您应该向init方法提供正确设置自身所需的信息

目标:

LevelConfig类:

package{
import flash.geom.Point;

public class LevelConfig {

    private var _startPosition:Point;
    private var _endPosition:Point;

    //add more properties

    public function LevelConfig(startPosition:Point, endPosition:Point) {
        this._startPosition = startPosition;
        this._endPosition = endPosition;
    }

    public function get endPosition():Point {
        return _endPosition;
    }

    public function set endPosition(value:Point):void {
        _endPosition = value;
    }
}
}
发动机:

function initLevels():void
{
    levels = new Vector.<LevelConfig>();
    levels.push(new LevelConfig(new Point((stage.stageWidth / 2) + 350,(stage.stageHeight) - 445),new Point((stage.stageWidth / 2) + 350,445));

    levels.push(new LevelConfig(new Point((stage.stageWidth / 2) + 350, 445),new Point((stage.stageWidth / 2) + 350,(stage.stageHeight) - 445));

    //add more levels
}

var levels:Vector.<LevelConfig>;
initLevels();

function startLevel(level:int):void
{
    var mcGoal:Goal = new Goal();
    var config:LevelConfig = levels[level];

    mcGoal.init(config.startPoint,config.endPoint);
}
函数initLevels():void
{
级别=新向量。();
levels.push(新LevelConfig(新点((stage.stageWidth/2)+350,(stage.stageHeight)-445),新点((stage.stageWidth/2)+350445));
levels.push(新LevelConfig(新点((stage.stageWidth/2)+350445),新点((stage.stageWidth/2)+350,(stage.stageHeight)-445);
//添加更多级别
}
变量水平:向量。;
initLevels();
函数级别(级别:int):无效
{
var mcGoal:Goal=新目标();
变量配置:LevelConfig=levels[level];
init(config.startPoint,config.endPoint);
}
然后您可以通过调用
startLevel(levelIndex)
您通常会从外部source.XML或JSON加载级别配置
请注意,levelIndex以0开头!因此,您的级别1是0。您还可以在此模型中添加级别名称、说明和其他内容。

很有趣。因此您分配了点变量。但我仍然对代码有点困惑。我不太清楚它将如何更改每个新级别的起始位置。请参阅我的添加内容。您没有o为你的级别构造某种配置。用方法布置一个项目的所有可能位置是不实际的。