Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by silverspectro

Hi everybody,

I've a bit of a problem ( like it isn't obvious enough ), i would like to do some animation before my title screen. For this i wanted to use AnimationSheets, but infortunately, i've been unable to make it work outside an entity.
I've checked the documentation and it is possible apparently...
I'm doing something wrong but i don't know what.

here's my code :

IntroScreen = ig.Game.extend({
    
    animSheet: new ig.AnimationSheet ( 'media/welfring.png', 30, 30 ),
    
    
    
    init: function() {
        ig.input.bind( ig.KEY.X, 'start'); 
	
    },
    
    update: function() {
		var walk= new ig.Animation( this.animSheet, 0.2, [1,2,3,2]);
		
        if(ig.input.pressed ('start')){
            ig.system.setGame(StartScreen)
        }
        
        this.parent();
        
    },
    
    draw: function() {
		var walk= new ig.Animation( this.animSheet, 0.2, [1,2,3,2]);
		
		walk.update();
		
        this.parent();
        
        walk.draw( ig.system.width/2, ig.system.height/2 );
        
    }
});

When i run this everything is fine, there is just one problem, the animation doesn't start...my sprite is drawn on the screen, but there isn't the rest of the animation, like if it was stuck at the first image...

If anybody have any idea, i'd be very happy to hear it

thank you very much ! ^^

1 decade ago by StuartTresadern

in your init create a new aimation for the sheet and set current animation:
this.addAnim( 'walk', 0.2, [1,2,3,4 );
this.currentAnim = this.anims.walk;

remove the var walk from your update and draw.

and then in your draw function you can reference this.currentAnim if required.


Not tested..

1 decade ago by DavidWeber

It's definitely possible, I did this last night.

If what Stuart has said doesn't work.

try
IntroScreen = ig.Game.extend({
    
    animSheet: new ig.AnimationSheet ( 'media/welfring.png', 30, 30 ),
    walk: null,
    
    init: function() {
        ig.input.bind( ig.KEY.X, 'start'); 
		this.walk = new ig.Animation( this.animSheet, 0.2, [1,2,3,2]);
    },
    
    update: function() {
        this.parent();
        this.walk.update();
        if (ig.input.pressed ('start'))
            ig.system.setGame(StartScreen)
    },
    
    draw: function() {
        this.parent();
        this.walk.draw( ig.system.width/2, ig.system.height/2 );
    }
});

1 decade ago by silverspectro

GREAT !

Thank you very much guys !
I love the impact community ! :D

Here's my code, in case anybody have the same problem :

IntroScreen = ig.Game.extend({
    
    animSheet: new ig.AnimationSheet ( 'media/welfring.png', 30, 30 ),
    walk: null,
    
    
    init: function() {
        ig.input.bind( ig.KEY.X, 'start'); 
		this.walk= new ig.Animation( this.animSheet, 0.2, [1,2,3,2]);
    },
    
    update: function() {
		this.parent();
		this.walk.update();
		
        if(ig.input.pressed ('start')){
            ig.system.setGame(StartScreen)
        }
        
        
        
    },
    
    draw: function() {
		
        this.parent();
        
        this.walk.draw( ig.system.width/2, ig.system.height/2 );
        
    }
});

Thank you again !
Page 1 of 1
« first « previous next › last »