phaserjs / phaser

Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
https://phaser.io
MIT License
36.75k stars 7.07k forks source link

Graphic child x/y #1849

Closed ForgeableSum closed 9 years ago

ForgeableSum commented 9 years ago

When you add a child (e.g. image) to a graphic, the child will always display in the game world top left x/y. Even after you set the x/y of the child.

photonstorm commented 9 years ago

Looks good to me (see below, assets can be found in the examples repo). Need a full code example that demonstrates this please:

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

function preload() {

    game.load.image('atari', 'assets/demoscene/atari.png');

}

function create() {

    var graphics = game.add.graphics(260, 260);

    graphics.beginFill(0x027a71);
    graphics.lineStyle(4, 0x02fdeb, 1);

    graphics.moveTo(0, 0);
    graphics.lineTo(250, 0);
    graphics.lineTo(250, 200);
    graphics.lineTo(125, 100);
    graphics.lineTo(0, 200);
    graphics.lineTo(0, 0);
    graphics.endFill();

    var sprite = game.make.sprite(32, -48, 'atari');

    graphics.addChild(sprite);

}