Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

102
Views
Nothing showing with PhaserJS

I'm trying to learn phaser js and I'm following the tutorial but when run my code nothing is showing on the web browser. Here is my code:

    <html>

<script type="text/javascript">
var config = {
    type: Phaser.AUTO,
    width: 1280,
    height: 720,
    scene: {
        preload: preload,
        create: create,
        update: update
    }
};

var game = Phaser.Game(config);

function preload ()
{
    this.load.image('player', 'assets/player.png');
    this.load.image('sky', 'assets/sky.png');
}
function create ()
{
    player = this.physics.add.image(640, 360);
    this.add.image(640, 360, 'sky');
    player.setBounce(0.2);
    player.setColliderWorldBounds(true);
}

what am I doing wrong?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

There are some points, that could cause problems(and/or are problematic), and/or should be checked:

  1. your placing the sky ontop of the player. The order in which you add assets / images is important.

  2. player = this.physics.add.image(640, 360) creates a image, with a physics-object, but if you don't pass a key, the image will not be displayed. that line change it to player = this.physics.add.image(640, 360, 'player');

  3. If you don't configure physics the application will crash. (check the browser console for an error message), solution, change the configuration to this:

    var config = {
       type: Phaser.AUTO,
       width: 1280,
       height: 720,
       scene: {
           preload: preload,
           create: create,
           update: update
       },
       physics: {
           default: 'arcade',
           arcade: {
                gravity: { y: 300 }
           }
       },
    };
    

btw.: the official phaser examples, are very helpful and showcase many functions of phaser in a tiny scope https://phaser.io/examples, they helped my to get started with phaser.

p.s.: when developing with html and javascript the browser-console is your best friend / tool, it shows error's and can help with debugging and alot more.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!