Problem with animation of character

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
markonway
Posts: 6
Joined: Thu Jul 23, 2020 6:45 pm

Problem with animation of character

Post 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.
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: Problem with animation of character

Post 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?
markonway
Posts: 6
Joined: Thu Jul 23, 2020 6:45 pm

Re: Problem with animation of character

Post 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
markonway
Posts: 6
Joined: Thu Jul 23, 2020 6:45 pm

Re: Problem with animation of character

Post 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
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: Problem with animation of character

Post 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.
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: Problem with animation of character

Post 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] );
markonway
Posts: 6
Joined: Thu Jul 23, 2020 6:45 pm

Re: Problem with animation of character

Post 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.
markonway
Posts: 6
Joined: Thu Jul 23, 2020 6:45 pm

Re: Problem with animation of character

Post 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
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: Problem with animation of character

Post 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
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: Problem with animation of character

Post 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.
Post Reply

Return to “Beginner Help and Support”