I am creating an “underwater diving game” where the backgrounds are set to repeated tileSprite, and players can swim up with key presses.
I managed to make camera follow my player with:
this.cameras.main.startFollow(this.player.sprite);
However, when I try to set bounds for avoiding the display going into “black space”, the outcome is either camera no longer follows the player, or it displays a strange sizing portion between the background and rest of black space.
this.cameras.main.setBounds(0,0, config.width, config.height);
My problem may due to the following misunderstandings:
- my lack of knowledge in setting up the background properly
- not specifying bounds in pixel? (I also don’t know how to convert background size to pixel)
- not understanding the setOrigin() method of backgrounds/sprite
My ultimate goal is to have a long background (width:height = 1:4), and the player can start at any random location within that background while the camera follows the player when it’s swimming up.
Any ideas or suggestions will be appreciated!