playif / play_phaser

A Dart port for Phaser 2D game engine.
MIT License
72 stars 13 forks source link

Question - Unable to get simple code akin to image loading example working. #25

Closed TheIceMageX50 closed 9 years ago

TheIceMageX50 commented 9 years ago

I am on Win7 running latest Dart version and I have my dart file as below

import 'package:play_phaser/phaser.dart';

class PhaserTest
{
  void main()
  {
    Game game = new Game(800, 600, AUTO, 'output');
    State blah = new MyState();

    game.state.add('state1', blah);
    game.state.start('state1');
  }
}

//Phaser basics_1 example
class MyState extends State
{
  Sprite image;

  preload() {

    //  You can fill the preloader with as many assets as your game requires

    //  Here we are loading an image. The first parameter is the unique
    //  string by which we'll identify the image later in our code.

    //  The second parameter is the URL of the image (relative)
    game.load.image('car', 'bunny.png');

  }

  create() {

    //  This creates a simple sprite that is using our loaded image and
    //  displays it on-screen
    image = game.add.sprite(game.world.centerX, game.world.centerY, 'car');

    //  Moves the image anchor to the middle, so it centers inside the game properly
    image.anchor.set(0.5);

    image.scale.set(2);
  }

  update() {
    image.angle += 1;
  }
}

When I click my index.html to "Run in Dartium" and it loads, there is nothing but a blank tab...I don't understand, have I really done something wrong here or is something broken? :( I mean really, my code is just like your first example. To clarify, bunny.png IS in the web directory of the same project and output is a div in the body of my html.

derrick56007 commented 9 years ago

Your main function won't be called because it is set as a class method

it should be

  void main()
  {
      new PhaserTest();
  }

  class PhaserTest
  {
      PhaserTest()
      {
          Game game = new Game(800, 600, AUTO, 'output');
          State blah = new MyState();

          game.state.add('state1', blah);
          game.state.start('state1');
      }
  }
TheIceMageX50 commented 9 years ago

Oh wow, really? I see, thank you.