【问题标题】:How to move the stage within a class in Actionscript3?如何在 Actionscript3 的班级内移动舞台?
【发布时间】:2011-12-18 14:45:42
【问题描述】:

好的,我知道如何通过修改第 1 层操作脚本中的 this.x 和 this.y 变量来在实际 .fla 文件中移动舞台。

但是在文档类中——公共类 Starlight 扩展了 MovieClip,无论我尝试什么,它似乎都不起作用,我的研究将我引向了这个使用代码:

for( i = 0; i < stage.numChildren; i ++){
        stage.getChildAt(i).x -= player.speedx * player.bounceSpeed;
    stage.getChildAt(i).y -= player.speedy * player.bounceSpeed;
}

我确实意识到,与实际移动舞台本身相比,它很笨拙且速度较慢。而且我不确定如果另一个移动的物体进入舞台会发生什么,因为从技术上讲,这段代码不自然地改变了舞台上所有东西的 x,y。

任何帮助表示赞赏! 干杯

编辑:试过这个--

    var stage2:Sprite = new Sprite();
        stage2.x = stage.stageWidth / 2;
        stage2.y = stage.stageHeight / 2;
        stage2.width = 4000;
        stage2.height = 4000;
        addChild(stage2);

        for (i = 1; i < 50; i ++)
        {
            var asteroid:Asteroid = new Asteroid();
            asteroid.x = Math.round(Math.random() * stage.stageWidth * 4);
            asteroid.y = Math.round(Math.random() * stage.stageHeight * 4);
            stage2.addChild(asteroid);
            collisionList.addItem(asteroid);
            asteroids.push(asteroid);
        }

【问题讨论】:

  • 你得到什么样的结果?一个错误,或者什么都没有,或者?..
  • 小行星根本不会生成,我无法与 Player 相撞。如果我从 addchild(asteroid) 中删除 stage2,它们会生成。

标签: class actionscript move stage


【解决方案1】:

哇,别动舞台!

创建一个MovieClipSprite 并将所有内容粘贴在那里,然后只需移动该对象即可。

var stage2:Sprite = new Sprite();

stage2.addChild(something);
stage2.addChild(somethingElse);

stage2.x = 10;
stage2.y = 10;

【讨论】:

  • 谢谢。我已经尝试过了,但它不起作用:我会将我的 OP 编辑​​为我尝试过的新代码。
  • 为什么要将 stageWidth 乘以 4 将容器精灵居中?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-28
  • 2014-02-01
  • 2012-11-22
  • 1970-01-01
  • 2013-10-19
相关资源
最近更新 更多