Sign in to follow this  

Uncaught TypeError: Cannot set property 'collideWorldBounds' of null

Recommended Posts

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" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<div id="ejemplo"></div>
<script src="phaser.min.js"></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(,, 'ball');

ball.anchor.setTo(0.5, 0.5);

ball.body.collideWorldBounds = true;

ball.body.bounce.setTo(1, 1);

computerBet = createBet(620,;
playerBet = createBet(20,;

computerBet.body.collideWorldBounds = true;

computerBet.body.bounce.setTo(1, 1);

computerBet.body.immovable = true;


function update () {


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;


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!! 

Share this post

Link to post
Share on other sites

By default Phaser.Physics.ARCADE is already started; no need to enable the system. You do however have to explicity enable the body on sprites - however you can create a group with the physics enabled by default on all its objects so you don't need to do this step:

var group =;// This will enable bodies on all sprites added to the group - by default it will be Arcadegroup.enableBody = true;// Both of the following will have bodies enabled straight away via the groupgroup.create(0, 0, 'sprite');game.add.sprite(0, 0, 'sprite', 0, group);

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.