Jump to content

Help on something probably quite simple


Heppell08
 Share

Recommended Posts

Its my cutscene then back to game idea.

I have my levels created in a certain way and in cutscene i have it change a varibale in game so that the next level begins.

 

The issue:

 

I'm leaving the game state then re-entering it after the cutscene - hence the variable change.

 

My maps are destroying a single variable 'layer' then re-creating back on the same variable layer. So each map is just 

var layer 

and not layer1, layer 2 etc etc.

 

So when im creating i'm destroying and re-creating in that order so as to work well. My problem is i have the cutscene telling the game that i want to load a specific level: eg level 6.

Now my maths uses 0.5 rules so that the game doesn't reload the map constantly (making a huge memory leak and lag problem) or confuse itself with the numbers needed. So i have it set that when i load the level i take 0.5 away from the level variable. It will load the map and then at the end add back to the level variable to stop and wait for next use.

The main issue:

When the cutscene ends and i go back into the game it is trying to fire the function i need to create a map. It wants to destroy layers. The level variable is 6.5 so it should take the 0.5 off, equal 6, load the map, then add up to 7.5 at the end but its erroring me on a higher tier of the function for level 2 to destroy that layer when there is no layer because it was destroyed long ago as the player progressed.

So i make a fake layer? or is there some other option around this?

Link to comment
Share on other sites

I'm sorry but I could not understand the problem, could you please paste your code? Maybe it will be easier to help you that way. Maybe it's the level counter logic that is overwriting its value?

Link to comment
Share on other sites

Its the level creation after leaving and entering a state. Game.js is told that the level variable equals 6.5. then i remove 0.5 to make it equal to 6 then it should load level 6. EG:

createMap: function()            {                            level -= 0.5;                        if(level === 1)            {                if(level > 1)                {                    layer.destroy();                }                map = this.add.tilemap('level01');                map.addTilesetImage('Space', 'tiles');                 layer = map.createLayer('Space');                layer.resizeWorld();                currentLevelX = 60;                currentLevelY = 480;                level = 2.5            }            if(level === 2)            {                layer.destroy();                map = this.add.tilemap('level02');                map.addTilesetImage('Space02', 'tiles');                layer = map.createLayer('Space02');                layer.resizeWorld();                currentLevelX = 61;                currentLevelY = 391;                level = 3.5;            }

That is the first 2 levels and when i start thegame it works fine. what the issue is, the game isnt looking at the level variable on return from the cutscene and not loading from the next number in the function when fired.

Link to comment
Share on other sites

So i've made some progress and have figured something out. The level, layer and map variables are not being referenced inside the function. They are global but for some reason are not being touched or used. I have the function firing because console is telling me that but its not even looking at the level number variable...

 

Heres the function...

createMap: function()            {                console.log('Worked!');                            level -= 0.5;                        if(level === 1)            {                map = this.add.tilemap('level01');                map.addTilesetImage('Space', 'tiles');                 layer = map.createLayer('Space');                layer.resizeWorld();                currentLevelX = 60;                currentLevelY = 480;                level = 2.5            }            if(level === 2)            {                map = this.add.tilemap('level02');                map.addTilesetImage('Space02', 'tiles');                layer = map.createLayer('Space02');                layer.resizeWorld();                currentLevelX = 61;                currentLevelY = 391;                level = 3.5;            }            if(level === 3)            {                console.log('Level3!!');                map = this.add.tilemap('level03');                map.addTilesetImage('Space03', 'tiles');                layer = map.createLayer('Space03');                layer.resizeWorld();                currentLevelX = 130;                currentLevelY = 710;                level = 4.5;            }            if(level === 4)            {                map = this.add.tilemap('level04');                map.addTilesetImage('Space04', 'tiles');                layer = map.createLayer('Space04');                layer.resizeWorld();                currentLevelX = 150;                currentLevelY = 450                level = 5.5;            }            if(level === 5)            {                map = this.add.tilemap('level05');                map.addTilesetImage('Space05', 'tiles');                layer = map.createLayer('Space05');                layer.resizeWorld();                level = 6.5;                currentLevelX= 125;                currentLevelY = 3603;            }            if(level === 6)            {                game.state.start('Cutscene1');                    level = 6.5;            }            map.setCollisionBetween(211, 217); // Main Floor        map.setCollisionBetween(246, 252); // stops glitching        map.setCollisionBetween(71,72);        map.setCollisionBetween(106,107); // blue lit box        map.setCollisionBetween(141,142);        map.setCollisionBetween(176, 177); // unlit box        map.setCollision(143); // small box        map.setCollisionBetween(178, 179); // 2 small boxes                 map.setCollisionBetween(146, 148); // black and yellow area        map.setCollisionBetween(334, 336); // black and yellow area        map.setCollisionBetween(369, 372); // black and yellow area        map.setCollisionBetween(181, 182); // black and yellow area        map.setCollision(301);        map.setCollision(299);     //   map.setTileIndexCallback([146,147], tileFunc1.emitBlock, this);        map.setTileIndexCallback(179, tileFunc2.gravSwitch, this);        map.setTileIndexCallback(143, tileFunc3.switchGrav, this);        map.setTileIndexCallback([168,2], tileFunc4.playerReset, this);        map.setTileIndexCallback(69, tileFunc5.mapChange, this);        if (this.game.device.iOS || this.game.device.android)        {            jButton.bringToTop();        }               },
Link to comment
Share on other sites

So i found the issue but i have no idea why its doing what it is doing...

The level variable is not being touched in the slightest. The map and layer are but not the level number.... Even in the game.js within the function for creating the map its classing it as something totally new...

Link to comment
Share on other sites

Eventually i got it. Was a bit confusing but got there in the end, I placed the global in boot so it was forgot about and i could work on the numbers. In cutscene when i was calling to go back into game i had the number reduction after the call into the state meaning the whole game.js was called before the minus 0.5 from cutscene so it was technically going backwards. I rearranged the calls and numbers and got it all up and running. Sorry if i confused anyone lol :)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...