Jump to content

How to reduce left side of world bounds while increasing the right side


Jorybraun
 Share

Recommended Posts

Hi guys,

so I'm building a endless runner I have my world bounds expanding after my platforms are created. Everything is running fine , it's a bit janky as the background is moving 95% of the camera speed.

 

My issue is that the world bounds is getting very big 50 seconds into play as I am moving the sprite and not the platforms. The platforms are being destroyed as the leave the camera 

 

Is there anyway to reduce the left side of the world bounds while increasing the right side - or is this happening automatically?

function updateWorld() { 
     var road = lastRoad();
     var a = (road.x + (road.width / 2));
     game.world.setBounds(0, 0, a, 500);
    }

function notEnoughRoads() { if (placedRoads < 4) { console.log("not enough roads") nextRoad(); } } function lastRoad() { var i = currentRoads.length - 1; var road = currentRoads; return road; } function lastConstruction() { var i = currentRoadWork.length - 1; var roadWork = currentRoadWork; return roadWork; } // check distance between every road then create an oject function nextRoad() { var gap = game.rnd.between(minRoadGap, maxRoadGap); var previousRoad = lastRoad(); var randomWidth = game.rnd.between(minRoadWidth, maxRoadWidth); var nextRoadPosition = (previousRoad.x + (previousRoad.width / 2)) + gap + (randomWidth / 2); var nextRoadWorkX = (previousRoad.x + (previousRoad.width / 2)) + (gap / 2); addRoadWork(nextRoadWorkX, gap); addRoad(nextRoadPosition, randomWidth); } function addRoad(roadX, width) { road = new Road(game, roadX, 400, width); road.anchor.set(0.5, 0); roadGroup.add(road); currentRoads.push(road); } Road = function(game, x, y, width) { Phaser.Sprite.call(this, game, x, y, "road"); game.physics.enable(this, Phaser.Physics.ARCADE); this.body.immovable = true; this.width = width; } Road.prototype = Object.create(Phaser.Sprite.prototype); Road.prototype.constructor = Road; Road.prototype.update = function() { if (game.camera.x > (this.x + (this.width/2))) { this.destroy(); console.log("destroy") currentRoads.splice(0, 1); } } function addRoadWork(roadx, width) { roadWork = new RoadWork(game, roadx, 400, width); roadWork.anchor.set(0.5, 0); roadWorkGroup.add(roadWork); currentRoadWork.push(roadWork); } RoadWork = function(game, x, y, width) { Phaser.Sprite.call(this, game, x, y, "roadWork"); game.physics.enable(this, Phaser.Physics.ARCADE); this.body.immovable = true; this.width = width; } RoadWork.prototype = Object.create(Phaser.Sprite.prototype); RoadWork.prototype.constructor = RoadWork; RoadWork.prototype.update = function() { if (game.camera.x > (this.x + (this.width/2))) { this.destroy(); currentRoadWork.splice(0, 1); console.log("destroy road work"); console.log(currentRoadWork[0]); } }

 

 
 
 
 
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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