Impact and Node.js Video #7
Posted: Fri Mar 16, 2012 12:32 am
Code: Select all
this.addAnim( 'up', .21, [9,10,11,10] ); //arregle unos anims
this.addAnim( 'down', .21, [0,1,2,1] );
this.addAnim( 'left', .21, [3,4,5,4] );
this.addAnim( 'right', .21, [6,7,8,7] );
I can also confirm that this happens. Although, since everything appears to work, I'm going to move along. Interesting nonetheless.Ark wrote:Hey halls really nice job on the tutorials!
Just wanted to know why do I always get this error on chrome console:
Uncaught TypeError: Cannot call method 'getEntitiesByType' of null index.html: 47
(repeated 4 times)
It only happens to the console of the second player that joins, not the first one. Of course everything seems to work fine, but maybe this could affect impact.
Oh and after testings found a better way for the player to animate more smoothly while moving:Thanks again for the tutorials!!Code: Select all
this.addAnim( 'up', .21, [9,10,11,10] ); //arregle unos anims this.addAnim( 'down', .21, [0,1,2,1] ); this.addAnim( 'left', .21, [3,4,5,4] ); this.addAnim( 'right', .21, [6,7,8,7] );
Code: Select all
ig.module(
'game.entities.player'
)
.requires(
'impact.entity'
)
.defines(function(){
var ismove = 0;
var speed = 100;
EntityPlayer = ig.Entity.extend({
type: ig.Entity.TYPE.A,
animSheet: new ig.AnimationSheet( 'media/paddle-blue.png', 64, 128 ),
checkAgainst: ig.Entity.TYPE.NONE,
size: {x:64, y:128},
nettimer: 10,
name: "player",
gamename: playername,
collides: ig.Entity.COLLIDES.FIXED,
messagebox: "",
messageboxtimer: 200,
speed: 100,
init: function( x, y, settings ) {
this.parent( x, y, settings );
this.addAnim( 'idle', 1, [0] );
socket.emit('initializeplayer', this.gamename);
},
//directional movement UP and DOWN
update: function() {
if( ig.input.state('up') ) {
this.vel.y = -this.speed;
//this.messagebox = this.messagebox + "you pressed up \n";
}
else if( ig.input.state('down') ) {
this.vel.y = +this.speed;
//this.messagebox = this.messagebox + "you pressed down \n";
}
else {
this.vel.y = 0
}
if(this.nettimer < 1)
{
this.nettimer = 5;
socket.emit('recievedata', this.pos.y, this.gamename);
}
this.nettimer = this.nettimer -1;
this.parent();
}
});
///other players
EntityOtherplayer = ig.Entity.extend({
size: {x:64, y:128},
type: ig.Entity.TYPE.B,
speed: 100,
name: "otherplayer",
gamename: "",
collides: eg.Entity.COLLIDES.FIXED,
animSheet: new ig.AnimationSheet( 'media/paddle-red.png', 64, 128 ),
init: function( x, y, settings ) {
this.parent( x, y, settings );
this.addAnim( 'idle', 1, [0] );
},
netmoveplayer: function()
{
this.pos.y = positiony;
},
update: function() {
if( ig.input.state('up') ) {
this.vel.y = -this.speed;
this.messagebox = this.messagebox + "you pressed up \n";
}
else if( ig.input.state('down') ) {
this.vel.y = +this.speed;
this.messagebox = this.messagebox + "you pressed down \n";
}
else {
this.vel.y = 0
}
},
});
})