cocos2d-js

Progress Timer Cocos JS v3


I'm newbie in cocos-js.

I want to make a health bar in cocos JS and try this code. And i choose to use Progress Timer. But when i use this code, it just show the bar, no running action. What's wrong ?

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);

Solution

  • This code is working for me very well:

    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);