Begins explaining my achieve: as I said in my last question, I am tryna makin' a 2D game with 3D player as Factorium. For hours I am tryna to make a kinda of bounding system:
1)Camera will follow player untill the left border of the screen will reach the left edge of the map
2)If left edge has been reached, only player keep walking towards left
3)Once player come back, camera will follow player again only when it will have reached the right distance
First image: left edge of the map still not reached, so camera keep following player constraints it at its center.
Second image: camera reached it, but layer kept waling, then begins come back
Thirds image: distance between player and left edge is at lest as half camera viewport, so camera begins follow player again.
Of course, I tried something...
/**
* Using tile map proeprties
* @param translateCords how much player has to be moved
* @return if the player can me moved<br> e.g. if the camera will not be over the map's edge
* after have been moved
*/
private boolean canPlayerMove(Vector3 translateCords) {
Vector3 playerPos = this.entityPlayer.getPosition();
Vector3 futurePos = playerPos.add(translateCords.x, translateCords.y, 0);
TiledMapTileLayer.Cell cell = ((TiledMapTileLayer)this.tiledMap.getLayers().get(0)).getCell((int)futurePos.x, (int)futurePos.y);
return cell.getTile().getProperties().containsKey("blocked");
}
This for move camera
/**
* @param translateCords how much camera has to be moved
* @param camPos current camera position
* @return if the camera can me moved<br> e.g. if the camera will not be over the map's edge
* after have been moved
*/
private boolean canCameraMove(Vector2 translateCords, Vector3 camPos){
if( (translateCords.x < 0 && camPos.x - this.viewportWCam >= 0) ||
(translateCords.x > 0 && camPos.x + this.viewportWCam <= this.widthWorld) ||
(translateCords.y < 0 && camPos.y - this.viewportHCam >= 0) ||
(translateCords.y > 0 && camPos.y + this.viewportHCam <= this.heightWorld)) {
return true;
}
return false;
}
I tried a lots of other stuff...