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

10 years ago by wytshadow

I want my player to be able to walk in and out of buildings so I'm making the inside of every building a new level. However, when I come back outside of a building, it spawns me at the origin point of the "outside" level which is where the player starts the game.

How do I make the game use the new spawn point when exiting a building instead of using the original spawn point for the beginning of the game?

10 years ago by Joncom

Let's see the code you have so far for warping the player around.

10 years ago by wytshadow

This is how I load the level in my main.js. this is where the character starts the game.

MyGame = ig.Game.extend({
    	init: function() {
        this.loadLevel( LevelLevel_1_2 );

I have a void and a trigger that connect to this levelchange.js script

ig.module(
        'game.entities.levelchange'
)
.requires(
        'impact.entity'
)
.defines(function(){
        
EntityLevelchange = ig.Entity.extend({
        _wmDrawBox: true,
        _wmBoxColor: 'rgba(0, 0, 255, 0.7)',
        _wmScalable: true,
        
        size: {x: 8, y: 8},
        level: null,
        spawn : null, // NAME OF THE VOID FOR THE POS
        
        triggeredBy: function( entity, trigger ) {      
                if(this.level) {
                        
                        var levelName = this.level.replace(/^(Level)?(\w)(\w*)/, function( m, l, a, b ) {
                                return a.toUpperCase() + b;
                        });
                        ig.game.player = ig.game.getEntitiesByType( EntityPlayer )[0];
                        var health = ig.game.player.health;  
                        ig.game.loadLevel( ig.global['Level'+levelName] );
                        if(this.spawn){                      
                                var spawnpoint = ig.game.getEntityByName(this.spawn);
                                if(spawnpoint)                         
                                {
                                        ig.game.spawnEntity(EntityPlayer, spawnpoint.pos.x, spawnpoint.pos.y);
                                        var nrPlayers =ig.game.getEntitiesByType( EntityPlayer ).length;
                                             
                                        ig.game.player = ig.game.getEntitiesByType( EntityPlayer )[0];
                                        /*nrPlayers > 1 ? ig.game.getEntitiesByType(EntityPlayer)[0].kill(): null;*/
                                        console.assert(ig.game.getEntitiesByType(EntityPlayer).length==1);
                                        ig.game.player.health = health;                                                                                                 
                                }                                                             
                        }
                                        
                }
        },
        
        update: function(){}
});

});

Page 1 of 1
« first « previous next › last »