9 years ago
by ijed
Hi guys,
I've searched around a bit and couldn't find a similar issue, either here or in general.
I'm new to Impact and have been adapting the jump n run demo to something new.
When constructing my checkpoint entity I used the coin as a base. Problem is, whenever I try running an animation on it I get the cyclic error
Uncaught TypeError: this.currentAnim.update is not a function
I thought this was because the coin entity originally avoided this.parent, so included that instead of the update animation call, but that instead tells me that Draw is not a function.
I've reordered the code several times but the basic thing remains - if I try to play animation it breaks.
Can someone point me in the right direction?
It's just that we can't start until you give us your code. Have you done
this.addAnim(...) yet?
9 years ago
by ijed
Sorry, I thought this would be a n00b gotcha. Here's the code so far:
ig.module(
'game.entities.graveskull'
)
.requires(
'impact.entity'
)
.defines(function(){
EntityGraveskull = ig.Entity.extend({
size: {x: 16, y: 4},
offset: {x: 8, y: 28},
type: ig.Entity.TYPE.NONE,
checkAgainst: ig.Entity.TYPE.A,
collides: ig.Entity.COLLIDES.NEVER,
animSheet: new ig.AnimationSheet( 'media/graves.png', 32, 32 ),
sfxCollect: new ig.Sound( 'media/sounds/coin.*' ),
status: 0,
burned: 0,
init: function( x, y, settings ) {
this.parent( x, y, settings );
this.zIndex = -10;
this.addAnim( 'inactive', 0.1, [0]);
this.addAnim( 'activate', 0.1, [1,2], true);
this.addAnim( 'burn', 0.1, [4,5], true);
},
update: function()
{
this.currentAnim.update();
},
check: function( other )
{
if (other instanceof EntityPlayer)
{
if ((other.health == 1) && (this.burned == 0) )
{
other.health = 3;
this.status = 1;
this.sfxCollect.play();
}
}
}
});
});
9 years ago
by ijed
It's a bit confusing because there are multiple states for the object, and they're not yet written.
It works as a waypoint and as a way for the player to restore themselves from a damaged state.
Also, right now the script that plays the animation is disabled to avoid the crash.
I haven't figured out the respawn point code yet either, but no worries :)
Thanks in advance!
Try on update:
console.log(this.currentAnim);
9 years ago
by ijed
That's interesting.
It logs no animation until I trigger one by playing, at which point it breaks with the same error and some 'not the droids you're looking for' error;
function () {
this.timer.set();
this.loopCount = 0;
this.frame = 0;
this.tile = this.sequence[0];
return this;
}
It does however tell me that the error is originating in entity.js line 101, which is where ImpactJS calls the exact same animation update. Not surprising, I know, but I haven't yet begun digging around in the guts of the system.
So whatever it is I'm provoking is most likely some stupid syntax thing that cripples the engine, or else a similar obvious requirement I've not included...
9 years ago
by Joncom
There&
039;s a few places in your code where you incorrectly call #rewind
this.currentAnim = this.anims.burn.rewind;
this.currentAnim = this.anims.burn.rewind();
Calling
rewind
or any of the animation methods like this would cause the issue, because you&
039;re not actually setting #this.currentAnim
to a valid animation.
9 years ago
by ijed
Confirmed and fixed.
Thank you!
Is there some sort of debugger or fake compiler I can use for these types of errors?
I doubt I'll be making this particular mistake again, but it's very easy to miss a , or something when writing out large blocks.
9 years ago
by Joncom
It&
039;s simply important to note that "methods" or "functions" are called with #()
. Your code was syntactically valid. It just wasn't what the ImpactJS engine expected you to do.
Edit:
The error makes sense because you were setting
this.currentAnim
to a function (instead of object with a property called
update
).
I suppose if you were using something like
TypeScript, then a linter could have told you that you set
this.currentAnim
to an invalid type, however a stable TypeScript version of ImpactJS is not available...
Page 1 of 1
« first
« previous
next ›
last »