mirror of
https://github.com/wassname/phaser.git
synced 2026-08-18 12:20:33 +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,13 +1,16 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, preload, create);
|
||||
|
||||
function preload() {
|
||||
// Using Phasers asset loader we load up a PNG from the assets folder
|
||||
game.load.image('bunny', 'assets/sprites/bunny.png');
|
||||
}
|
||||
|
||||
function create() {
|
||||
// Here we'll assign the new sprite to the local bunny variable
|
||||
var bunny = game.add.sprite(0, 0, 'bunny');
|
||||
|
||||
// And this sets the alpha of the sprite to 0.5, which is 50% opaque
|
||||
bunny.alpha = 0.5;
|
||||
}
|
||||
|
||||
@@ -1,33 +1,28 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update);
|
||||
|
||||
function preload() {
|
||||
game.load.atlas('bot', 'assets/sprites/running_bot.png', 'assets/sprites/running_bot.json');
|
||||
}
|
||||
|
||||
var bot;
|
||||
|
||||
function create() {
|
||||
bot = game.add.sprite(game.stage.width, 300, 'bot');
|
||||
|
||||
// If you are using a Texture Atlas and want to specify the frames of an animation by their name rather than frame index
|
||||
// then you can use this format:
|
||||
bot.animations.add('run', [
|
||||
'run00',
|
||||
'run01',
|
||||
'run02',
|
||||
'run03',
|
||||
'run04',
|
||||
'run05',
|
||||
'run06',
|
||||
'run07',
|
||||
'run08',
|
||||
'run09',
|
||||
'run10'
|
||||
], 10, true, false);
|
||||
bot.animations.add('run', ['run00', 'run01', 'run02', 'run03', 'run04', 'run05', 'run06', 'run07', 'run08', 'run09', 'run10'], 10, true, false);
|
||||
|
||||
bot.animations.play('run');
|
||||
//bot.velocity.x = -100;
|
||||
}
|
||||
}
|
||||
|
||||
function update() {
|
||||
bot.x -= 1;
|
||||
if(bot.x < -bot.width) {
|
||||
|
||||
if (bot.x < -bot.width) {
|
||||
bot.x = game.stage.width;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,27 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, preload, create);
|
||||
|
||||
function preload() {
|
||||
// Using Phasers asset loader we load up a PNG from the assets folder
|
||||
// The sprite sheet is a standard frame-by-frame sheet, and each frame is 37 x 45 pixels in size.
|
||||
// The final parameter (18) is the number of frames there are. You can omit this if your frames fill the entire sheet.
|
||||
game.load.spritesheet('mummy', 'assets/sprites/metalslug_mummy37x45.png', 37, 45, 18);
|
||||
}
|
||||
|
||||
var mummy;
|
||||
|
||||
function create() {
|
||||
mummy = game.add.sprite(game.stage.centerX, game.stage.centerY, 'mummy');
|
||||
|
||||
// Here we add new animation called 'walk'.
|
||||
// As it's the only animation in our sprite sheet we don't need to define the frames being used.
|
||||
mummy.animations.add('walk');
|
||||
|
||||
// This plays the animation at 20 frames per second on a loop (the 3rd parameter)
|
||||
// Try changing the 20 value to something low to slow the speed down, or higher to make it play faster.
|
||||
mummy.animations.play('walk', 20, true);
|
||||
|
||||
// This just scales the sprite up so you can see the animation better
|
||||
mummy.transform.scale.setTo(4, 4);
|
||||
}
|
||||
|
||||
@@ -1,21 +1,28 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, preload, create);
|
||||
|
||||
function preload() {
|
||||
// Using Phasers asset loader we load up a PNG from the assets folder
|
||||
game.load.spritesheet('monster', 'assets/sprites/metalslug_monster39x40.png', 39, 40);
|
||||
}
|
||||
|
||||
var monster;
|
||||
|
||||
function create() {
|
||||
game.stage.backgroundColor = 'rgb(50,10,10)';
|
||||
|
||||
// Notice the use of 'stage.centerX' - this places the sprite in the middle of the stage without needing to do any extra math
|
||||
monster = game.add.sprite(game.stage.centerX, game.stage.centerY, 'monster');
|
||||
|
||||
// For this animation we pass 'null' for the frames, because we're going to use them all
|
||||
// And we set the frame rate (30) and loop status (true) when we add the animation
|
||||
// If the frame rate and looping is never going to change then it's easier to do it here
|
||||
monster.animations.add('walk', null, 30, true);
|
||||
|
||||
// Then you can just call 'play' on its own with no other values to start things going
|
||||
monster.animations.play('walk');
|
||||
|
||||
monster.transform.scale.setTo(2, 2);
|
||||
}
|
||||
})();
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, preload, create);
|
||||
|
||||
function preload() {
|
||||
// Using Phasers asset loader we load up a PNG from the assets folder
|
||||
game.load.image('bunny', 'assets/sprites/bunny.png');
|
||||
}
|
||||
|
||||
function create() {
|
||||
// This will create a Sprite positioned at the top-left of the game (0,0)
|
||||
// Try changing the 0, 0 values
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update, render);
|
||||
|
||||
function preload() {
|
||||
// Using Phasers asset loader we load up a PNG from the assets folder
|
||||
game.load.image('disk', 'assets/sprites/oz_pov_melting_disk.png');
|
||||
@@ -9,15 +10,19 @@
|
||||
game.load.image('fuji3', 'assets/tests/320x200.png');
|
||||
game.load.image('fuji4', 'assets/tests/320x200g.png');
|
||||
}
|
||||
|
||||
var fuji;
|
||||
var fuji2;
|
||||
var fuji3;
|
||||
|
||||
function create() {
|
||||
game.stage.backgroundColor = 'rgb(0,0,0)';
|
||||
|
||||
//game.world.setSize(2000, 1200, true);
|
||||
// The sprite is 320 x 200 pixels in size positioned in the middle of the stage
|
||||
//fuji = game.add.sprite(game.stage.centerX, game.stage.centerY, 'fuji4');
|
||||
fuji2 = game.add.sprite(game.stage.centerX, game.stage.centerY, 'fuji3');
|
||||
|
||||
//fuji2 = game.add.sprite(game.stage.centerX, game.stage.centerY, 'fuji2');
|
||||
//fuji3 = game.add.sprite(game.stage.centerX, game.stage.centerY, 'fuji2');
|
||||
//fuji.visible = false;
|
||||
@@ -38,31 +43,35 @@
|
||||
//fuji.transform.origin.setTo(0.5, 0.5);
|
||||
//fuji.transform.origin.setTo(0, 0);
|
||||
fuji2.transform.origin.setTo(1, 1);
|
||||
|
||||
//fuji3.transform.origin.setTo(1, 1);
|
||||
game.input.onTap.add(rotateIt, this);
|
||||
//game.stage.clear = false;
|
||||
}
|
||||
}
|
||||
|
||||
function rotateIt() {
|
||||
//fuji.rotation += 10;
|
||||
fuji2.rotation += 10;
|
||||
//fuji3.rotation += 20;
|
||||
}
|
||||
}
|
||||
|
||||
function update() {
|
||||
//fuji.rotation++;
|
||||
//fuji2.rotation++;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
var points;
|
||||
var points2;
|
||||
|
||||
function render() {
|
||||
// This = the center point
|
||||
//var cx = fuji2.x + (fuji2.width / 2) * cos - (fuji2.height / 2) * sin;
|
||||
@@ -90,6 +99,7 @@
|
||||
//game.stage.context.fillRect(cx, cy, 4, 4);
|
||||
var sin = Math.sin((fuji2.transform.rotation + fuji2.transform.rotationOffset) * Phaser.GameMath.DEG_TO_RAD);
|
||||
var cos = Math.cos((fuji2.transform.rotation + fuji2.transform.rotationOffset) * Phaser.GameMath.DEG_TO_RAD);
|
||||
|
||||
var originX = fuji2.transform.origin.x * fuji2.width;
|
||||
var originY = fuji2.transform.origin.y * fuji2.height;
|
||||
var centerX = 0.5 * fuji2.width;
|
||||
@@ -97,8 +107,10 @@
|
||||
var distanceX = originX - centerX;
|
||||
var distanceY = originY - centerY;
|
||||
var distance = Math.sqrt(((originX - centerX) * (originX - centerX)) + ((originY - centerY) * (originY - centerY)));
|
||||
|
||||
var px = fuji2.x + distance * Math.cos(fuji2.transform.rotation + 45 * Math.PI / 180);
|
||||
var py = fuji2.y + distance * Math.sin(fuji2.transform.rotation + 45 * Math.PI / 180);
|
||||
|
||||
game.stage.context.save();
|
||||
game.stage.context.fillStyle = 'rgb(255,255,0)';
|
||||
game.stage.context.fillText('rect width: ' + originX + ' height: ' + originY, 32, 32);
|
||||
@@ -107,6 +119,7 @@
|
||||
game.stage.context.fillText('point of rotation x: ' + fuji2.transform.origin.x + ' y: ' + fuji2.transform.origin.y, 32, 92);
|
||||
game.stage.context.fillText('x: ' + fuji2.x + ' y: ' + fuji2.y, fuji2.x + 4, fuji2.y);
|
||||
game.stage.context.restore();
|
||||
|
||||
game.stage.context.save();
|
||||
game.stage.context.fillStyle = 'rgba(255,255,255,0.1)';
|
||||
game.stage.context.arc(fuji2.x, fuji2.y, distance, 0, Math.PI * 2);
|
||||
@@ -224,5 +237,5 @@
|
||||
*/
|
||||
//game.stage.context.strokeStyle = 'rgb(255,255,0)';
|
||||
//game.stage.context.strokeRect(fuji.cameraView.x, fuji.cameraView.y, fuji.cameraView.width, fuji.cameraView.height);
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, preload, create);
|
||||
|
||||
function preload() {
|
||||
// Using Phasers asset loader we load up a PNG from the assets folder
|
||||
game.load.image('bunny', 'assets/sprites/bunny.png');
|
||||
}
|
||||
|
||||
var smallBunny;
|
||||
|
||||
function create() {
|
||||
// Here we'll assign the new sprite to the local smallBunny variable
|
||||
smallBunny = game.add.sprite(0, 0, 'bunny');
|
||||
|
||||
// And now let's scale the sprite by half
|
||||
// You can do either:
|
||||
//smallBunny.scale.x = 0.5;
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, preload, create);
|
||||
|
||||
function preload() {
|
||||
// Using Phasers asset loader we load up a PNG from the assets folder
|
||||
game.load.image('bunny', 'assets/sprites/bunny.png');
|
||||
}
|
||||
|
||||
var bigBunny;
|
||||
|
||||
function create() {
|
||||
// Here we'll assign the new sprite to the local bigBunny variable
|
||||
bigBunny = game.add.sprite(0, 0, 'bunny');
|
||||
|
||||
// And now let's scale the sprite by two
|
||||
// You can do either:
|
||||
// smallBunny.transform.scale.x = 2;
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, preload, create);
|
||||
|
||||
function preload() {
|
||||
// Using Phasers asset loader we load up a PNG from the assets folder
|
||||
game.load.image('bunny', 'assets/sprites/bunny.png');
|
||||
}
|
||||
|
||||
var bunny;
|
||||
|
||||
function create() {
|
||||
// Here we'll assign the new sprite to the local bunny variable
|
||||
bunny = game.add.sprite(0, 0, 'bunny');
|
||||
|
||||
// You don't have to use the same values when scaling a sprite,
|
||||
// here we'll create a short and wide bunny
|
||||
bunny.transform.scale.setTo(3, 0.7);
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, preload, create);
|
||||
|
||||
function preload() {
|
||||
// Using Phasers asset loader we load up a PNG from the assets folder
|
||||
game.load.image('bunny', 'assets/sprites/bunny.png');
|
||||
}
|
||||
|
||||
var bunny;
|
||||
var tweenUp;
|
||||
var tweenDown;
|
||||
|
||||
function create() {
|
||||
// Here we'll assign the new sprite to the local bunny variable
|
||||
bunny = game.add.sprite(0, 0, 'bunny');
|
||||
|
||||
bunny.transform.scale.setTo(0.5, 0.5);
|
||||
|
||||
// This time let's scale the sprite by a looped tween
|
||||
game.add.tween(bunny.transform.scale).to({
|
||||
x: 1.5,
|
||||
y: 1.5
|
||||
}, 2000, Phaser.Easing.Elastic.Out, true, 0, true, true);
|
||||
game.add.tween(bunny.transform.scale).to({ x: 1.5, y: 1.5 }, 2000, Phaser.Easing.Elastic.Out, true, 0, true, true);
|
||||
}
|
||||
})();
|
||||
|
||||
@@ -1,40 +1,46 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, preload, create);
|
||||
|
||||
function preload() {
|
||||
// Using Phasers asset loader we load up a PNG from the assets folder
|
||||
game.load.image('fuji', 'assets/pics/atari_fujilogo.png');
|
||||
}
|
||||
|
||||
var fuji;
|
||||
var tween;
|
||||
|
||||
function create() {
|
||||
game.stage.backgroundColor = 'rgb(0,0,100)';
|
||||
|
||||
// Here we'll assign the new sprite to the local fuji variable
|
||||
fuji = game.add.sprite(game.stage.centerX, game.stage.centerY, 'fuji');
|
||||
|
||||
// sets origin to the center of the sprite (half the width and half the height)
|
||||
fuji.transform.origin.setTo(0.5, 0.5);
|
||||
|
||||
// We'll tween the scale down to zero (which will make the sprite invisible) and then flip it
|
||||
// The end result should look like turning over a card
|
||||
// Create our tween
|
||||
tween = game.add.tween(fuji.transform.scale);
|
||||
|
||||
// Start it going
|
||||
scaleLeft();
|
||||
}
|
||||
|
||||
function scaleLeft() {
|
||||
tween.clear();
|
||||
tween.to({
|
||||
x: 0
|
||||
}, 1000);
|
||||
tween.to({ x: 0 }, 1000);
|
||||
tween.onComplete.add(scaleRight, this);
|
||||
tween.start();
|
||||
}
|
||||
|
||||
function scaleRight() {
|
||||
tween.clear();
|
||||
tween.to({
|
||||
x: 1
|
||||
}, 1000);
|
||||
tween.to({ x: 1 }, 1000);
|
||||
tween.onComplete.add(scaleLeft, this);
|
||||
tween.start();
|
||||
|
||||
// This line says "if the texture is flippedX then unflip it (set flippedX to false), otherwise set flippedX to true
|
||||
(fuji.texture.flippedX) ? fuji.texture.flippedX = false : fuji.texture.flippedX = true;
|
||||
}
|
||||
|
||||
@@ -1,19 +1,22 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, preload, create);
|
||||
|
||||
function preload() {
|
||||
// Using Phasers asset loader we load up a PNG from the assets folder
|
||||
game.load.image('fuji', 'assets/pics/atari_fujilogo.png');
|
||||
}
|
||||
|
||||
var fuji;
|
||||
|
||||
function create() {
|
||||
game.stage.backgroundColor = 'rgb(0,0,100)';
|
||||
|
||||
// Here we'll assign the new sprite to the local fuji variable
|
||||
fuji = game.add.sprite(game.stage.centerX, game.stage.centerY, 'fuji');
|
||||
|
||||
// The sprite is 320 x 200 pixels in size
|
||||
// If we don't set an origin then the sprite will rotate around 0,0 - the top left corner
|
||||
game.add.tween(fuji).to({
|
||||
rotation: 360
|
||||
}, 2000, Phaser.Easing.Linear.None, true, 0, true);
|
||||
game.add.tween(fuji).to({ rotation: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true);
|
||||
}
|
||||
})();
|
||||
|
||||
@@ -1,21 +1,25 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, preload, create);
|
||||
|
||||
function preload() {
|
||||
// Using Phasers asset loader we load up a PNG from the assets folder
|
||||
game.load.image('fuji', 'assets/pics/atari_fujilogo.png');
|
||||
}
|
||||
|
||||
var fuji;
|
||||
|
||||
function create() {
|
||||
game.stage.backgroundColor = 'rgb(0,0,100)';
|
||||
|
||||
// Here we'll assign the new sprite to the local fuji variable
|
||||
fuji = game.add.sprite(game.stage.centerX, game.stage.centerY, 'fuji');
|
||||
|
||||
// The sprite is 320 x 200 pixels in size
|
||||
// Here we set the origin to the center of the sprite (half of its width and height, so 160x100)
|
||||
// This will cause it to rotate on its center
|
||||
fuji.transform.origin.setTo(0.5, 0.5);
|
||||
game.add.tween(fuji).to({
|
||||
rotation: 360
|
||||
}, 2000, Phaser.Easing.Linear.None, true, 0, true);
|
||||
|
||||
game.add.tween(fuji).to({ rotation: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true);
|
||||
}
|
||||
})();
|
||||
|
||||
@@ -1,21 +1,25 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, preload, create);
|
||||
|
||||
function preload() {
|
||||
// Using Phasers asset loader we load up a PNG from the assets folder
|
||||
game.load.image('fuji', 'assets/pics/atari_fujilogo.png');
|
||||
}
|
||||
|
||||
var fuji;
|
||||
var tween;
|
||||
|
||||
function create() {
|
||||
game.stage.backgroundColor = 'rgb(0,0,100)';
|
||||
|
||||
// Here we'll assign the new sprite to the local fuji variable
|
||||
fuji = game.add.sprite(game.stage.centerX, game.stage.centerY, 'fuji');
|
||||
|
||||
// The sprite is 320 x 200 pixels in size
|
||||
// Here we set the origin to be the bottom-right of the sprite
|
||||
fuji.origin.setTo(1, 1);
|
||||
game.add.tween(fuji).to({
|
||||
rotation: 360
|
||||
}, 2000, Phaser.Easing.Linear.None, true, 0, true);
|
||||
|
||||
game.add.tween(fuji).to({ rotation: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true);
|
||||
}
|
||||
})();
|
||||
|
||||
@@ -1,41 +1,44 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, preload, create);
|
||||
|
||||
function preload() {
|
||||
// Using Phasers asset loader we load up a PNG from the assets folder
|
||||
game.load.image('fuji', 'assets/pics/atari_fujilogo.png');
|
||||
}
|
||||
|
||||
var fuji;
|
||||
var tweenUp;
|
||||
var tweenDown;
|
||||
|
||||
function create() {
|
||||
game.stage.backgroundColor = 'rgb(0,0,100)';
|
||||
|
||||
// Here we'll assign the new sprite to the local fuji variable
|
||||
fuji = game.add.sprite(game.stage.centerX, game.stage.centerY, 'fuji');
|
||||
|
||||
// The sprite is 320 x 200 pixels in size
|
||||
// Here we set the origin to the center of the sprite again, so we can rotate and scale it at the same time
|
||||
fuji.transform.origin.setTo(0.5, 0.5);
|
||||
game.add.tween(fuji).to({
|
||||
rotation: 360
|
||||
}, 2000, Phaser.Easing.Linear.None, true, 0, true);
|
||||
|
||||
game.add.tween(fuji).to({ rotation: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true);
|
||||
|
||||
tweenUp = game.add.tween(fuji.transform.scale);
|
||||
tweenUp.onComplete.add(scaleDown, this);
|
||||
|
||||
tweenDown = game.add.tween(fuji.transform.scale);
|
||||
tweenDown.onComplete.add(scaleUp, this);
|
||||
|
||||
scaleUp();
|
||||
}
|
||||
|
||||
function scaleUp() {
|
||||
tweenUp.to({
|
||||
x: 2,
|
||||
y: 2
|
||||
}, 1000, Phaser.Easing.Elastic.Out);
|
||||
tweenUp.to({ x: 2, y: 2 }, 1000, Phaser.Easing.Elastic.Out);
|
||||
tweenUp.start();
|
||||
}
|
||||
|
||||
function scaleDown() {
|
||||
tweenDown.to({
|
||||
x: 0.5,
|
||||
y: 0.5
|
||||
}, 1000, Phaser.Easing.Elastic.Out);
|
||||
tweenDown.to({ x: 0.5, y: 0.5 }, 1000, Phaser.Easing.Elastic.Out);
|
||||
tweenDown.start();
|
||||
}
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user