Page 1 of 1

Problem with animation of character

Posted: Thu Jul 23, 2020 6:55 pm
by markonway
Hello, I was watching the tutorials on youtube how to create a PRG with impactjs from the howell gene channel. I'm in part 3. My character, him and a sprite of him turns, but it's not changing. 32px / 62px. The character.png is 3/4 (and sorry, i'm a brazillian guy and i used a google translater.)

The is my code Player.js:

Code: Select all

ig.module(
    'game.entities.player'
)
    .requires(
    'impact.entity'
)
    .defines(function(){
         EntityPlayer = ig.Entity.extend({
            animSheet: new ig.AnimationSheet( 'media/character.png', 32, 62 ),
            size: {x: 32, y: 62},
            type: ig.Entity.TYPE.A,
            checkAgainst: ig.Entity.TYPE.NONE,
            collides: ig.Entity.COLLIDES.PASSIVE,

            speed:80,

            init: function( x, y, settings ) {
                this.parent( x, y, settings );

                this.addAnim( 'up', .1, [6,7,8]);
                this.addAnim( 'down', .1, [0,1,2]);
                this.addAnim( 'left', .1, [9,10,11] );
                this.addAnim( 'right', .1, [11,12,13] );

                this.addAnim( 'idleup', .1, [8] );
                this.addAnim( 'idledown', .1, [0] );
                this.addAnim( 'idleleft', .1, [5] );
                this.addAnim( 'idleright', .1, [11] );

                this.currentAnim = this.anims.idleup;
            },

            update: function() {
                //Move Left Or Right

                if ( ig.input.state('left') && ismove != 2 && ismove != 3 && ismove != 4 ) {
                    this.vel.x = -this.speed;
                    var ismove = 1;
                    this.direction = 1;
                    this.currentAnim = this.anims.left;
                }else if ( ig.input.state('right') && ismove != 1 && ismove != 3 && ismove != 4 ) {
                    this.vel.x = +this.speed;
                    var ismove = 2;
                    this.direction = 2;
                    this.currentAnim = this.anims.right;
                }else if ( ig.input.state('up') && ismove != 1 && ismove != 2 && ismove != 4 ){
                    this.vel.y = -this.speed;
                    var ismove = 3;
                    this.direction = 3;
                    this.currentAnim = this.anims.up;
                }else if ( ig.input.state('down') && ismove != 1 && ismove != 2 && ismove != 3 ){
                    this.vel.y = +this.speed;
                    var ismove = 4;
                    this.direction = 4;
                    this.currentAnim = this.anims.down;
                }else{
                    this.vel.x = 0;
                    this.vel.y = 0;
                    var ismove = 0;
                }

                /////

                if ( this.direction == 1 ){
                    this.currentAnim = this.anims.idleleft;
                }else if ( this.direction == 2 ){
                    this.currentAnim = this.anims.idleright;
                }else if ( this.direction == 3 ){
                    this.currentAnim = this.anims.idleup;
                }else{
                    this.currentAnim = this.anims.idledown;
                }

                this.parent();
            }
        });
    });
and gene howell, if you're reading this, you're an expensive legend. Your videos from 8 years ago I am watching today in 2020, there are no tutorials in Portuguese, so I had to search in English even knowing only the basics in English. Thankyou very much gene howell.

Re: Problem with animation of character

Posted: Thu Jul 23, 2020 7:42 pm
by hallsofvallhalla
It has been a long time so I am a bit rusty on impact but i re watched the video. Do you have "this.parent();" at the end of the function?

Re: Problem with animation of character

Posted: Thu Jul 23, 2020 8:00 pm
by markonway
hallsofvallhalla wrote:It has been a long time so I am a bit rusty on impact but i re watched the video. Do you have "this.parent();" at the end of the function?
yes, you can see her:
Captura de tela de 2020-07-23 16-58-45.png

Re: Problem with animation of character

Posted: Thu Jul 23, 2020 11:46 pm
by markonway
updating: I downloaded the files from part 3 of the video that posted here on the forum (player.js and main.js) the animation worked, but ... when walking up, left and right the animation is missing something, for example : sprites 1, 2, 3, one of them does not appear. As if one of the 3 does not appear. But when I walk down, the animation works normal, just left / right / up that one of the sprites doesn't appear
Captura de tela de 2020-07-23 20-39-53.png

Re: Problem with animation of character

Posted: Thu Jul 23, 2020 11:57 pm
by hallsofvallhalla
Does the character actually disappear or does it jump animation? It goes 0,1,2 then jumps back to 0. Try doing [0,1,0,2] and see if that helps.

Re: Problem with animation of character

Posted: Thu Jul 23, 2020 11:59 pm
by hallsofvallhalla

Code: Select all

this.addAnim( 'up', .1, [6,7,6,8]);
                this.addAnim( 'down', .1, [0,1,0,2]);
                this.addAnim( 'left', .1, [9,10,9,11] );
                this.addAnim( 'right', .1, [11,12,11,13] );

Re: Problem with animation of character

Posted: Fri Jul 24, 2020 1:15 am
by markonway
When I press down, the character is normally. Even with these changes, left / right / top continues to have the same problem. For example when I press to go right:

this.addAnim ('right', .1, [11,12,11,13]);

it is as if one of the items in this array did not have a sprite, [11, no sprite, 11, no sprite]. And also when I stop walking, the character is without a sprite, only when I walk down he gets the sprite.

Re: Problem with animation of character

Posted: Fri Jul 24, 2020 8:29 pm
by markonway
markonway wrote:When I press down, the character is normally. Even with these changes, left / right / top continues to have the same problem. For example when I press to go right:

this.addAnim ('right', .1, [11,12,11,13]);

it is as if one of the items in this array did not have a sprite, [11, no sprite, 11, no sprite]. And also when I stop walking, the character is without a sprite, only when I walk down he gets the sprite.
would it be possible that impactjs is trying to get a sprite on the right? as if it were 4/4 and not 3/4

Re: Problem with animation of character

Posted: Sat Jul 25, 2020 3:45 pm
by hallsofvallhalla
Sorry for delay in response. Was away. The only way it would try to get additional sprite is if your image is not what your measurement defines. for instance not compatible with 32x62

Re: Problem with animation of character

Posted: Sat Jul 25, 2020 3:49 pm
by hallsofvallhalla
try to add another animation to the right and see what happens. Like make a copy of your sprite sheet and add another image just for a test.