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 pobble

Hello peeps. I've been putting off buying Impact for quite a while. Lord knows why, now I've taken the plunge, I love it.

So I've started a little something to get into the swing of things and I have a question for y'all ...

I've map a couple of maps and linked them with a teleport entity (works a treat) but rather than spawn a new player entity when a new map is loaded, I'd like to have a "global" player entity that I can just put place in a new map.

Experimented with instantiating a player entity in the main game class but can't figure out how I'd place it in the world.

Any help appreciated
Thank'ee
pobble

1 decade ago by stillen

In you main game file:
player:null,
init: function() {
	    	ig.game.spawnEntity(EntityPlayer,20,20);
                this.player = ig.game.getEntitiesByType( EntityPlayer )[0];


Now within the main.js file you can reference the player by "this.player" and if you want to use him within other files you can reference him by "ig.game.player"

You should always check for the player as well:

if(ig.game.player){
   // do your player magic
}


1 decade ago by pobble

Thanks, stillen

I'll give that a whirl

1 decade ago by pobble

Hmm! Well that sort of worked but I still have a problem. In main.js I declare and assign the player like this ...

code
player: null,

init: function() {
this.loadLevel(LevelTest001);
ig.game.spawnEntity(EntityPlayer, 128, 128);
this.player = ig.game.getEntityByName('player');
}
code

Then in my teleport entity the check event looks like this ...

code
check: function(target) {
if (target === ig.game.player) {
if (this.map) {
ig.game.loadLevelDeferred(ig.global["Level" + this.map]);
}

ig.game.player.pos.x = this.targetX * ig.game.map.tilesize;
ig.game.player.pos.y = this.targetY * ig.game.map.tilesize;
}
},
code

Problem is the player just doesn't appear when the map is changed. I know it still exists after some console.log action. But I'm mystified about where he is!

1 decade ago by stillen

I didn't know you were reloading levels when you teleport your player, I though you had a huge level and were just moving them around the map.

Usually when you load a new level, I believe that all entities are wiped out. You may want to kill your current player just before the unload the level and then respawn him in the new location after the new load level.

1 decade ago by pobble

Thanks, stillen.

I dug through the source this afternoon and found out about the dumping entities bit. Respawning works.

The whole purpose of the exercise was for the player to have persistent attributes, RPG-like. I reckon the solution is to hold the attributes in a separate object or have the spatial entity as part of a super object, containing attributes and the spatial, that gets respawned after each map load.

Thanks for the help
Page 1 of 1
« first « previous next › last »