说明

支持IE 9+、Firefox、Chrome、Safari、Opera以及Mobile Chrome(Android 2.2+)、Mobile Safari(iOS 5+)

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

function preload() {

    //  Here we load the Starling Texture Atlas and XML file
    game.load.atlasXML('octopus', 'assets/sprites/octopus.png', 'assets/sprites/octopus.xml');

}

function create() {

    //  A more suitable underwater background color
    game.stage.backgroundColor = '#1873CE';

    //  Create our octopus
    var octopus = game.add.sprite(300, 200, 'octopus');

    //  Create an animation called 'swim', the fact we don't specify any frames means it will use all frames in the atlas
    octopus.animations.add('swim');

    //  Play the animation at 30fps on a loop
    octopus.animations.play('swim', 30, true);

    //  Bob the octopus up and down with a tween
    game.add.tween(octopus).to({ y: 300 }, 2000, Phaser.Easing.Quadratic.InOut, true, 0, 1000, true);

}

下载

所有的demo源码都可以访问github项目主页下载

下载所有demo

在线代码编辑

使用这个在线代码编辑器可以不用下载和安装任何东西就可以看到运行效果

返回顶部