Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by ChrisD

Hello all, I'm pretty far into a game project, however, thus far ALL of my logic has been going into the update method. It's getting very cluttered.

How do I create a new method? This is honestly my first time using javascript.

I tried to do the following:
    update: function() {
        ...
    },

    myfunction: function() {
        ...
    },

    draw: function() {
        ...
    }
});
});

but didn't work.

1 decade ago by DavidWeber

Hi

You should try use entities to encapsulate most of your code.
But you can also break up your logic into separate functions like your example.

You just need to call your custom methods in one of the the init / update / draw methods.

update: function() {
        this.myfunction();
},

myfunction: function() {
        ...
},

1 decade ago by ChrisD

Thank you for your response, I am using entities.

I tried what you stated inside of an entity and got the following error:

Uncaught ReferenceError: myfunction is not defined 

Edit: I see what I did wrong! I didn't use this.myfunction.

Thank you :P such a simple mistake.
Page 1 of 1
« first « previous next › last »