Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by chadpeppers

I was currently reading through an HTML5 canvas game development book and they have some examples i am following through. The problem is there is an error in there code and I cannot seem to figure out why.

Error receiving:
SyntaxError: Unexpected identifier

ig.module(
'game.entities.zombie'
)
.requires(
'impact.entity'
)
.defines(function(){
EntityZombie = ig.Entity.extend({
animSheet: new ig.AnimationSheet( 'media/zombie.png', 16, 16 ),
size: {x: 8, y:14},
offset: {x: 4, y: 2},
flip: false,
maxVel: {x: 100, y: 100},
friction: {x: 150, y: 0},
speed: 14,

init: function( x, y, settings ) {
this.parent( x, y, settings );
this.addAnim('walk', .07, [0,1,2,3,4,5]);

},

update: function() {
// near an edge? return!
if( !ig.game.collisionMap.getTile(
this.pos.x + (this.flip ? +4 : this.size.x −4),
this.pos.y + this.size.y+1;
)
) {
this.flip = !this.flip;
}
var xdir = this.flip ? −1 : 1;
this.vel.x = this.speed * xdir;
this.currentAnim.flip.x = this.flip;
this.parent();
},
},

handleMovementTrace: function( res ) {
this.parent( res );
// collision with a wall? return!
if( res.collision.x ) {
this.flip = !this.flip;
}
},	
});	
});

1 decade ago by Joncom

Quote from chadpeppers
Error receiving:
SyntaxError: Unexpected identifier

Is that the whole error? It seems like maybe you left out part of it...

1 decade ago by quidmonkey

Your .update() has a misplaced semi-colon on the .getTile() call.

1 decade ago by chadpeppers

It was that and also for some reason copying from safari books online to dreamweaver somehow had an incorrect "-" sign. I deleted and put the minus sign back in and it worked fine.
Page 1 of 1
« first « previous next › last »