Sign in to follow this  

Uncaught TypeError: Cannot read property 'x' of undefined

Recommended Posts

The previous time I worked on this project it would load no problem within the browser, now I get the error Uncaught TypeError: Cannot read property 'x' of undefined and it says it's coming from phaser.min.js:24 which isn't making sense to me.

var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });

function preload() {'tilemap', 'assets/tilemaps/csv/tiles.csv', null, Phaser.Tilemap.CSV);'tiles', 'assets/tilemaps/tiles/snow_tiles_32.png', 32,32);'player', 'assets/penguin.png', 32,48);

var cursors;
//var snowballs;
//var sTime = 0;
//var fireButton;

function create() {;;
    cursors = game.input.keyboard.createCursorKeys(); ='tilemap');'snow_tiles_32', 'tiles'); = '#80e3ff';

    this.ground =;
        1:  'FULL',
        2:  'FULL',
        3:  'FULL',
        4:  'FULL',
        5:  'FULL',
        6:  'FULL',
        7:  'FULL',
        8:  'FULL',
        9:  'HALF_TOP',
        10: 'FULL',
        12: 'FULL',
        13: 'HALF_BOTTOM_LEFT',
        14: 'HALF_BOTTOM_RIGHT',
        15: 'HALF_BOTTOM_LEFT',

    });, 34, true, 0);

    this.player =, 50, 'player');;
    this.player.body.slopes = {sat: {response: 0}}; // workaround for a phaser bug;
    this.player.body.slopes.preferY = true; // stops the player sliding down slopes

    this.player.body.bounce.y = 0.2;
    this.player.body.gravity.y = 700;
    this.player.body.collideWorldBounds = true;

    this.player.animations.add('left', [0,1,2,3], 10, true);
    this.player.animations.add('right', [5,6,7,8], 10, true);

    //this.snowballs =;
    //this.snowballs.enableBody = true;
    //this.snowballs.physicsBodyType = Phaser.Physics.ARCADE;
    //this.snowballs.createMultiple(1, 'snowball');
    //this.snowballs.setAll('anchor.x', 0.5);
    //this.snowballs.setAll('anchor.y', 1);
    //this.snowballs.setAll('outOfBoundsKill', true);
    //this.snowballs.setAll('checkWorldBounds', true);

    //this.fireButton = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);;;

function update() {, this.ground);

    this.player.body.velocity.x = 0;

        this.player.body.velocity.x = -150;'left');
    else if (cursors.right.isDown){
        this.player.body.velocity.x = 150;'right');
        this.player.frame = 4;

    if(cursors.up.isDown && (this.player.body.onFloor() || this.player.body.touching.down)){
        this.player.body.velocity.y = -350;


//function fireSnowball(){
    //if( > sTime){
    //this.snowball = snowballs.getFirstExists(false);
    // this.snowball.reset(player.x+30, player.y+30);
    //this.snowball.body.velocity.x = 400;
    //this.sTime = = 10;
    // }


Test Game Phaser2.rar

Share this post

Link to post
Share on other sites

I don't see anything obviously wrong at first glance, but here are two tips:

- Try to inspect all the objects of which you try to access the property 'x'; apparently one of these objects is undefined.
- For development purposes, it's usually better to use the non-minified version of a library, so that the error messages point to meaningful lines of code (as you say, with a minified file, line 24 doesn't mean much).

Hopefully this will help you track down the issue.

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.