mirror of
https://github.com/wassname/phaser.git
synced 2026-09-09 11:28:47 +08:00
Revamping the examples area.
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
var baddie;
|
||||
var keys = Phaser.Keyboard;
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.image('background','assets/misc/starfield.jpg');
|
||||
game.load.image('ufo','assets/sprites/ufo.png');
|
||||
game.load.image('baddie','assets/sprites/space-baddie.png');
|
||||
|
||||
}
|
||||
|
||||
function create() {
|
||||
|
||||
game.add.tileSprite(0, 0, 2000, 2000, 'background');
|
||||
|
||||
game.world.setBounds(0, 0, 1400,1400);
|
||||
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
game.add.sprite(game.world.randomX, game.world.randomY, 'ufo');
|
||||
}
|
||||
|
||||
baddie = game.add.sprite(150, 320, 'baddie');
|
||||
|
||||
game.camera.follow(baddie);
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
baddie.body.velocity.setTo(0, 0);
|
||||
|
||||
if (game.input.keyboard.isDown(keys.LEFT) && !game.input.keyboard.isDown(keys.RIGHT))
|
||||
{
|
||||
baddie.body.velocity.x = -155;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(keys.RIGHT) && !game.input.keyboard.isDown(keys.LEFT))
|
||||
{
|
||||
baddie.body.velocity.x = 155;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(keys.UP) && !game.input.keyboard.isDown(keys.DOWN))
|
||||
{
|
||||
baddie.angle = 90;
|
||||
baddie.body.velocity.y = -155;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(keys.DOWN) && !game.input.keyboard.isDown(keys.UP))
|
||||
{
|
||||
baddie.angle = 90;
|
||||
baddie.body.velocity.y = 155;
|
||||
}
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.renderCameraInfo(game.camera, 32, 32);
|
||||
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
|
||||
<?php
|
||||
$title = "Following the player";
|
||||
require('../head.php');
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
var baddie,
|
||||
keys=Phaser.Keyboard;
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.image('background','assets/misc/starfield.jpg');
|
||||
game.load.image('ufo','assets/sprites/ufo.png');
|
||||
game.load.image('baddie','assets/sprites/space-baddie.png');
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function create() {
|
||||
|
||||
game.add.tileSprite(0, 0, 2000, 2000, 'background');
|
||||
|
||||
game.world.setBounds(0, 0, 1400,1400);
|
||||
|
||||
for(var i=0,nb=10;i<nb;i++){
|
||||
|
||||
game.add.sprite(game.world.randomX,game.world.randomY,'ufo');
|
||||
}
|
||||
|
||||
baddie=game.add.sprite(150,320,'baddie');
|
||||
|
||||
game.camera.follow(baddie);
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
baddie.body.velocity.x=baddie.body.velocity.y=0;
|
||||
|
||||
|
||||
if(game.input.keyboard.isDown(keys.LEFT) && !game.input.keyboard.isDown(keys.RIGHT)){
|
||||
|
||||
baddie.body.velocity.x=-155;
|
||||
|
||||
}
|
||||
else if(game.input.keyboard.isDown(keys.RIGHT) && !game.input.keyboard.isDown(keys.LEFT)){
|
||||
baddie.body.velocity.x=155;
|
||||
|
||||
}
|
||||
else if(game.input.keyboard.isDown(keys.UP) && !game.input.keyboard.isDown(keys.DOWN)){
|
||||
|
||||
baddie.angle=90;
|
||||
baddie.body.velocity.y=-155;
|
||||
|
||||
}
|
||||
else if(game.input.keyboard.isDown(keys.DOWN) && !game.input.keyboard.isDown(keys.UP)){
|
||||
baddie.angle=90;
|
||||
baddie.body.velocity.y=155;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.renderCameraInfo(game.camera, 32, 32);
|
||||
// game.debug.renderSpriteInfo(d, 32, 200);
|
||||
// game.debug.renderWorldTransformInfo(d, 32, 200);
|
||||
// game.debug.renderLocalTransformInfo(d, 32, 400);
|
||||
// game.debug.renderSpriteCorners(d, false, true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<?php
|
||||
require('../foot.php');
|
||||
?>
|
||||
@@ -0,0 +1,48 @@
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
game.load.image('disk', 'assets/sprites/ra_dont_crack_under_pressure.png');
|
||||
}
|
||||
|
||||
var s;
|
||||
|
||||
function create() {
|
||||
|
||||
game.stage.backgroundColor = '#182d3b';
|
||||
|
||||
s = game.add.sprite(game.world.centerX, game.world.centerY, 'disk');
|
||||
s.anchor.setTo(0.5, 0.5);
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
s.rotation += 0.01;
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
s.x -= 4;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
{
|
||||
s.x += 4;
|
||||
}
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
{
|
||||
s.y -= 4;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
|
||||
{
|
||||
s.y += 4;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.renderSpriteCorners(s, true, true);
|
||||
game.debug.renderSpriteInfo(s, 20, 32);
|
||||
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
<?php
|
||||
$title = "Camera Cull";
|
||||
require('../head.php');
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
game.load.image('disk', 'assets/sprites/ra_dont_crack_under_pressure.png');
|
||||
}
|
||||
|
||||
var s;
|
||||
|
||||
function create() {
|
||||
|
||||
game.stage.backgroundColor = '#182d3b';
|
||||
|
||||
s = game.add.sprite(game.world.centerX, game.world.centerY, 'disk');
|
||||
s.anchor.setTo(0.5, 0.5);
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
s.rotation += 0.01;
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
s.x -= 4;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
{
|
||||
s.x += 4;
|
||||
}
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
{
|
||||
s.y -= 4;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
|
||||
{
|
||||
s.y += 4;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.renderSpriteCorners(s, true, true);
|
||||
game.debug.renderSpriteInfo(s, 20, 32);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<?php
|
||||
require('../foot.php');
|
||||
?>
|
||||
@@ -0,0 +1,109 @@
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
var ufo;
|
||||
var Keys = Phaser.Keyboard;
|
||||
var speed = 4;
|
||||
var style = 'default';
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.image('ground', 'assets/tests/ground-2x.png');
|
||||
game.load.image('river', 'assets/tests/river-2x.png');
|
||||
game.load.image('sky', 'assets/tests/sky-2x.png');
|
||||
game.load.image('cloud0', 'assets/tests/cloud-big-2x.png');
|
||||
game.load.image('cloud1', 'assets/tests/cloud-narrow-2x.png');
|
||||
game.load.image('cloud2', 'assets/tests/cloud-small-2x.png');
|
||||
game.load.image('ufo','assets/sprites/ufo.png');
|
||||
game.load.image('baddie','assets/sprites/space-baddie.png');
|
||||
game.load.spritesheet('button', 'assets/buttons/follow-style-button.png', 224, 70);
|
||||
|
||||
}
|
||||
|
||||
function create() {
|
||||
|
||||
// Make the world larger than the actual canvas
|
||||
game.world.setBounds(0, 0, 1400, 1400);
|
||||
|
||||
for (var i=0; i < 10; i++)
|
||||
{
|
||||
game.add.sprite(game.world.randomX, game.world.randomY, 'baddie');
|
||||
}
|
||||
|
||||
// Background images
|
||||
game.add.tileSprite(0, 0, 1400, 600, 'sky');
|
||||
game.add.sprite(0, 360, 'ground');
|
||||
game.add.sprite(0, 400, 'river');
|
||||
game.add.sprite(200, 120, 'cloud0');
|
||||
game.add.sprite(-60, 120, 'cloud1');
|
||||
game.add.sprite(900, 170, 'cloud2');
|
||||
|
||||
// ufo sprite
|
||||
ufo = game.add.sprite(300, 240, 'ufo');
|
||||
|
||||
//registration point
|
||||
ufo.anchor.setTo(0.5, 0.5);
|
||||
|
||||
game.camera.follow(ufo);
|
||||
|
||||
// follow style switch buttons
|
||||
btn0 = game.add.button(6, 40, 'button', lockonFollow,this, 0, 0, 0);
|
||||
btn1 = game.add.button(6, 120, 'button', platformerFollow,this, 1, 1, 1);
|
||||
btn2 = game.add.button(6, 200, 'button', topdownFollow,this, 2, 2, 2);
|
||||
btn3 = game.add.button(6, 280, 'button', topdownTightFollow,this, 3, 3, 3);
|
||||
|
||||
}
|
||||
|
||||
function lockonFollow() {
|
||||
game.camera.follow(ufo, Phaser.Camera.FOLLOW_LOCKON);
|
||||
style = 'STYLE_LOCKON';
|
||||
}
|
||||
|
||||
function platformerFollow() {
|
||||
game.camera.follow(ufo, Phaser.Camera.FOLLOW_PLATFORMER);
|
||||
style = 'STYLE_PLATFORMER';
|
||||
}
|
||||
|
||||
function topdownFollow() {
|
||||
game.camera.follow(ufo, Phaser.Camera.FOLLOW_TOPDOWN);
|
||||
style = 'STYLE_TOPDOWN';
|
||||
}
|
||||
|
||||
function topdownTightFollow() {
|
||||
game.camera.follow(ufo, Phaser.Camera.FOLLOW_TOPDOWN_TIGHT);
|
||||
style = 'STYLE_TOPDOWN_TIGHT';
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
if (game.input.keyboard.isDown(Keys.LEFT))
|
||||
{
|
||||
ufo.x -= speed;
|
||||
ufo.angle = -15;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Keys.RIGHT))
|
||||
{
|
||||
ufo.x += speed;
|
||||
ufo.angle = 15;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Keys.UP))
|
||||
{
|
||||
ufo.y -= speed;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Keys.DOWN))
|
||||
{
|
||||
ufo.y += speed;
|
||||
}
|
||||
else
|
||||
{
|
||||
ufo.angle = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function render () {
|
||||
|
||||
game.debug.renderText('Click buttons to switch follow styles', 32, 32);
|
||||
game.debug.renderText('Current style: ' + style, 32, 64);
|
||||
|
||||
}
|
||||
@@ -1,130 +0,0 @@
|
||||
|
||||
<?php
|
||||
$title = "Follow Styles";
|
||||
require('../head.php');
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update,render : render });
|
||||
|
||||
var ufo,
|
||||
Keys=Phaser.Keyboard,
|
||||
speed=4,
|
||||
style='default';
|
||||
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.image('ground', 'assets/tests/ground-2x.png');
|
||||
game.load.image('river', 'assets/tests/river-2x.png');
|
||||
game.load.image('sky', 'assets/tests/sky-2x.png');
|
||||
game.load.image('cloud0', 'assets/tests/cloud-big-2x.png');
|
||||
game.load.image('cloud1', 'assets/tests/cloud-narrow-2x.png');
|
||||
game.load.image('cloud2', 'assets/tests/cloud-small-2x.png');
|
||||
game.load.image('ufo','assets/sprites/ufo.png');
|
||||
game.load.image('baddie','assets/sprites/space-baddie.png');
|
||||
game.load.spritesheet('button', 'assets/buttons/follow-style-button.png', 224, 70);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function create() {
|
||||
|
||||
//make the world larger than the actual canvas
|
||||
game.world.setBounds(0,0,1400,1400);
|
||||
|
||||
for(var i=0,nb=10;i<nb;i++){
|
||||
|
||||
game.add.sprite(game.world.randomX,game.world.randomY,'baddie');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// background images
|
||||
game.add.tileSprite(0, 0,1400,600, 'sky');
|
||||
game.add.sprite(0, 360, 'ground');
|
||||
game.add.sprite(0, 400, 'river');
|
||||
game.add.sprite(200, 120, 'cloud0');
|
||||
game.add.sprite(-60, 120, 'cloud1');
|
||||
game.add.sprite(900, 170, 'cloud2');
|
||||
|
||||
|
||||
// ufo sprite
|
||||
ufo = game.add.sprite(300, 240, 'ufo');
|
||||
|
||||
|
||||
//registration point
|
||||
ufo.anchor.setTo(0.5, 0.5);
|
||||
|
||||
|
||||
|
||||
game.camera.follow(ufo);
|
||||
|
||||
// follow style switch buttons
|
||||
btn0 = game.add.button(6, 40, 'button', lockonFollow,this, 0, 0, 0);
|
||||
btn1 = game.add.button(6, 120, 'button', platformerFollow,this, 1, 1, 1);
|
||||
btn2 = game.add.button(6, 200, 'button', topdownFollow,this, 2, 2, 2);
|
||||
btn3 = game.add.button(6, 280, 'button', topdownTightFollow,this, 3, 3, 3);
|
||||
|
||||
}
|
||||
function lockonFollow() {
|
||||
game.camera.follow(ufo, Phaser.Camera.FOLLOW_LOCKON);
|
||||
style = 'STYLE_LOCKON';
|
||||
}
|
||||
function platformerFollow() {
|
||||
game.camera.follow(ufo, Phaser.Camera.FOLLOW_PLATFORMER);
|
||||
style = 'STYLE_PLATFORMER';
|
||||
}
|
||||
function topdownFollow() {
|
||||
game.camera.follow(ufo, Phaser.Camera.FOLLOW_TOPDOWN);
|
||||
style = 'STYLE_TOPDOWN';
|
||||
}
|
||||
function topdownTightFollow() {
|
||||
game.camera.follow(ufo, Phaser.Camera.FOLLOW_TOPDOWN_TIGHT);
|
||||
style = 'STYLE_TOPDOWN_TIGHT';
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
|
||||
if (game.input.keyboard.isDown(Keys.LEFT)) {
|
||||
ufo.x -= speed;
|
||||
ufo.angle = -15;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Keys.RIGHT)) {
|
||||
ufo.x += speed;
|
||||
ufo.angle = 15;
|
||||
}
|
||||
|
||||
else if (game.input.keyboard.isDown(Keys.UP)) {
|
||||
ufo.y -= speed;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Keys.DOWN)) {
|
||||
ufo.y += speed;
|
||||
}
|
||||
else {
|
||||
ufo.angle = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function render () {
|
||||
|
||||
game.context.fillStyle = '#fff';
|
||||
game.context.font="24px Courier";
|
||||
game.context.fillText('Click buttons to switch between different styles.', 60, 220);
|
||||
game.context.fillText('Current style: ' + style, 60, 250);
|
||||
}
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<?php
|
||||
require('../foot.php');
|
||||
?>
|
||||
@@ -0,0 +1,52 @@
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
|
||||
|
||||
function preload() {
|
||||
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
|
||||
}
|
||||
|
||||
function create() {
|
||||
|
||||
game.stage.backgroundColor = '#2d2d2d';
|
||||
|
||||
// Make our game world 2000x2000 pixels in size (the default is to match the game size)
|
||||
game.world.setBounds(0,0,2000, 2000);
|
||||
|
||||
for (var i = 0; i < 50; i++)
|
||||
{
|
||||
var s = game.add.sprite(game.world.randomX, game.world.randomY, 'mushroom');
|
||||
}
|
||||
|
||||
for (var i = 0; i < 50; i++)
|
||||
{
|
||||
game.add.sprite(game.world.randomX, game.world.randomY, 'mushroom');
|
||||
}
|
||||
|
||||
for (var i = 0; i < 50; i++)
|
||||
{
|
||||
var s = game.add.sprite(game.world.randomX, game.world.randomY, 'mushroom');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
game.camera.x -= 4;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
{
|
||||
game.camera.x += 4;
|
||||
}
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
{
|
||||
game.camera.y -= 4;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
|
||||
{
|
||||
game.camera.y += 4;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
<?php
|
||||
$title = "Moving the Camera";
|
||||
require('../head.php');
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });
|
||||
|
||||
function preload() {
|
||||
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
|
||||
}
|
||||
|
||||
function create() {
|
||||
|
||||
game.stage.backgroundColor = '#2d2d2d';
|
||||
|
||||
// Make our game world 2000x2000 pixels in size (the default is to match the game size)
|
||||
game.world.setBounds(0,0,2000, 2000);
|
||||
|
||||
for (var i = 0; i < 50; i++)
|
||||
{
|
||||
var s = game.add.sprite(game.world.randomX, game.world.randomY, 'mushroom');
|
||||
}
|
||||
|
||||
for (var i = 0; i < 50; i++)
|
||||
{
|
||||
game.add.sprite(game.world.randomX, game.world.randomY, 'mushroom');
|
||||
}
|
||||
|
||||
for (var i = 0; i < 50; i++)
|
||||
{
|
||||
var s = game.add.sprite(game.world.randomX, game.world.randomY, 'mushroom');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
game.camera.x -= 4;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
{
|
||||
game.camera.x += 4;
|
||||
}
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
{
|
||||
game.camera.y -= 4;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
|
||||
{
|
||||
game.camera.y += 4;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<?php
|
||||
require('../foot.php');
|
||||
?>
|
||||
@@ -0,0 +1,54 @@
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update,render : render });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.world.setBounds(0, 0, 1920, 1200);
|
||||
|
||||
game.load.image('backdrop', 'assets/pics/remember-me.jpg');
|
||||
game.load.image('card', 'assets/sprites/mana_card.png');
|
||||
|
||||
}
|
||||
|
||||
var card;
|
||||
var Keys = Phaser.Keyboard;
|
||||
|
||||
function create() {
|
||||
|
||||
game.add.sprite(0, 0, 'backdrop');
|
||||
|
||||
card = game.add.sprite(200, 200, 'card');
|
||||
|
||||
card.body.velocity.x = 50;
|
||||
card.scale.setTo(2, 2);
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
if (game.input.keyboard.isDown(Keys.LEFT))
|
||||
{
|
||||
card.x -= 4;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Keys.RIGHT))
|
||||
{
|
||||
card.x += 4;
|
||||
}
|
||||
|
||||
if (game.input.keyboard.isDown(Keys.UP))
|
||||
{
|
||||
card.y -= 4;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Keys.DOWN))
|
||||
{
|
||||
card.y += 4;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.renderCameraInfo(game.camera, 32, 32);
|
||||
game.debug.renderSpriteInfo(card, 32, 200);
|
||||
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
|
||||
<?php
|
||||
$title = "World Sprite";
|
||||
require('../head.php');
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update,render : render });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.world.setBounds(0,0,1920, 1200);
|
||||
|
||||
game.load.image('backdrop', 'assets/pics/remember-me.jpg');
|
||||
game.load.image('card', 'assets/sprites/mana_card.png');
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
var card,
|
||||
Keys=Phaser.Keyboard;
|
||||
|
||||
function create() {
|
||||
|
||||
game.add.sprite(0, 0, 'backdrop');
|
||||
|
||||
card = game.add.sprite(200, 200, 'card');
|
||||
|
||||
card.body.velocity.x = 50;
|
||||
card.scale.setTo(2, 2);
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
|
||||
if (game.input.keyboard.isDown(Keys.LEFT)){
|
||||
card.x -= 4;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Keys.RIGHT)){
|
||||
card.x += 4;
|
||||
}
|
||||
|
||||
if (game.input.keyboard.isDown(Keys.UP)){
|
||||
card.y -= 4;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Keys.DOWN)){
|
||||
card.y += 4;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
// debug are now accessed using game.debug instead of the Static DebugUtils class
|
||||
game.debug.renderCameraInfo(game.camera, 32, 32);
|
||||
game.debug.renderSpriteInfo(card, 32, 200);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<?php
|
||||
require('../foot.php');
|
||||
?>
|
||||
Reference in New Issue
Block a user