javascript - Prevent object from leaving camera bounds -
i'm playing little phaser framework , try make simple "fall down" game. goal fall fast enough without getting pushed out @ top of screen:
to accomplish set canvas size 800x600:
var game = new phaser.game(800, 600, ...);
and resizing world in create()
800x6000:
game.world.resize(800, 6000);
in update()
move camera 1
down:
game.camera.y += 1;
and check if ball still inside camera:
if (!ball.incamera) { // ... }
my question is:
on left , on right world borders limiting moveability of ball (because of ball can't leave camera there). how can prevent ball "falling" out camera on bottom, still able pushed out camera @ top?
is there similar to
game.physics.arcade.checkcollision.down = true;
but camera bounds?
edit
this how ball created:
ball = game.add.sprite(game.world.width / 2, 20, "ball"); game.physics.arcade.enable(ball); ball.body.gravity.y = 1000;
to move ball check key presses , change ball.body.velocity
parameters.
physics has nothing camera (and indeed shouldn't), elegant solution create invisible body, align top bottom camera bound , move camera, still allowing ball moved out of view @ top, not allowing fall down.
Comments
Post a Comment