Play an entire animation with a single button press


(Oli) #1

if (Input.pressed(Global.keyA) && counter > 50) { pull(); }

public function pull():void { sprSword.play(“pull”,true); trace(“pulling!”) }

This only plays the first frame of the spritemap and gets stuck there any suggestion I would appreciate:)

i have verified i am super updating in the main


(Jean) #2

And where’s the code you defined the animation “pull”? How you created the instance of the graphic of your sprSword?


(Oli) #3
public var sprSword:Spritemap = new Spritemap(Assets.SWORD, 64, 96)
    public var sprLight:Spritemap = new Spritemap(Assets.SWORD, 64, 96)
    
    public var counter:int;
    public var start:Point;
                    

    public function Sword(x:int, y:int) 
    {
        
        sprLight.alpha = .5
        
        sprLight.add("Light", [ 0, 1, 2, 3], 10, true);
        sprSword.add("Sword", [ 4, 5, 6, 7], 10, true);
        sprSword.add("force", [8, 9, 10, 11], 5, true);
        sprSword.add("idle", [12, 13, 14, 15], 5, true);
        sprSword.add("pull", [16, 17, 18, 19], 5, true);
        sprSword.add("pose", [20, 21, 22, 23], 5, true);
        sprSword.add("poseIdle", [24, 25, 26, 27], 5, true);
        
        
        
        var display:Graphiclist = new Graphiclist(sprSword,sprLight);
                    
        
        addGraphic(display)
        sprLight.play("Light");
        
        addGraphic(display)
        sprSword.play("Sword");

(Jean) #4

I think I got it. Since you are making the call of the animation everytime the key A is pressed, then make

sprSword.play("pull",false);

So if pull is already playing it doesn’t do anything.


(Oli) #5

nope this dosent do it either:(


(Jean) #6

Probably won’t change anything but I have a few sugestions…

May I know why you have to Spritemaps using the same image as source? Using only one Spritemap won’t be enough? I saw that they have different alphas but you could try using only one and setting the alpha everytime the animations change.

Also, you dont have to call twice addGraphic if you already made yourself the GraphicList, either add sprLight and sprSword, or set the graphic property as display, or call once addGraphic using display.


(Oli) #7

yea those are great ideas…


(Granit Bajraktari) #8

I dont think it will solve the problem but why would you want the animation to loop?

Also see the docs here


(Martí Angelats i Ribera) #10

What’s that animation? A player’s sword? A projectile?

If it’s a player’s wapon you shouldn’t be unig something in the main. Actually no graphic should be in the main, at most you should have it in the Wold.

Explain what you want a bit, so we can help more.

Note: I don’t think you’d have to use a fuction to create it unless it’s a projectile. But in that case you would be making an Entity not a graphic.


(Oli) #11

hey i just figured out, my problem was that two animations wanted to play at the same time so it froze. Thx