Jump to content

Adding Graphics to Group


ISOmetric
 Share

Recommended Posts

I am looking at this Phaser example, and am simply trying to replace the aliens sprites with simple filled circles drawn by graphics - I've also removed the car, I just want some sprites moving around the area randomly. Unfortunately, the sprites appear with the "no image" graphic. I'm not sure what I am doing wrong here, any help is appreciated:

 

var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create });

  var aliens;
  var sprite;

  function preload() {
    sprite = game.make.graphics(0,0);
    sprite.beginFill(0x00FFFF, 1);
    sprite.boundsPadding = 0;
    sprite.drawCircle(50, 50, 100, 100);
  }
  
  function create() {
    game.physics.startSystem(Phaser.Physics.ARCADE);
    aliens = game.add.group();
    aliens.enableBody = true;
    for (var i = 0; i < 10; i++)
    {
      var s = aliens.create(game.world.randomX, game.world.randomY, sprite);
      s.name = 'alien' + s;
      s.body.collideWorldBounds = true;
      s.body.bounce.setTo(0.8, 0.8);
      s.body.velocity.setTo(10 + Math.random() * 40, 10 + Math.random() * 40);
    }
  }

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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