How to use CitrusSprite.velocity

48 views Asked by At

I have the following function in a scene that extends citrus.core.starling.StarlingState - it loads the PlayerRun animation and displays it on the screen. For the most part, this code works: I see the sprite on the screen (it's running in place).

protected final override function DrawScene ():void
{
    Player = new CitrusSprite ( "Player" );

    Player.velocity = [60, 0]; // Doesn't seem to have an effect
    Player.x = 40;
    Player.y = 40;

    var oClip:MovieClip = new MovieClip ( Resources.getTextures ( 
        "PlayerRun" ), 24 );

    Player.view = oClip;

    add ( Player );
}

I'm not sure how I'm supposed to use the velocity property - there's no documentation for it and no matter what numbers I use in the code above, it doesn't change the display: the animation plays but the sprite is stationary (it doesn't move horizontally as I would expect it).

Am I using the velocity property incorrectly? Does Citrus support sprite velocity or is this something I'd have to implement myself?

2

There are 2 answers

1
xxbbcc On

As it turns out, CitrusSprite has a property, updateCallEnabled that's false by default and disables calls to update(). Once I set this property to true, the code started working as expected.

1
Marty On

I haven't used Citrus yet, but looking at the source code it should work the way you've gone about it assuming that the update method is called on your player:

You can review the way the velocity property works at these locations:

I suspect you need to add the player to something that will queue it for updating.