Impact and Node.js Video #7

Impact, Node, Web Sockets, Javascript, HTML5, Mysql, tons of things in this tutorial
Post Reply
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Impact and Node.js Video #7

Post by hallsofvallhalla »

User avatar
MikeD
Posts: 294
Joined: Thu Sep 08, 2011 4:28 am

Re: Video 7

Post by MikeD »

Awesome, got it up and running, although when one player is moving, it looks really choppy on the other screen, but it is moving in real time with no lag..Weird. Can't wait to see what's next, hopefully AI/Combat! ;)
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: Video 7

Post by hallsofvallhalla »

going to smooth out the multiplayer
User avatar
Chris
Posts: 1580
Joined: Wed Sep 30, 2009 7:22 pm

Re: Video 7

Post by Chris »

Hey, just watched your video and noticed you were on about installing socket.io, there's a project on Google Code that installs node with socket.io and other libraries automatically on windows.

http://code.google.com/p/nodejs-win/
Fighting for peace is declaring war on war. If you want peace be peaceful.
User avatar
Ark
Posts: 427
Joined: Wed Jun 01, 2011 10:25 pm

Re: Video 7

Post by Ark »

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:

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] );
Thanks again for the tutorials!!
Orgullo Catracho
gxxaxx
Posts: 9
Joined: Mon Mar 26, 2012 4:40 am

Re: Video 7

Post by gxxaxx »

Hey Chris looks like the win install project has been taken under the wing of nodejs.org

http://code.google.com/p/nodejs-win/
"This project will now be discontinued! NodeJS for Windows is now fully supported by the official release. Please use the official release found from this site!(http://nodejs.org/) Thank you all for your support!"
Joncom
Posts: 9
Joined: Fri Apr 20, 2012 5:00 am

Re: Video 7

Post by Joncom »

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:

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] );
Thanks again for the tutorials!!
I can also confirm that this happens. Although, since everything appears to work, I'm going to move along. Interesting nonetheless.
patrick.bell
Posts: 19
Joined: Thu May 10, 2012 2:34 am

Re: Video 7

Post by patrick.bell »

Hi there,

I'm currently adopting this method into making another game use node.js and socket.io

although, I'm getting an error in my firebug (firefox) javascript console saying 'gamename: playername,' is not defined. playername is not defined in player.js line xxx

I followed through with assigning the playername using the arrays but no luck getting this to work ;9

Any ideas?
User avatar
Chris
Posts: 1580
Joined: Wed Sep 30, 2009 7:22 pm

Re: Video 7

Post by Chris »

Need to see code before we can be sure.
Fighting for peace is declaring war on war. If you want peace be peaceful.
patrick.bell
Posts: 19
Joined: Thu May 10, 2012 2:34 am

Re: Video 7

Post by patrick.bell »

This is my player.js code... Hopefully its clear...

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
		}
	},
	
});

})
Post Reply

Return to “Impact and Node/Socket.io”