Hi,
I'm new to impact and the reason I got a license is, that I want to create a multiplayer game with impact and node.js.
Ape, your plugins is a great basis to start with, but unfortunately your plugin is hiding the socket.io callbacks from impact.
For instance, when the socket is established the player should join the game automatically. In your example you'r checking if the socket is connected, as well as for the existence of the player entity on every update call. I don't think that's necessary. Using event callbacks it's much prettier IMO.
Hence I've extended your plugin to pass the basic socket.io events back to the game, similar to the way jQuery attaches event callbacks.
Basically what I've done is adding an on() method.
For instance:
this.impsock = new ig.Impsock(this);
this.impsock.on('disconnect',function() { alert('disconnect form server');});
This way you can subscribe to the events connect, disconnect and message. Unfortunately subscribing to the connect event AFTER instantiating the impsocket class is pointless, since the establishSocket() function is called right away inside the init call.
So I've added an optional parameter to the constructor for passing events on instantiation.
for instance:
this.impsock = new ig.Impsock(this,{'connect':CreateDelegate(this,this.joinGame)});
This way you can pass ANY event callback directly to the object. Unfortunately, the callback will loose the current context. Therefore I've added the createDelegate() function, which looks like this:
function CreateDelegate(contextObject, delegateMethod){
return function() {
return delegateMethod.apply(contextObject, arguments);
}
}
To cut a long story short.... thanks for creating the impsocket plugin. It's a great basis to build upon and I hope you might consider applying my changes to your plugin.
You can get the sourcecode here:
tweaked impsock
I just hacked the event callbacks into your plugin a few minutes ago and haven't deployed it to a real project yet, since I've just started using impact yesterday. There probably room for improvements ;)
Have a nice and sunny sunday :)
Steffen