Growler Posted July 23, 2018 Share Posted July 23, 2018 @Parasyte @obiot On Melon 5.1, I want to let the player travel/warp around the same map. They click on a place they want to go, and it loads the player to that location. And really, for any NPC entity, I'd want it to be persistent because I alter property values on the entity and don't want them reset. Except as you can see from the video below, it fades to white twice, but also me.game.world.children's length grows by one. It's hard to tell what is being added to me.game.world.children array and why. The PlayerEntity isPersistent flag is true, yet it seems to load the player entity again anyway. PlayerEntity instance: this.isPersistent = true console.log('PLAYER RENDERABLE: ', this.renderable); me.LevelEntity instance: Utilities.Main.setSubwayContent((args) => { game.data.spawnX = args.x; game.data.spawnY = args.y; this.goTo(); }); ... onFadeComplete: function() { game.data.playerEntity.pos.x = game.data.spawnX; game.data.playerEntity.pos.y = game.data.spawnY; } ////////////////////////////////////////////////////////////////////////////// If I use levelDirector instead and set the pos on the entity when the new level loads, it goes haywire (see 2nd video). me.LevelEntity instance: Utilities.Main.setSubwayContent((args) => { game.data.spawnX = args.x; game.data.spawnY = args.y; this.goTo(); }); ... onFadeComplete: function() { me.levelDirector.loadLevel(this.gotolevel); } game.PlayerEntity = me.Entity.extend({ init: function(x, y, settings) { // call the constructor this._super(me.Entity, 'init', [x, y, settings]); if (game.data.spawnX && game.data.spawnY) { this.pos.x = game.data.spawnX; this.pos.y = game.data.spawnY; } Question: what's a safe, easy way to respawn the player elsewhere in the map? Quote Link to comment Share on other sites More sharing options...
Growler Posted July 26, 2018 Author Share Posted July 26, 2018 @Parasyte @obiot any thoughts here? Quote Link to comment Share on other sites More sharing options...
obiot Posted July 26, 2018 Share Posted July 26, 2018 Hi, sorry, I started looking at a small thing earlier this week, and ended being busy tracking down memory allocation in melonJS since the last 2 days, which was really useful at the end I think the issue and therefore the solution is a mix of the following : - persistent object should not be defined in a map, but added manually, else you are indeed adding additional new persistent object when you are changing map. you could still define a transparent non-colliding element in the map as the "spawning point", and retrieve the coordinates of it (together maybe with other parameters) using one of the `me.game.world.getChildXXXX` (as a reminder the root world object in melonJS is a me.Container as well) to manually add the player entity. -> that would be (in my opinion) the safest way to respwan an entity in a map (does not even need to be persistent actually) - the double fading is probably due to the object being indeed persistent and triggering a second time the level change. if I am correct, probably you could just add a flag that is only resetted in the object constructor to avoid changing level again, and do something like the following pseudo-code : `if (triggered == false ) then { triggered = true ; changeLevel() ; }` . let me know if this helps, or if I missed/misunderstood anything. Quote Link to comment Share on other sites More sharing options...
obiot Posted July 26, 2018 Share Posted July 26, 2018 on a side note, your game looks super good, I can't wait to try it ! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.