CreateJS是否包含类似于“;ENTER_FRAME”;在AS3

Does CreateJS contain an event listener similar to "ENTER_FRAME" in AS3?

本文关键字:FRAME AS3 ENTER 包含 类似于 CreateJS 是否      更新时间:2023-09-26

我正在尝试将"Actionscript 3.0:Game Programming University"中的效果转换为HTML5 Canvas渲染,更具体地说,是Create/EsselJS。

这是我正在处理的代码:

    private var flipStep:uint;
    private var isFlipping:Boolean = false;
    private var flipToFrame:uint;
    // begin the flip, remember which frame to jump to
    public function startFlip(flipToWhichFrame:uint) {
        isFlipping = true;
        flipStep = 10;
        flipToFrame = flipToWhichFrame;
        this.addEventListener(Event.ENTER_FRAME, flip);
    }
    // take 10 steps to flip
    public function flip(event:Event) {
        flipStep--; // next step
        if (flipStep > 5) { // first half of flip
            this.scaleX = .20*(flipStep-6);
        } else { // second half of flip
            this.scaleX = .20*(5-flipStep);
        }
        // when it is the middle of the flip, go to new frame
        if (flipStep == 5) {
            gotoAndStop(flipToFrame);
        }
        // at the end of the flip, stop the animation
        if (flipStep == 0) {
            this.removeEventListener(Event.ENTER_FRAME, flip);
        }
    }

我已经完成了一半,才意识到它几乎需要一步一步地推动每一帧才能正确设置动画。这是我在HTML5:中的JS等价物

function FlipTile(e)
{
    if (!TileFlipping)
    {
        var flipStep = 30;
        var sprite = e.currentTarget;
        console.log(sprite);
        TileFlipping = true;
        flipStep--;
        if (flipStep > 15)
        {
            sprite.scaleX = .02 * (flipStep-6);
        } else {
            sprite.scaleX = .02 * (5 - flipStep);
        }

        if (flipStep == 0)
        {
            TileFlipping = false;
        }
    }
}

然而,这种效果就像一张卡在中心翻转一样这会破坏并"扭曲"精灵翻转,但没有一步一步。它也只发射一次,打破了翻转计数器。这让它开始寻找ENTER_FRAME的等价物。。或者一种替代的方法。此刻,我被难住了。

不太确定我是否答对了你的问题,但你应该使用CreateJS Ticker来更新舞台上的内容,请查看此处的文档:http://www.createjs.com/docs/easeljs/classes/Ticker.html您可以将Event.ENTER_FRAME替换为"tick",并保持与AS3示例中相同的逻辑。

在内部,Ticker使用window.requestAnimationFrame,它通常每秒运行60次(=60fps(。https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame