Correct the map position to the center of the screen

 

//Game layer

this.panelGame

{

let maxX = -10000;

let minX = 10000;

//Traverse the X coordinate of the elements in the map

for(let i in roadVt){

let road = roadVt[i]

maxX = Math.max(maxX, road.x + road.width*road.anchorX)

minX = Math.min(minX, road.x - road.width*road.anchorX)

}

this.setGamePanelCenter(maxX,minX)

}

 

//Incoming objects in the game, the X coordinates of the rightmost and leftmost

 setGamePanelCenter(maxX,minX){

        this.panelGame.x = - (maxX*this.panelGame.scaleX + minX*this.panelGame.scaleX)/2;

    }

Guess you like

Origin blog.csdn.net/qq_17148595/article/details/115002301