Impact

» Edit Game Info

5 months ago by kortes

Hello there! I just bought impact and working with it has been a blast so far. I'm about to create a multiplayer platformer for the browser.

How can I access properties set on my game.main module from my entities? The easy solution is to use ig.global or window. But is that the right way to do it?

Does entities know anything about the main game object?

Right now I boot my websocket up in my game's init(), and I'm about to emit the creation of the entity in its init() function. But the socket variable is local to the game.main module.

5 months ago by Joncom

Maybe something like this...

// main.js
MyGame = ig.Game.extend({
    ...
    socket null,
    init: function() {
        ...
        this.socket = ... // Create socket connection
    },
    ...
});

// player.js
EntityPlayer = ig.Entity.extend({
    ...
    init: function(x, y, settings) {
        this.parent(x, y, settings);
        ig.game.socket.emit("spawned_player");
        ...
    },
    ...
});
Page 1 of 1
« first « previous next › last »

Post Reply

Please login or register to reply.