Sign in to follow this  
Ninjadoodle

Scaling a sprite with another sprite tweening inside?

Recommended Posts

Hi @enpu / Panda People

I have a question about tweening and sprites inserted into other sprites.

I've created a timer bar and I would like to change the width of the whole bar to stretch to a width of the browser window (as the window is stretched).

I'm doing this inside the update function of the class.

Inside the timer bar there is another bar that is tweening it's width to 0.

When I try to change the width of the parent sprite, the tweening on the child sprite does not work as expected.

Is this possible?

Thank you in advance!

game.createClass('TimerBarBottom', {

    init: function() {
        
        this.xPos = 0 - (game.system.width / 2 - game.system.originalWidth / 2) + 50;
        this.yPos = game.system.originalHeight - 128 + (game.system.height / 2 - game.system.originalHeight / 2);
        
        this.bg = new game.Graphics();
        this.bg.fillColor = '#ff0000';
        this.bg.drawRect(0, 0, game.system.width - 100, 128);
        this.bg.position.set(this.xPos, this.yPos);
        this.bg.addTo(game.scene.fg);
        
        this.bar = new game.Graphics();
        this.bar.fillColor = '#ffff00';
        this.bar.drawRect(0, 0, game.system.width - 100, 128);
        this.bar.addTo(this.bg);
        
        this.fg = new game.Graphics();
        this.fg.fillColor = '#000000';
        this.fg.drawRect(0, 0, game.system.width - 100, 64);
        this.fg.alpha = 0.1;
        this.fg.addTo(this.bg);
    },
    
    start: function() {
        
        game.Tween.add(this.bar.scale, {
            x: 0
        }, 20000, {
            easing: 'Linear.None'
        }).start();
    },
    
    update: function() {
        
        this.bg.scale.set(game.system.width - 100, 128);
        this.bg.position.set(this.xPos, this.yPos);
    }
});

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.