Page 1 of 1

Multiplayer dynamic character texture and infos

PostPosted: Wed Jan 07, 2015 11:29 am
by Laurent
Hi,

I bought the personnal licence in order to developp an isometric multiplayer tchat for one of my websites.
My problem is that each character has it own texture, and that texture should be dynamically loaded.

I start from the example 24.5.

I tried sending arguments(characterTextureImage) with entitycreate :
Code: Select all
// client.js file
// Ask the server to create an entity for us
ige.network.send('playerEntity',characterTextureImage);


It works fine on serverside and I can get my characterTextureImage argument in the init method of characterContainer and Character.

But on the client side, when trying to apply the texture for other characters, I can't find the characterTextureImage.
Code: Select all
// CharacterContainer.js
if (!ige.isServer) {
         ../..
   
         // Create a character entity as a child of this container
         self.character = new Character()
            .../..
      }


Thanks for your help ;)

Re: Multiplayer dynamic character texture

PostPosted: Wed Jan 07, 2015 8:14 pm
by TheBenji
You'd probably need to send the filename/path from the image to the client and then the client needs to load the texture on it's own from this path and you can apply it as usual.

I could be wrong though...

Re: Multiplayer dynamic character texture

PostPosted: Wed Jan 07, 2015 10:04 pm
by Laurent
I agree with you, but I can't fidn the way to send the image path from the server to the client :cry:

Re: Multiplayer dynamic character texture and infos

PostPosted: Sat Jan 10, 2015 7:17 pm
by Laurent
I just need to send parameters (as texture url, playername, playerscode) to display them on every player screen...
Help please :|

Re: Multiplayer dynamic character texture and infos

PostPosted: Tue Feb 17, 2015 9:36 pm
by robaldred
Hey Laurent, sorry for the delay. I wanted to reply here instead of via private message so others can benefit from the discussion.
What you're asking is quite simple if you know how :)

What you need to do is pass around instantiation variables. You do this by defining the streamCreateData method on your entity this method must return your instantiation object.

This can be seen in action in example 24.1-network-stream, the speed of the rotators is passed over the network to all the clients.
Let me illustrate with little snippet.

Character.js
Code: Select all
var Character = IgeEntity.extend({
    init: function (texturename) {
        this._texturename = texturename;

        var self = this;
   
        if(ige.isClient) {
            this._tex = new IgeTexture('assets/textures/sprites/' + this._texturename);
            this._tex.on('loaded', function () {
                self.texture(self._tex);
            });
           
        }
       
    },

    streamCreateData: function() {
        return this._texturename;
    }
});



On your server you'd create a character by calling:
Code: Select all
char = new Character('texture.png')
    .streamMode(1)
    .mount(this.mainScene);


This it, the stream will take care of creating your Character entities on the clients and passing the texture to it.
The down side is the streamCreateData can only handle strings when using NetIO, so if you wanted to send more than one property you'd need to send it say as a comma separated string and then re-assemble it in your init method.

Something like:

Code: Select all
//server
new Character('texture.png,playername,playercode');

//character.js
init: function(args) {
   this._args = args.split(',');
   this._texturename = this._args[0];
   this._playername = this._args[1];
   this._playercode = this._args[2];

   //.... other init stuff
},
streamCreateData: function() {
   return this._texturename + ',' + this._playername + ',' + this._playercode;
}


I hope this gives you what you need, let me know how you get on.

Re: Multiplayer dynamic character texture and infos

PostPosted: Mon Mar 09, 2015 3:10 pm
by Laurent
Thanks a lot Rob,

It works fine :)

Re: Multiplayer dynamic character texture and infos

PostPosted: Mon Mar 09, 2015 3:15 pm
by robaldred
Excellent, looking forward to see what you've been building.