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 Joncom

I plan to use a lot of animations in my backgroundMap, and currently I'm accomplishing this using a code generator. What I've been having to do is paste in my generated code into main.js...

Due to the constantly changing code, and not wanting to have these changes be associated with different versions of my main.js, I was wondering if there is a simple way to put this code into an external file.

What would be the best way to do this. WIth an entity seems inappropriate. And to make a plugin just for this seems overkill. Or is it?

// Just some example generated code
var animationSheet0 = new ig.AnimationSheet( 'media/1-16.png', 16, 16 );
this.backgroundAnims = { 'media/master.png': {
787: new ig.Animation( animationSheet0, 0.26667, [1,2,3,4,5,6,7,8] ) ,
1144: new ig.Animation( animationSheet0, 0.26667, [10,11,12,13,14,15,16,17] ) ,
234: new ig.Animation( animationSheet0, 0.26667, [19,20,21,22,23,24,25,26] ) ,
910: new ig.Animation( animationSheet0, 0.26667, [28,29,30,31,32,33,34,35] ) ,
380: new ig.Animation( animationSheet0, 0.26667, [37,38,39,40,41,42,43,44] ) ,
1465: new ig.Animation( animationSheet0, 0.26667, [46,47,48,49,50,51,52,53] ) ,
940: new ig.Animation( animationSheet0, 0.26667, [55,56,57,58,59,60,61,62] ) ,
2073: new ig.Animation( animationSheet0, 0.26667, [64,65,66,67,68,69,70,71] ) ,
944: new ig.Animation( animationSheet0, 0.26667, [73,74,75,76,77,78,79,80] ) ,
441: new ig.Animation( animationSheet0, 0.26667, [82,83,84,85,86,87,88,89] ) ,
2153: new ig.Animation( animationSheet0, 0.26667, [91,92,93,94,95,96,97,98] ) ,
732: new ig.Animation( animationSheet0, 0.26667, [100,101,102,103,104,105,106,107] ) ,
2337: new ig.Animation( animationSheet0, 0.26667, [109,110,111,112,113,114,115,116] ) ,
487: new ig.Animation( animationSheet0, 0.26667, [118,119,120,121,122,123,124,125] ) ,
2539: new ig.Animation( animationSheet0, 0.26667, [127,128,129,130,131,132,133,134] ) ,
1254: new ig.Animation( animationSheet0, 0.26667, [136,137,138,139,140,141,142,143] ) ,
821: new ig.Animation( animationSheet0, 0.26667, [145,146,147,148,149,150,151,152] ) ,
421: new ig.Animation( animationSheet0, 0.26667, [154,155,156,157,158,159,160,161] ) ,
2424: new ig.Animation( animationSheet0, 0.26667, [163,164,165,166,167,168,169,170] ) ,
860: new ig.Animation( animationSheet0, 0.26667, [172,173,174,175,176,177,178,179] ) ,
750: new ig.Animation( animationSheet0, 0.26667, [181,182,183,184,185,186,187,188] ) ,
2435: new ig.Animation( animationSheet0, 0.26667, [190,191,192,193,194,195,196,197] ) ,
1121: new ig.Animation( animationSheet0, 0.26667, [199,200,201,202,203,204,205,206] ) ,
2388: new ig.Animation( animationSheet0, 0.26667, [208,209,210,211,212,213,214,215] ) ,
2144: new ig.Animation( animationSheet0, 0.26667, [217,218,219,220,221,222,223,224] ) ,
418: new ig.Animation( animationSheet0, 0.26667, [226,227,228,229,230,231,232,233] ) ,
1388: new ig.Animation( animationSheet0, 0.26667, [235,236,237,238,239,240,241,242] ) } }; 	

1 decade ago by Datamosh

Create game/myfile.js

ig.module('game.myfile')
.requires(
	'impact.game'
)
.defines(function() {
	myfunction = function() {
		// Code
	}
})

Remembed add in main.js require: 'game.myfile'
and call myfunction() when you want.

1 decade ago by Joncom

I'll give that a shot, thank you!

EDIT Worked perfectly - cheers :)

1 decade ago by Joncom

Just a quick follow up question:

My code doesn't actually need to inherit anything from ig.game, so do I actually need this part?

.requires(
    'impact.game'
)

EDIT I suppose I should have tested it before asking. So I went ahead and tried replacing the line above with this:

.requires()

And it works just fine.
Page 1 of 1
« first « previous next › last »