1 decade ago
by 80bit
Maybe im going about this the wrong way, but basically I want to spawn my player using code after I've loaded the level. The reasoning for this is just because I've got various spawn points depending on where the character is actually 'coming from' so if they come through a certain door they will spawn in that particular spot.
Is there any reason why this wouldnt work in my levelchange.js entity? Could very well be that I have no clue what I'm doing. :)
ig.game.loadLevelDeferred( ig.global['Level'+levelName] );
ig.game.spawnEntity( EntityPlayer, 124, 50, {flip:1} );
Level loads fine, but it doesnt load the player.. as always, any help is infinitely appreciated!
1 decade ago
by dominic
What your code does, is setting a flag for the game, to load the new level when the update loop is completely through (that's the
deferred part). After it sets this flag, it spawns your Player entity, finishes the rest of the update loop and finally loads the new level - clearing all entities that are currently present, including the Player you just spawned.
To spawn an entity immediately after a level was loaded, overwrite the Game&
039;s #loadLevel()
method:
loadLevel: function( data ) {
this.parent( data );
this.spawnEntity( EntityPlayer, 124, 50, {flip:1} );
}
1 decade ago
by 80bit
Hmm Pierre was just talking to you on the forums about this and using a Spawn entity to determine where the player is spawned. I was using the this.spawnEntity as you explained but i couldnt how to get specific values passed depending on which level was loading.
Thanks for your help i am going to work on the spawn point entity method and see what I can come up with. Youre the man, Dom.
1 decade ago
by ansimuz
80bit,
How did you solved this? i have the same issue i want to spawn my player on different locations depending from where it came from (which door ) .
I am using a void entity to set the spawn point but with no luck.
Let me know
1 decade ago
by drhayes
I have an entity called EntityCheckpoint. In its
check
method, it sees if it&
039;s touching the EntityPlayer. If it is, it calls #ig.game.checkpointPlayer(this);
, a method I added to my base game class.
checkpointPlayer
sets
this.currentCheckpoint
. Simple enough.
There is another method on the game class called
playerHasDied
. Whenver the player dies, whatever killed the player calls
ig.game.playerHasDied
. It uses an (shameless plug)
event chain to time the respawn; after waiting a bit, it calls
this.spawnPlayer
(another method I added).
spawnPlayer
uses the position of the
currentCheckpoint
to
ig.game.spawnEntity
another EntityPlayer.
The reason I&
039;m laying all of this out is because level entrances are *also* checkpoints. I don't place the EntityPlayer directly into the level in Weltmeister, I have EntityPlayerSpawn for that. It sets itself as the current checkpoint in its #ready
method by calling
ig.game.checkpointPlayer
.
There&
039;s another entity called EntityLevelPortal that knows to load a new level if the player invokes it. Each level portal also has a name. Before it calls #ig.game.loadLevelDeferred
, it sets what the name of the exit portal in the next level will be (set through Weltmeister to connect levels).
Guess what the portal does? It checkpoints the player.
Make sense?
Page 1 of 1
« first
« previous
next ›
last »