Build games as easily as you play them — join the Phaser Beam waitlist for Early Access.
var config = { type: Phaser.WEBGL, parent: 'phaser-example', width: 800, height: 600, scene: { preload: preload, create: create } }; var game = new Phaser.Game(config); function preload () { this.load.setBaseURL('https://cdn.phaserfiles.com/v355'); this.load.atlas('cards', 'assets/atlas/cards.png', 'assets/atlas/cards.json'); } function create () { var image = this.add.image(400, 300, 'cards', 'clubsKing'); // Rotate it image.setAngle(45); // Scale it image.setScale(2); // Make interactive image.setInteractive(); // Make draggable this.input.setDraggable(image); this.input.on('dragstart', function (pointer, gameObject) { this.children.bringToTop(gameObject); }, this); this.input.on('drag', function (pointe, gameObject, dragX, dragY) { gameObject.x = dragX; gameObject.y = dragY; }); }
var config = {
type: Phaser.WEBGL,
parent: 'phaser-example',
width: 800,
height: 600,
scene: {
preload: preload,
create: create
}
};
var game = new Phaser.Game(config);
function preload ()
{
this.load.setBaseURL('https://cdn.phaserfiles.com/v355');
this.load.atlas('cards', 'assets/atlas/cards.png', 'assets/atlas/cards.json');
}
function create ()
{
var image = this.add.image(400, 300, 'cards', 'clubsKing');
// Rotate it
image.setAngle(45);
// Scale it
image.setScale(2);
// Make interactive
image.setInteractive();
// Make draggable
this.input.setDraggable(image);
this.input.on('dragstart', function (pointer, gameObject) {
this.children.bringToTop(gameObject);
}, this);
this.input.on('drag', function (pointe, gameObject, dragX, dragY) {
gameObject.x = dragX;
gameObject.y = dragY;
});
}