Progress Timer Cocos JS v3

问题描述 投票:2回答:2

我是cocos-js的新手。

我想在cocos JS中制作一个健康栏,然后尝试以下代码。我选择使用进度计时器。但是,当我使用此代码时,它仅显示该栏,没有运行操作。怎么了?

var healthBar = cc.ProgressTimer.create(cc.Sprite.create("health_bar1.png"));
            healthBar.setType(cc.PROGRESS_TIMER_TYPE_BAR);
            healthBar.setBarChangeRate(cc.p(1,0));
            healthBar.setMidpoint(cc.p(0,0));
            this.addChild(healthBar, 1);
            healthBar.setPosition(cc.winSize.width/2, cc.winSize.height/2);
            var to1 = cc.progressTo(5, 100);
            healthBar.runAction(to1);
cocos2d-js
2个回答
0
投票

此代码非常适合我:

var healthBar = cc.ProgressTimer.create(cc.Sprite.create("health_bar1.png"));
        healthBar.setType(cc.ProgressTimer.TYPE_BAR);
        healthBar.setBarChangeRate(cc.p(1,0));
        healthBar.setMidpoint(cc.p(0,0));
        healthBar.setPosition(cc.winSize.width/2, cc.winSize.height/2);
        this.getParent().addChild(healthBar, 1);
        var to1 = cc.progressTo(5, 100);
        healthBar.runAction(to1);

0
投票

您可以参考cocos本身提供的示例。你可以在这里找到它。https://cocos2d-x.org/js-tests/

© www.soinside.com 2019 - 2024. All rights reserved.