Search the Community
Showing results for tags 'boundaries'.
-
Hi everyone! I'm looking to have sprites generated randomly within another sprite's bounds. I've seen examples of bounds used within sprites, like so for example (from this Phaser example): // Our sprite that will act as the drag bounds bounds = game.add.sprite(game.world.centerX, game.world.centerY, 'pic'); // And the sprite we'll drag sprite = game.add.sprite(300, 300, 'atari'); sprite.inputEnabled = true; sprite.input.enableDrag(); sprite.input.boundsSprite = bounds; However, I haven't seen this applied on a group of random sprites? And when I try this method on my group, it doesn't seem to work. Here is my code so far... I'm attempting to have the stars sprites randomly created within the room's image bounds. var game = new Phaser.Game(window.innerWidth, window.innerHeight, Phaser.AUTO, '', { preload: preload, create: create, update: update }); function preload() { game.load.image('star', 'assets/images/star.png'); game.load.image('room', 'assets/images/room.png'); } function create() { //*** The image I'd like to use for bounds room = game.add.image(210, 232, 'room') // Create random Star group starGroup = game.add.group(); // And add 3 sprites to it //** I'd like to have these sprites generated within the room's bounds only for (var i = 0; i < 3; i++) { starGroup.create(game.world.randomX, game.world.randomY, 'star'); } } Any help? Thanks!
-
Hello guys, i'm totally new to Babylon and I was wondering if there's a way to check if an object is hitting the border of the screen and prevent it to get off the screen. This is what i wrote so far: http://www.babylonjs-playground.com/#SKWZP#0 I found these values manually, i hate to hard-code stuff inside my code but it was just for testing. if (box1.position.x > 6 ) { box1.position.x = 6; } if (box1.position.y > 4 ) { box1.position.y = 4; } if (box1.position.x < -6) { box1.position.x = -6; } if (box1.position.y < -4) { box1.position.y = -4; } Can you please me help to understand how can i retrieve the screen boundaries wrt the viewport?
- 1 reply
-
- viewport
- boundaries
-
(and 2 more)
Tagged with: