collinhover / impactplusplus

Impact++ is a collection of additions to ImpactJS with full featured physics, dynamic lighting, UI, abilities, and more.
http://collinhover.github.com/impactplusplus
MIT License
276 stars 59 forks source link

Uncaught TypeError: Cannot call method 'playFromStart' of undefined #141

Closed Pattentrick closed 10 years ago

Pattentrick commented 10 years ago

Hi @collinhover,

When i spawn my player i get an "Uncaught TypeError: Cannot call method 'playFromStart' of undefined" in the console. But everything works fine in Chrome/Firefox, but in IE my player won't show up.

If I add an existence check at this line:

https://github.com/collinhover/impactplusplus/blob/master/lib/plusplus/abstractities/character.js#L2637

javascript if (this.currentAnim !== anim && this.currentAnim )


It fixes the problem. But i am not sure if this is really a bug, or if i messed my player entity up. Here is the relevant code of my player:

``` javascript```

size: {
    x: 32,
    y: 16
},

canFlipX: false,

canFlipY: false,

temporaryInvulnerabilityAlpha: 1,

maxVelGrounded: {
    x: 50,
    y: 50
},

animInit: 'idle',

animSheet: new ig.AnimationSheet( _c.PATH_TO_MEDIA + 'player.png', 32, 16 ),

animSettings: {
    idle: {
        frameTime: 0.8,
        sequence: [0,1]
    },
    idleDown: {
        frameTime: 0.8,
        sequence: [0,1]
    },
    idleLeft: {
        frameTime: 0.8,
        sequence: [0,1]
    },
    idleRight: {
        frameTime: 0.8,
        sequence: [0,1]
    },
    idleUp: {
        frameTime: 0.8,
        sequence: [0,1]
    },
    moveDown: {
        frameTime: 0.8,
        sequence: [2,3]
    },
    moveUp: {
        frameTime: 0.8,
        sequence: [4,5]
    },
    moveLeft: {
        frameTime: 0.8,
        sequence: [0,1]
    },
    moveRight: {
        frameTime: 0.8,
        sequence: [0,1]
    }
},

animsExpected: [ "idle", "move" ],

What do you think about that? And on a site note, i noticed that there is no local variable/parameter with the name animInit at the placeholdAnims method:

https://github.com/collinhover/impactplusplus/blob/master/lib/plusplus/abstractities/character.js#L726

Is this a typo and it should be this.animInit instead?

collinhover commented 10 years ago

Player looks fine, but your fix is a bit odd. Doesn't that check only allow the current anim to change if the current anim already exists? Can you try the following instead please:

if (this.currentAnim !== anim) {
    this.currentAnim = anim;
    if(this.currentAnim) {
        this.currentAnim.playFromStart();
    }
}

Any better?

Pattentrick commented 10 years ago

Your solution works like a charm. Thanks!

Pattentrick commented 10 years ago

I noticed that you added the fix. Awesome! One question though, what is about the animInit value i mentioned above:

https://github.com/collinhover/impactplusplus/blob/master/lib/plusplus/abstractities/character.js#L726

Is this a typo and it should be this.animInit instead? Or do i just misunderstand the concept? Sorry to ask again about that. I know that you are very busy at the moment with DUELYST. I don't want to get on your nerves ;-)

collinhover commented 10 years ago

Oops you're totally right, it should be this.animInit. I'll change that now, thanks for catching that :-)

Pattentrick commented 10 years ago

You are welcome :D