ISOmetric

Adding Graphics to Group

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);
    }
  }

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.