Jump to content

Uncaught TypeError: player.body.thrust is not a function


Mrityunjai
 Share

Recommended Posts

Hi i keep on getting this error i dont know what the problem is ??

plz help me find it out

index.html

```

<html>
<head>
<script type="text/javascript" src="phaser.min.js"></script><title>Racing Game</title>

</head>
<body>
<script type="text/javascript" src="index.js"></script>
</body>
</html>

```

index.js

```

var game = new Phaser.Game(770,770, Phaser.AUTO);
var racingTrack;
var grass;
var player
var velocity =0;

var mainState = {

    preload:function(){

    game.load.image('background','assets/RacingTrack.png');
    game.load.image('grass','assets/grassMain.png');
    game.load.image('player','assets/car_red_small_3.png');
    },



    create:function() {

        racingTrack = game.add.tileSprite(0,0,770,770,'background');
        game.physics.enable(racingTrack,Phaser.Physics.ARCADE);

    grass = game.add.sprite(254,254,'grass');
        game.physics.enable(grass,Phaser.Physics.ARCADE);


        cursors = game.input.keyboard.createCursorKeys();
        player = game.add.sprite(300,300,'player');
        game.physics.enable(player,Phaser.Physics.p2);



    },


    update:function () {
        if (cursors.left.isDown) {player.body.rotateLeft(100);}   
        else if (cursors.right.isDown){player.body.rotateRight(100);}

        if (cursors.up.isDown){player.body.thrust(400) ;}
        else if (cursors.down.isDown){player.body.reverse(400);}


        }
};

//loading and starting gameState

game.state.add('mainState',mainState);
game.state.start('mainState');
```



`````
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...