mirror of
https://github.com/wassname/phaser.git
synced 2026-07-23 13:00:41 +08:00
yuidoc scripts added. Tidied up the Docs folder. Added back in the Emitter and fixed the Tests that weren't compiling.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, preload, create, null, render);
|
||||
|
||||
function preload() {
|
||||
game.load.image('atari1', 'assets/sprites/atari130xe.png');
|
||||
game.load.image('atari2', 'assets/sprites/atari800xl.png');
|
||||
@@ -11,16 +12,18 @@
|
||||
game.load.image('diamond', 'assets/sprites/diamond.png');
|
||||
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
|
||||
}
|
||||
|
||||
function create() {
|
||||
// This returns an array of all the image keys in the cache
|
||||
var images = game.cache.getImageKeys();
|
||||
// Now let's create some random sprites and enable them all for drag and 'bring to top'
|
||||
for(var i = 0; i < 20; i++) {
|
||||
|
||||
for (var i = 0; i < 20; i++) {
|
||||
var tempSprite = game.add.sprite(game.stage.randomX, game.stage.randomY, game.rnd.pick(images));
|
||||
tempSprite.input.start(i, false, true);
|
||||
tempSprite.input.enableDrag(false, true);
|
||||
}
|
||||
}
|
||||
|
||||
function render() {
|
||||
Phaser.DebugUtils.renderInputInfo(32, 32);
|
||||
}
|
||||
|
||||
@@ -1,20 +1,26 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, preload, create, null, render);
|
||||
|
||||
function preload() {
|
||||
// Using Phasers asset loader we load up a PNG from the assets folder
|
||||
game.load.image('sprite', 'assets/sprites/atari130xe.png');
|
||||
}
|
||||
|
||||
var sprite;
|
||||
|
||||
function create() {
|
||||
sprite = game.add.sprite(200, 200, 'sprite');
|
||||
|
||||
// Enable Input detection. Sprites have this disabled by default,
|
||||
// so you have to start it if you want to interact with them.
|
||||
sprite.input.start(0, false, true);
|
||||
|
||||
// This allows you to drag the sprite. The parameter controls if you drag from the position you touched it (false)
|
||||
// or if it will snap to the center (true)
|
||||
sprite.input.enableDrag(true);
|
||||
}
|
||||
|
||||
function render() {
|
||||
Phaser.DebugUtils.renderInputInfo(32, 32);
|
||||
Phaser.DebugUtils.renderSpriteInputInfo(sprite, 300, 32);
|
||||
|
||||
@@ -1,19 +1,26 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, preload, create, null, render);
|
||||
|
||||
function preload() {
|
||||
// Using Phasers asset loader we load up a PNG from the assets folder
|
||||
game.load.image('sprite', 'assets/sprites/atari800.png');
|
||||
}
|
||||
|
||||
var sprite;
|
||||
|
||||
function create() {
|
||||
sprite = game.add.sprite(200, 200, 'sprite');
|
||||
|
||||
sprite.input.start(0, false, true);
|
||||
|
||||
sprite.input.enableDrag(true);
|
||||
|
||||
// The drag offset allows us to position the sprite relative to the pointer (+ lock) position
|
||||
// In this case it will be positioned -100px above the pointer
|
||||
sprite.input.dragOffset.y = -100;
|
||||
}
|
||||
|
||||
function render() {
|
||||
Phaser.DebugUtils.renderInputInfo(32, 32);
|
||||
Phaser.DebugUtils.renderSpriteInputInfo(sprite, 300, 32);
|
||||
|
||||
@@ -1,20 +1,28 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, preload, create, null, render);
|
||||
|
||||
function preload() {
|
||||
// Using Phasers asset loader we load up a PNG from the assets folder
|
||||
game.load.image('sprite', 'assets/sprites/atari800.png');
|
||||
}
|
||||
|
||||
var sprite;
|
||||
|
||||
function create() {
|
||||
sprite = game.add.sprite(500, 300, 'sprite');
|
||||
|
||||
sprite.input.start(0, false, true);
|
||||
|
||||
// This will ensure the sprite is dragged from its center
|
||||
sprite.input.enableDrag(true);
|
||||
}
|
||||
|
||||
function render() {
|
||||
Phaser.DebugUtils.renderSpriteCorners(sprite);
|
||||
|
||||
Phaser.DebugUtils.renderInputInfo(32, 32);
|
||||
|
||||
Phaser.DebugUtils.renderSpriteInfo(sprite, 32, 200);
|
||||
}
|
||||
})();
|
||||
|
||||
@@ -2,32 +2,40 @@
|
||||
(function () {
|
||||
// Here we create a tiny game (320x240 in size)
|
||||
var game = new Phaser.Game(this, 'game', 320, 240, preload, create, update, render);
|
||||
|
||||
function preload() {
|
||||
// This sets a limit on the up-scale
|
||||
game.stage.scale.maxWidth = 800;
|
||||
game.stage.scale.maxHeight = 600;
|
||||
|
||||
// Then we tell Phaser that we want it to scale up to whatever the browser can handle, but to do it proportionally
|
||||
game.stage.scaleMode = Phaser.StageScaleMode.SHOW_ALL;
|
||||
|
||||
game.load.image('melon', 'assets/sprites/melon.png');
|
||||
}
|
||||
|
||||
function create() {
|
||||
game.world.setSize(2000, 2000);
|
||||
for(var i = 0; i < 1000; i++) {
|
||||
|
||||
for (var i = 0; i < 1000; i++) {
|
||||
game.add.sprite(game.world.randomX, game.world.randomY, 'melon');
|
||||
}
|
||||
}
|
||||
|
||||
function update() {
|
||||
if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||
game.camera.x -= 4;
|
||||
} else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
||||
} else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
||||
game.camera.x += 4;
|
||||
}
|
||||
if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) {
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) {
|
||||
game.camera.y -= 4;
|
||||
} else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
|
||||
} else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
|
||||
game.camera.y += 4;
|
||||
}
|
||||
}
|
||||
|
||||
function render() {
|
||||
Phaser.DebugUtils.renderInputInfo(16, 16);
|
||||
}
|
||||
|
||||
@@ -1,23 +1,31 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, preload, create, null, render);
|
||||
|
||||
function preload() {
|
||||
// Using Phasers asset loader we load up a PNG from the assets folder
|
||||
game.load.image('sprite', 'assets/sprites/darkwing_crazy.png');
|
||||
}
|
||||
|
||||
var sprite;
|
||||
|
||||
function create() {
|
||||
game.stage.backgroundColor = 'rgb(85,85,85)';
|
||||
|
||||
sprite = game.add.sprite(200, 200, 'sprite');
|
||||
|
||||
// Enable Input detection. Sprites have this disabled by default,
|
||||
// so you have to start it if you want to interact with them.
|
||||
sprite.input.start(0, false, true);
|
||||
|
||||
// This allows you to drag the sprite. The parameter controls if you drag from the position you touched it (false)
|
||||
// or if it will snap to the center (true)
|
||||
sprite.input.enableDrag();
|
||||
|
||||
// This will lock the sprite so it can only be dragged vertically, not horizontally
|
||||
sprite.input.allowHorizontalDrag = false;
|
||||
}
|
||||
|
||||
function render() {
|
||||
Phaser.DebugUtils.renderInputInfo(32, 32);
|
||||
Phaser.DebugUtils.renderSpriteInputInfo(sprite, 300, 32);
|
||||
|
||||
@@ -1,23 +1,31 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, preload, create, null, render);
|
||||
|
||||
function preload() {
|
||||
// Using Phasers asset loader we load up a PNG from the assets folder
|
||||
game.load.image('sprite', 'assets/sprites/parsec.png');
|
||||
}
|
||||
|
||||
var sprite;
|
||||
|
||||
function create() {
|
||||
game.stage.backgroundColor = 'rgb(85,85,85)';
|
||||
|
||||
sprite = game.add.sprite(200, 400, 'sprite');
|
||||
|
||||
// Enable Input detection. Sprites have this disabled by default,
|
||||
// so you have to start it if you want to interact with them.
|
||||
sprite.input.start(0, false, true);
|
||||
|
||||
// This allows you to drag the sprite. The parameter controls if you drag from the position you touched it (false)
|
||||
// or if it will snap to the center (true)
|
||||
sprite.input.enableDrag();
|
||||
|
||||
// This will lock the sprite so it can only be dragged horizontally, not vertically
|
||||
sprite.input.allowVerticalDrag = false;
|
||||
}
|
||||
|
||||
function render() {
|
||||
Phaser.DebugUtils.renderInputInfo(32, 32);
|
||||
Phaser.DebugUtils.renderSpriteInputInfo(sprite, 300, 32);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, null, null, null, render);
|
||||
|
||||
function render() {
|
||||
Phaser.DebugUtils.renderPointer(game.input.pointer1);
|
||||
Phaser.DebugUtils.renderPointer(game.input.pointer2);
|
||||
|
||||
@@ -1,16 +1,21 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, preload, create, null, render);
|
||||
|
||||
function preload() {
|
||||
// Using Phasers asset loader we load up a PNG from the assets folder
|
||||
game.load.image('sprite', 'assets/sprites/atari130xe.png');
|
||||
}
|
||||
|
||||
var sprite;
|
||||
|
||||
function create() {
|
||||
sprite = game.add.sprite(200, 200, 'sprite');
|
||||
|
||||
// Enable Input detection
|
||||
sprite.input.start(0, false, true);
|
||||
}
|
||||
|
||||
function render() {
|
||||
Phaser.DebugUtils.renderInputInfo(32, 32);
|
||||
Phaser.DebugUtils.renderSpriteInputInfo(sprite, 300, 32);
|
||||
|
||||
@@ -1,23 +1,27 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, preload, create, null, render);
|
||||
|
||||
function preload() {
|
||||
// Using Phasers asset loader we load up a PNG from the assets folder
|
||||
game.load.image('sprite', 'assets/sprites/shinyball.png');
|
||||
}
|
||||
|
||||
var sprite;
|
||||
|
||||
function create() {
|
||||
// Create a load of sprites
|
||||
for(var i = 0; i < 26; i++) {
|
||||
for (var i = 0; i < 26; i++) {
|
||||
var tempSprite = game.add.sprite(i * 32, 100, 'sprite');
|
||||
tempSprite.input.start(0, false, true);
|
||||
tempSprite.events.onInputOver.add(dropSprite, this);
|
||||
}
|
||||
}
|
||||
|
||||
function dropSprite(sprite) {
|
||||
sprite.body.velocity.y = 300;
|
||||
sprite.input.enabled = false;
|
||||
}
|
||||
|
||||
function render() {
|
||||
Phaser.DebugUtils.renderInputInfo(32, 32);
|
||||
}
|
||||
|
||||
@@ -1,38 +1,51 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update, render);
|
||||
|
||||
function preload() {
|
||||
game.load.image('sprite', 'assets/sprites/atari130xe.png');
|
||||
}
|
||||
|
||||
var sprite;
|
||||
var rotate = false;
|
||||
|
||||
function create() {
|
||||
sprite = game.add.sprite(200, 200, 'sprite');
|
||||
|
||||
game.input.onTap.add(rotateIt, this);
|
||||
}
|
||||
|
||||
function rotateIt() {
|
||||
if(rotate == false) {
|
||||
if (rotate == false) {
|
||||
rotate = true;
|
||||
} else {
|
||||
rotate = false;
|
||||
}
|
||||
}
|
||||
|
||||
var inPoint = false;
|
||||
|
||||
function update() {
|
||||
if(rotate) {
|
||||
if (rotate) {
|
||||
sprite.rotation++;
|
||||
}
|
||||
|
||||
inPoint = Phaser.SpriteUtils.overlapsXY(sprite, game.input.x, game.input.y);
|
||||
}
|
||||
|
||||
function render() {
|
||||
game.stage.context.save();
|
||||
game.stage.context.fillStyle = 'rgb(255,0,255)';
|
||||
|
||||
game.stage.context.fillText('x: ' + Math.round(sprite.transform.upperLeft.x) + ' y: ' + Math.round(sprite.transform.upperLeft.y), sprite.transform.upperLeft.x, sprite.transform.upperLeft.y);
|
||||
game.stage.context.fillText('x: ' + Math.round(sprite.transform.upperRight.x) + ' y: ' + Math.round(sprite.transform.upperRight.y), sprite.transform.upperRight.x, sprite.transform.upperRight.y);
|
||||
game.stage.context.fillText('x: ' + Math.round(sprite.transform.bottomLeft.x) + ' y: ' + Math.round(sprite.transform.bottomLeft.y), sprite.transform.bottomLeft.x, sprite.transform.bottomLeft.y);
|
||||
game.stage.context.fillText('x: ' + Math.round(sprite.transform.bottomRight.x) + ' y: ' + Math.round(sprite.transform.bottomRight.y), sprite.transform.bottomRight.x, sprite.transform.bottomRight.y);
|
||||
|
||||
Phaser.DebugUtils.renderInputInfo(32, 32);
|
||||
|
||||
game.stage.context.fillText('in: ' + inPoint, 300, 32);
|
||||
|
||||
game.stage.context.restore();
|
||||
}
|
||||
})();
|
||||
|
||||
@@ -1,31 +1,40 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, preload, create, null, render);
|
||||
|
||||
function preload() {
|
||||
// Using Phasers asset loader we load up a PNG from the assets folder
|
||||
game.load.image('atari1', 'assets/sprites/atari130xe.png');
|
||||
game.load.image('atari2', 'assets/sprites/atari800xl.png');
|
||||
game.load.image('sonic', 'assets/sprites/sonic_havok_sanity.png');
|
||||
}
|
||||
|
||||
var atari1;
|
||||
var atari2;
|
||||
var sonic;
|
||||
|
||||
function create() {
|
||||
atari1 = game.add.sprite(200, 200, 'atari1');
|
||||
atari2 = game.add.sprite(500, 400, 'atari2');
|
||||
sonic = game.add.sprite(400, 500, 'sonic');
|
||||
|
||||
atari1.origin.setTo(0.5, 0.5);
|
||||
atari1.rotation = 35;
|
||||
|
||||
atari2.origin.setTo(1, 1);
|
||||
atari2.rotation = 80;
|
||||
|
||||
sonic.rotation = 140;
|
||||
|
||||
atari1.input.start(0, false, true);
|
||||
atari2.input.start(1, false, true);
|
||||
sonic.input.start(2, false, true);
|
||||
|
||||
atari1.input.enableDrag();
|
||||
atari2.input.enableDrag();
|
||||
sonic.input.enableDrag();
|
||||
}
|
||||
|
||||
function render() {
|
||||
Phaser.DebugUtils.renderInputInfo(32, 32);
|
||||
}
|
||||
|
||||
@@ -1,31 +1,40 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, preload, create, null, render);
|
||||
|
||||
function preload() {
|
||||
// Using Phasers asset loader we load up a PNG from the assets folder
|
||||
game.load.image('grid', 'assets/tests/debug-grid-1920x1920.png');
|
||||
game.load.image('atari1', 'assets/sprites/atari130xe.png');
|
||||
game.load.image('atari2', 'assets/sprites/atari800xl.png');
|
||||
}
|
||||
|
||||
var atari1;
|
||||
var atari2;
|
||||
var sonic;
|
||||
|
||||
function create() {
|
||||
game.add.sprite(0, 0, 'grid');
|
||||
|
||||
atari1 = game.add.sprite(128, 128, 'atari1');
|
||||
atari2 = game.add.sprite(256, 256, 'atari2');
|
||||
|
||||
// Input Enable the sprites
|
||||
atari1.input.start(0, false, true);
|
||||
atari2.input.start(1, false, true);
|
||||
|
||||
// Allow dragging
|
||||
atari1.input.enableDrag();
|
||||
atari2.input.enableDrag();
|
||||
|
||||
// Enable snapping. For the atari1 sprite it will snap as its dragged around and on release.
|
||||
// The snap is set to every 32x32 pixels.
|
||||
atari1.input.enableSnap(32, 32, true, true);
|
||||
|
||||
// For the atari2 sprite it will snap only when released, not on drag.
|
||||
atari2.input.enableSnap(32, 32, false, true);
|
||||
}
|
||||
|
||||
function render() {
|
||||
Phaser.DebugUtils.renderInputInfo(32, 32);
|
||||
}
|
||||
|
||||
@@ -1,26 +1,32 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, preload, create, null, render);
|
||||
|
||||
function preload() {
|
||||
// Using Phasers asset loader we load up a PNG from the assets folder
|
||||
game.load.image('atari1', 'assets/sprites/atari130xe.png');
|
||||
game.load.image('atari2', 'assets/sprites/atari800xl.png');
|
||||
game.load.image('sonic', 'assets/sprites/sonic_havok_sanity.png');
|
||||
}
|
||||
|
||||
var atari1;
|
||||
var atari2;
|
||||
var sonic;
|
||||
|
||||
function create() {
|
||||
atari1 = game.add.sprite(100, 100, 'atari1');
|
||||
atari2 = game.add.sprite(300, 200, 'atari2');
|
||||
sonic = game.add.sprite(400, 300, 'sonic');
|
||||
|
||||
atari1.input.start(0, false, true);
|
||||
atari2.input.start(1, false, true);
|
||||
sonic.input.start(2, false, true);
|
||||
|
||||
atari1.input.enableDrag();
|
||||
atari2.input.enableDrag();
|
||||
sonic.input.enableDrag();
|
||||
}
|
||||
|
||||
function render() {
|
||||
Phaser.DebugUtils.renderInputInfo(32, 32);
|
||||
}
|
||||
|
||||
@@ -1,26 +1,33 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update, render);
|
||||
|
||||
function preload() {
|
||||
game.world.setSize(1920, 1200, true);
|
||||
|
||||
game.load.image('backdrop', 'assets/pics/remember-me.jpg');
|
||||
}
|
||||
|
||||
var test;
|
||||
|
||||
function create() {
|
||||
game.add.sprite(0, 0, 'backdrop');
|
||||
}
|
||||
|
||||
function update() {
|
||||
if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||
game.camera.x -= 4;
|
||||
} else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
||||
} else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
||||
game.camera.x += 4;
|
||||
}
|
||||
if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) {
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) {
|
||||
game.camera.y -= 4;
|
||||
} else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
|
||||
} else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
|
||||
game.camera.y += 4;
|
||||
}
|
||||
}
|
||||
|
||||
function render() {
|
||||
Phaser.DebugUtils.renderInputInfo(32, 32);
|
||||
Phaser.DebugUtils.renderPointer(game.input.activePointer);
|
||||
|
||||
@@ -1,18 +1,24 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update, render);
|
||||
|
||||
function preload() {
|
||||
game.world.setSize(1920, 1200, true);
|
||||
|
||||
game.load.image('backdrop', 'assets/pics/remember-me.jpg');
|
||||
game.load.image('diamond', 'assets/sprites/diamond.png');
|
||||
}
|
||||
|
||||
var test;
|
||||
|
||||
function create() {
|
||||
game.add.sprite(0, 0, 'backdrop');
|
||||
for(var i = 0; i < 50; i++) {
|
||||
|
||||
for (var i = 0; i < 50; i++) {
|
||||
var sprite = game.add.sprite(game.world.randomX, game.world.randomY, 'diamond');
|
||||
sprite.input.start(i, false, true);
|
||||
if(i < 25) {
|
||||
|
||||
if (i < 25) {
|
||||
sprite.input.enableDrag(false);
|
||||
} else {
|
||||
sprite.input.enableDrag(true);
|
||||
@@ -20,18 +26,21 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function update() {
|
||||
if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||
game.camera.x -= 4;
|
||||
} else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
||||
} else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
||||
game.camera.x += 4;
|
||||
}
|
||||
if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) {
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) {
|
||||
game.camera.y -= 4;
|
||||
} else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
|
||||
} else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
|
||||
game.camera.y += 4;
|
||||
}
|
||||
}
|
||||
|
||||
function render() {
|
||||
Phaser.DebugUtils.renderCameraInfo(game.camera, 16, 32);
|
||||
Phaser.DebugUtils.renderInputInfo(16, 200);
|
||||
|
||||
Reference in New Issue
Block a user