Created
          August 5, 2020 21:13 
        
      - 
      
 - 
        
Save photonstorm/dd2aa4eaff2447257f1801a8d7921a2e to your computer and use it in GitHub Desktop.  
    Add body to shape
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | var config = { | |
| type: Phaser.AUTO, | |
| parent: 'phaser-example', | |
| backgroundColor: '#0072bc', | |
| physics: { | |
| default: 'arcade', | |
| arcade: { | |
| debug: true | |
| } | |
| }, | |
| scene: { | |
| create: create, | |
| update: update | |
| } | |
| }; | |
| var cursors; | |
| var player; | |
| var game = new Phaser.Game(config); | |
| function create () | |
| { | |
| player = this.add.rectangle(400, 300, 64, 64, 0xffffff); | |
| this.physics.add.existing(player, false); | |
| cursors = this.input.keyboard.createCursorKeys(); | |
| player.body.setCollideWorldBounds(true); | |
| } | |
| function update () | |
| { | |
| player.body.setVelocity(0); | |
| if (cursors.left.isDown) | |
| { | |
| player.body.setVelocityX(-300); | |
| } | |
| else if (cursors.right.isDown) | |
| { | |
| player.body.setVelocityX(300); | |
| } | |
| if (cursors.up.isDown) | |
| { | |
| player.body.setVelocityY(-300); | |
| } | |
| else if (cursors.down.isDown) | |
| { | |
| player.body.setVelocityY(300); | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment