1 decade ago
by dmen
I'm new to Impact and not sure how to go about making a level class. Right now I have test level consisting of four entities. I'm placing them on screen in the init method of the main game.js file. It works fine, but I'd like to make a class 'level1' which creates and places the entities for me - just to keep my code clean.
I see I can use the Class object of Impact, but I don't see how I use the requires section - so not sure how to create an entity.
Hope this is clear enough...
thanks
1 decade ago
by dmen
OK, so I tried to make a level module using the module definition... but it's not working. FYI - not using Weltmeister as it's just not the right tool for the game I'm building....
Here's what I have as a simple test thus far:
ig.module(
'game.levels.level1'
)
.requires(
'impact.game',
'game.entities.l1bgbottom',
'game.entities.l1bgmiddle',
'game.entities.l1bgtop',
'game.entities.l1bgback'
)
.defines(function () {
LevelLevel1 = {
entities: [
{type:"EntityL1BGBack", x:0, y:0, settings:{} },
{type:"EntityL1BGTop", x:0, y:235, settings:{} },
{type:"EntityL1BGMiddle", x:0, y:332, settings:{} },
{type:"EntityL1BGBottom", x:0, y:432, settings:{} }
]
}
});
and then try to load that in Main.js init() method with:
ig.game.loadLevel('Level1');
All i get is a js console error:
Cannot read property 'length' of undefined
Anyone help?
Your object is missing a layer sub-object; loadLevel will break when trying to access it and its length property.
Instead, try this:
ig.module('game.levels.level1')
.requires(
'impact.game',
'game.entities.l1bgbottom',
'game.entities.l1bgmiddle',
'game.entities.l1bgtop',
'game.entities.l1bgback')
.defines(function () {
LevelLevel1=/*JSON[*/{
entities:[
{type:"EntityL1BGBack", x:0, y:0},
{type:"EntityL1BGTop", x:0, y:235},
{type:"EntityL1BGMiddle", x:0, y:332},
{type:"EntityL1BGBottom", x:0, y:432}
],
"layer":[]
}/*]JSON*/;
});
1 decade ago
by dmen
Hey, thanks much! It works without error now, but nothing shows on screen. Now I need to figure out how to spawn the entities.
For entities to be visible, they'll need an animation sheet property, 1 or more anims created with the addAnim Entity method within init, and their currentAnim prop set to one of said anims (automatically done for you when one of your anims is named 'idle', otherwise set manually with this.currentAnim = '<name of initial anim>'.
1 decade ago
by dmen
Thanks again alexandre. I ended up not using a level object, and going the route you suggested in my other thread regarding screens. ie - extending the game class and using ig.system.setGame to swap things out. Seems to work great.
Page 1 of 1
« first
« previous
next ›
last »