Uncaught TypeError: Cannot call method 'playFromStart' of undefined
Closed this issue · 5 comments
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:
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:
Is this a typo and it should be this.animInit
instead?
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?
Your solution works like a charm. Thanks!
I noticed that you added the fix. Awesome! One question though, what is about the animInit
value i mentioned above:
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 ;-)
Oops you're totally right, it should be this.animInit. I'll change that now, thanks for catching that :-)
You are welcome :D