I am not using Weistmeister to place my EntityPlayer on the map. Instead, I am spawning my player programatically when the main.js loads via a ig.game.spawnEntity() call. This works fine with the level that the game starts on.
However, if I load a new level with loadLevelDeferred() call, no EntityPlayer is on the map. I need to spawn the EntityPlayer again on the new map after it has loaded -- how can I do this programatically without Weistmeister? Thank you.
1 decade ago
by TommyBs
After you've made your call to loadLevel call the ig.game.spawnEntity method passing in an instance of your player and the x,y pos. Or am I missing something here? Do you have some code you can share
ig.game.loadLevel(myLevel);
ig.game.spawnEntity(EntityPlayer,0,0);
Hi, in my main.js, I have overridden loadLevel as such:
loadLevel: function( data ) {
// Call the original implementation. This loads the level
this.parent( data );
// Do your own processing here...
this.spawnEntity( EntityPlayer, 100, 50 );
}
I think that it might be the EntityLevelexit class that I wrote that is weird. I wrote an EntityLevelexit class that I placed into Weistmeister to check when a EntityPlayer collided with it and then call the loadLevelDeferred().
This is part of the code below (I am using Impact++ as well):
.defines(function(){
"use strict";
var _c = ig.CONFIG;
var _ut = ig.utils;
ig.EntityLevelexit = ig.global.EntityLevelexit = ig.EntityLevelchange.extend({
size: {x: 8, y: 8},
check: function( entity ) {
if(entity instanceof EntityPlayer){
if( this.level ) {
console.log("level change");
var levelName = this.level.replace(/^(Level)?(\w)(\w*)/, function( m, l, a, b ) {
return a.toUpperCase() + b;
});
ig.game.loadLevelDeferred( ig.global['LevelTest2'] );
currentLevel = "LevelTest2";
}
else{
console.log("level not defined");
}
}
}
});
});
Oops, sorry, I didnt format the code :(
But basically after putting in some console.log calls, I can see the loadLevel callback in the main.js and the EntityLevelexit check being called infinitely in a loop...
Page 1 of 1
« first
« previous
next ›
last »