phaser/examples/wip/group destroy.js
photonstorm 7e12075be1 Buttons are now cleanly destroyed if part of a Group without leaving their InputHandler running.
You can now safely destroy a Group and the 'destroyChildren' boolean will propogate fully down the display list.
Calling destroy on an already destroyed object would throw a run-time error. Now checked for and aborted.
Calling destroy while in an Input Event callback now works for either the parent Group or the calling object itself.
In Group.destroy the default for 'destroyChildren' was false. It's now `true` as this is a far more likely requirement when destroying a Group.
All GameObjects now have a 'destroyChildren' boolean as a parameter to their destroy method. It's default is true and the value propogates down its children.
2014-02-27 20:05:16 +00:00

72 lines
1.8 KiB
JavaScript

var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.image('atari1', 'assets/sprites/atari130xe.png');
game.load.image('sonic', 'assets/sprites/sonic_havok_sanity.png');
game.load.image('starfield', 'assets/misc/starfield.jpg');
game.load.bitmapFont('carrier', 'assets/fonts/carrier_command.png', 'assets/fonts/carrier_command.xml', null, 0, 24);
game.load.spritesheet('button', 'assets/buttons/button_sprite_sheet.png', 193, 71);
}
var group;
var DaddyGroup;
function create() {
DaddyGroup = game.add.group();
group = game.add.group();
// Testing Group.destroy with different object types:
var sprite = game.make.sprite(300, 100, 'atari1');
var graphics = game.make.graphics(0, 0);
graphics.beginFill(0xFF3300);
graphics.moveTo(0,50);
graphics.lineTo(250, 50);
graphics.lineTo(100, 100);
graphics.lineTo(250, 220);
graphics.lineTo(50, 220);
graphics.lineTo(0, 50);
graphics.endFill();
var tilesprite = game.make.tileSprite(600, 100, 200, 200, 'starfield');
tilesprite.autoScroll(0, 100);
var bitmaptext = game.make.bitmapText(100, 300, 'carrier', 'bitmap text', 32);
var text = game.make.text(100, 350, "normal text");
text.font = 'Arial Black';
text.fontSize = 60;
text.fill = '#ff0044';
var button = game.make.button(100, 450, 'button', actionOnClick, this, 2, 1, 0);
group.add(sprite);
group.add(graphics);
group.add(tilesprite);
group.add(bitmaptext);
group.add(text);
group.add(button);
DaddyGroup.add(group);
game.input.onDown.add(actionOnClick, this);
}
function actionOnClick() {
DaddyGroup.destroy();
}
function update() {
}
function render() {
}