Search the Community
Showing results for tags 'collideWorldBounds'.
-
Hi, I'm learning to make games Phaser, watching a tutorial to create the Pong. For starters, I have to draw all elements in screen, which are ball and two rackets. Failure to draw the ball, the ball is only draws and no draws snowshoes. The code is as follows <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Pong</title> </head> <body> <div id="ejemplo"></div> <script src="phaser.min.js"></script> <script> window.onload = function(){ var game = new Phaser.Game(640, 480, Phaser.CANVAS, 'ejemplo', { preload: preload, create: create, update: update }); var playerBet; var computerBet; var ball; var computerBetSpeed = 190; var ballSpeed = 300; function preload() { game.load.image('bet', 'assets/rocket.png'); game.load.image('ball', 'assets/ball.png'); game.load.image('background', 'assets/backg.png'); } function create() { game.add.tileSprite(0, 0, 640, 480, 'background'); ball = game.add.sprite(game.world.centerX, game.world.centerY, 'ball'); ball.anchor.setTo(0.5, 0.5); ball.body.collideWorldBounds = true; ball.body.bounce.setTo(1, 1); computerBet = createBet(620, game.world.centerY); playerBet = createBet(20, game.world.centerY); computerBet.body.collideWorldBounds = true; computerBet.body.bounce.setTo(1, 1); computerBet.body.immovable = true; } function update () { } //Funciones function createBet(x, y) { var bet = game.add.sprite(x, y, 'bet'); bet.anchor.setTo(0.5, 0.5); bet.body.collideWorldBounds = true; bet.body.bounce.setTo(1, 1); bet.body.immovable = true; return bet; } }; </script> </body> </html> and failure I get is: Uncaught TypeError: Can not set property 'collideWorldBounds' of null In line 39, that is: ball.body.collideWorldBounds = true; Help me please!!
- 6 replies
-
- collideWorldBounds
- null
-
(and 1 more)
Tagged with:
-
Hi all, I can't seem to find any documented way of initialising a sprite with a negative axis value, whilst having collideWorldBounds enabled. It appears to be resetting my negative axis values to 0 upon rendering, which makes it appear really clunky. app.game.prototype.spawn = function() { var germId = germs[Math.floor(Math.random()*germs.length)], germ = spawnGroup.create( this.rnd.integerInRange(0, this.world.width), -50, germId ); this.physics.arcade.enable(germ); germ.body.gravity.y = this.rnd.integerInRange(200, 500); germ.body.collideWorldBounds = true; germ.inputEnabled = true; germ.events.onInputDown.add(this.onInputDown, this); }; Any suggestions on how to get around this?
-
I'm using Phaser 2.4.2 with P2 physics. I have a sort of jar shaped body containing some circular bodies (balls). I want to move the jar offscreen but the balls are colliding with the world bounds. I tried setting collideWorldBounds on the balls but this stops them colliding with the jar which I want. You can see a demo here: https://output.jsbin.com/vuyexo Click the red button to make the jar move. Uncomment `collideWorldBounds=false` in the 'balls' section to see my problem. Why is this happening and how can I make the balls collide with the jar body but not the world bounds when the jar is moved offscreen?