9 years ago
by Bum
I put a console output in the game.js code whenever spawning entities. If I place the entity in weltmeister, it resolves to 'EntityIntroProp' correctly.
If I try to spawn inside the init() function in the IntroScreen game class it resolves to 'function Class()'. Strangely, the entity's init() function is invoked. For a split second impact.Debug acknowledges the entity before dropping to 0 entities.
I have also tried pushing the entity into the 'this.entities' array. Same result.
Another issue: I want to nest a folder called "intro" in the "lib/game/entities" folder. Following convention, the module name should be "game.entities.intro.foo". I require it with the same module identifier. Impact can't resolve this or it seems I'm doing it incorrectly. (This is not the same issue as including the path in weltmeister.js script. I know how to do that.) Any advice?
9 years ago
by dominic
How exactly do you create the Entity? Can you show some code?
Usually the Game's
.spawnEntity() method should be used. I.e. in your case:
ig.game.spawnEntity(EntityIntroProp, x, y);
The module name
"game.entities.intro.foo"
should correctly resolve to the
lib/game/entities/intro/foo.js
. What's the exact issue? Do you see an error message?
9 years ago
by Bum
In my Game class init() function:
init: function() {
// Load the test room
this.loadLevelDeferred(LevelIntro);
// Clear the screen compltely black
this.clearColor = "#000000";
// init the font
this.font = new ig.Font( 'media/fonts/04b03.font.png' );
// Add the first two props to the intro screen
this.introKidBoy = ig.game.spawnEntity(EntityIntroprop, ig.system.width, ig.system.height/10.0, {propType: "boy"});
this.introKidGirl = ig.game.spawnEntity(EntityIntroprop, ig.system.width+16, ig.system.height/10.0, {propType: "girl", leftLimitAdjust: 16});
},
There were no issues. In game.js, I printed to the console to see what was up.
spawnEntity: function( type, x, y, settings ) {
console.log(type);
...
Entities placed in the level editor would resolve correctly to EntityIntroProp and stay in the game.
Entities spawned via the init() function would resolve to 'function Class()' and be removed from game.
I thought the module path was the culprit which is why I brought it into question. Glad to know I have it right.
9 years ago
by Bum
* They resolve to EntityIntroprop.
The type-case is correct in the code.
9 years ago
by dominic
Well that sounds alright. Doing console.log(type);
at the top of the spawnEntity()
function will log the constructor for that object (function Class()
) - that's exactly what you call the function with and is correct.
spawnEntity()
can also deal with the type name as a string (i.e. spawnEntity("EntityIntroprop",...)
) and that's how entities in the level file are referenced. If you look into the source of your level json you'll the entitys are just referenced as a string of their name.
So, that's not a problem then. There's something else going on, probably in the entity itself, that removes it from the game world instantly.
9 years ago
by Bum
Keep in mind it doesn't remove itself when added via the level editor.
Strange that entities added via the level editor resolve to type "EntityIntroprop" but the ones that were not resolve to editor "function Class()" regardless if that's intended to work. Something is fishy.
9 years ago
by Joncom
Maybe add a console.log
to the entity kill
method.
Or to the game removeEntity
method.
This should let you see when the problematic entity is making its exit.
9 years ago
by drhayes
Can you post the code for the EntityIntroprop
class? Does it have any _wmSettings
in it? Are you using a property named _killed
?
And maybe instead of console.log
, try console.trace
to get a stacktrace of who's calling what?
9 years ago
by Bum
Check this out. If I add the code in the update() function as opposed to the init() function, they spawn. Why is that?
9 years ago
by Joncom
Quote from Bum
In my Game class init() function:
init: function() {
// Load the test room
this.loadLevelDeferred(LevelIntro);
// Clear the screen compltely black
this.clearColor = "#000000";
// init the font
this.font = new ig.Font( 'media/fonts/04b03.font.png' );
// Add the first two props to the intro screen
this.introKidBoy = ig.game.spawnEntity(EntityIntroprop, ig.system.width, ig.system.height/10.0, {propType: "boy"});
this.introKidGirl = ig.game.spawnEntity(EntityIntroprop, ig.system.width+16, ig.system.height/10.0, {propType: "girl", leftLimitAdjust: 16});
},
I&
039;m pretty sure the problem is that you're using #loadLevelDeferred
. This means that your not loading the level right away. But you
are spawning the entities right away. Then soon after, the deferred
loadLevel
occurs, but since
loadLevel
wipes any existing entities, you'll lose the ones you already spawned.
Try replacing
loadLevelDeferred
in your
init
function with
loadLevel
.
9 years ago
by Bum
Thanks for clarity. When would I want to use loadLevelDeferred
over loadLevel
?
9 years ago
by Joncom
From
this thread:
[loadLevelDeferred
] should be used when you want to load a level in the midst of an update() cycle.
Basically, weird things can happen if you load a new level while work is still being done with the current one.
So if you need to load a level after the
init
, either call
loadLevel
at the very start (or very end) of your
update
function, or use the
loadLevelDeferred
function which will simply load the new level at the start of the next frame.
Page 1 of 1
« first
« previous
next ›
last »