mirror of
https://github.com/wassname/phaser.git
synced 2026-06-27 16:10:15 +08:00
Updated a lot of examples to Phaser 2.0 :)
This commit is contained in:
@@ -69,6 +69,4 @@ function render() {
|
||||
game.debug.renderSpriteCoords(player, 32, 200);
|
||||
game.debug.renderSpriteCoords(fixed, 600, 200);
|
||||
|
||||
// game.debug.renderSpriteCoords(game.world._container, 32, 400);
|
||||
|
||||
}
|
||||
|
||||
@@ -20,20 +20,20 @@ function create() {
|
||||
sprite = game.add.sprite(0, 0, 'sprite');
|
||||
sprite.alpha = 0.5 ;
|
||||
sprite.x = game.width / 2 ;
|
||||
sprite.anchor.x = sprite.anchor.y = 0.5 ;
|
||||
sprite.physicsEnabled = true;
|
||||
|
||||
// create sprite B
|
||||
otherSprite = game.add.sprite(0, 0, 'otherSprite');
|
||||
otherSprite.alpha = 0.5 ;
|
||||
otherSprite.x = (game.width / 2) + 150 ;
|
||||
otherSprite.y = (game.height / 2) + 150 ;
|
||||
otherSprite.anchor.x = sprite.anchor.y = 0.5 ;
|
||||
otherSprite.physicsEnabled = true;
|
||||
otherSprite.body.immovable = true ;
|
||||
}
|
||||
|
||||
function update()
|
||||
{
|
||||
game.physics.collide( sprite, otherSprite ) ;
|
||||
// game.physics.collide( sprite, otherSprite ) ;
|
||||
|
||||
// Move sprite up and down smoothly for show
|
||||
var tStep = Math.sin( counter ) ;
|
||||
@@ -45,9 +45,8 @@ function update()
|
||||
function render() {
|
||||
|
||||
// Physics
|
||||
game.debug.renderSpriteBody(sprite);
|
||||
game.debug.renderSpriteCollision(sprite, 32, 32);
|
||||
game.debug.renderSpriteBounds(sprite);
|
||||
|
||||
game.debug.renderSpriteBody(otherSprite);
|
||||
game.debug.renderSpriteBounds(otherSprite);
|
||||
|
||||
}
|
||||
|
||||
@@ -35,7 +35,5 @@ function render() {
|
||||
|
||||
// Sprite debug info
|
||||
game.debug.renderSpriteInfo(sprite, 32, 32);
|
||||
game.debug.renderLocalTransformInfo(sprite, 32, 160);
|
||||
game.debug.renderWorldTransformInfo(sprite, 32, 290);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update });
|
||||
|
||||
function preload() {
|
||||
|
||||
@@ -28,6 +28,8 @@ function create() {
|
||||
// Populate the wave with some data
|
||||
waveData = game.math.sinCosGenerator(32, 8, 8, 2);
|
||||
|
||||
console.log(bmd.context)
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
@@ -44,6 +46,8 @@ function update() {
|
||||
|
||||
function updateWobblyBall()
|
||||
{
|
||||
|
||||
|
||||
var s = 0;
|
||||
var copyRect = { x: 0, y: 0, w: wavePixelChunk, h: 32 };
|
||||
var copyPoint = { x: 0, y: 0 };
|
||||
|
||||
@@ -39,12 +39,12 @@ function create() {
|
||||
|
||||
stuffContainer = game.add.group();
|
||||
stuffContainer.x = 800/2;
|
||||
stuffContainer.y = 600/2
|
||||
stuffContainer.y = 600/2;
|
||||
|
||||
// now create some items and randomly position them in the stuff container
|
||||
for (var i = 0; i < 20; i++)
|
||||
{
|
||||
var item = stuffContainer.create(Math.random() * 400 - 200, Math.random() * 400 - 200, game.rnd.pick(game.cache.getImageKeys()));
|
||||
var item = stuffContainer.create(Math.random() * 400 - 200, Math.random() * 400 - 200, game.rnd.pick(game.cache.getKeys(Phaser.Cache.IMAGE)));
|
||||
item.anchor.setTo(0.5, 0.5);
|
||||
}
|
||||
|
||||
@@ -73,6 +73,6 @@ function update() {
|
||||
|
||||
// render the stage to the texture
|
||||
// the true clears the texture before content is rendered
|
||||
renderTexture2.renderXY(game.stage.display, 0, 0, true);
|
||||
renderTexture2.renderXY(game.stage, 0, 0, true);
|
||||
|
||||
}
|
||||
|
||||
@@ -27,11 +27,13 @@ function create() {
|
||||
|
||||
function update() {
|
||||
|
||||
|
||||
|
||||
if (!game.input.activePointer.position.isZero())
|
||||
{
|
||||
// This time we'll draw the ball sprite twice, in a mirror effect
|
||||
texture.renderXY(ball, game.input.activePointer.x, game.input.activePointer.y, false, true);
|
||||
texture.renderXY(ball, game.input.activePointer.x, 600 - game.input.activePointer.y, false, true);
|
||||
texture.renderXY(ball, game.input.activePointer.x, game.input.activePointer.y, true);
|
||||
texture.renderXY(ball, game.input.activePointer.x, 600 - game.input.activePointer.y, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,12 +35,12 @@ function create() {
|
||||
eye = robot.create(335, 173,'eye');
|
||||
|
||||
// Tween the robot's size, so all the components also scaled.
|
||||
game.add.tween(robot._container.scale).to( {x: 1.2, y: 1.2}, 1000, Phaser.Easing.Back.InOut, true, 0, false).yoyo(true);
|
||||
game.add.tween(robot.scale).to( {x: 1.2, y: 1.2}, 1000, Phaser.Easing.Back.InOut, true, 0, false).yoyo(true);
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.renderText('The robot is a group and every component is a sprite.', 240, 580);
|
||||
game.debug.renderText('The robot is a group and every component is a sprite.', 32,32);
|
||||
|
||||
}
|
||||
|
||||
@@ -25,9 +25,9 @@ function create() {
|
||||
normalBaddies = game.add.group();
|
||||
purpleBaddies = game.add.group();
|
||||
|
||||
// Add both teams to enemies group, using the Pixi container otherwise it's impossible
|
||||
enemies.add(normalBaddies._container);
|
||||
enemies.add(purpleBaddies._container);
|
||||
|
||||
enemies.add(normalBaddies);
|
||||
enemies.add(purpleBaddies);
|
||||
|
||||
|
||||
// Create a ufo as a friend sprite.
|
||||
|
||||
@@ -16,7 +16,7 @@ function preload() {
|
||||
function create() {
|
||||
|
||||
// This returns an array of all the image keys in the cache
|
||||
var images = game.cache.getImageKeys();
|
||||
var images = game.cache.getKeys(Phaser.Cache.IMAGE);
|
||||
|
||||
// Now let's create some random sprites and enable them all for drag and 'bring to top'
|
||||
for (var i = 0; i < 20; i++)
|
||||
|
||||
@@ -17,7 +17,7 @@ function preload() {
|
||||
function create() {
|
||||
|
||||
// This returns an array of all the image keys in the cache
|
||||
var images = game.cache.getImageKeys();
|
||||
var images = game.cache.getKeys(Phaser.Cache.IMAGE);
|
||||
|
||||
var test = game.add.group();
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ function create() {
|
||||
|
||||
game.stage.backgroundColor = '#0072bc';
|
||||
|
||||
text = game.add.bitmapText(200, 100, 'Bitmap Fonts!', { font: '64px Desyrel', align: 'center' });
|
||||
text = game.add.bitmapText(200, 100, 'desyrel','Bitmap Fonts!',64);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ function preload() {
|
||||
function create() {
|
||||
|
||||
// This returns an array of all the image keys in the cache
|
||||
var images = game.cache.getImageKeys();
|
||||
var images = game.cache.getKeys(Phaser.Cache.IMAGE);
|
||||
|
||||
// Now let's create some random sprites and enable them all for drag and 'bring to top'
|
||||
for (var i = 0; i < 20; i++)
|
||||
|
||||
@@ -11,6 +11,7 @@ function create() {
|
||||
|
||||
pic = game.add.sprite(0, 0, 'trsi');
|
||||
|
||||
|
||||
pic.cropEnabled = true;
|
||||
|
||||
pic.crop.width = 128;
|
||||
|
||||
@@ -1,23 +1,27 @@
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create });
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update : update });
|
||||
|
||||
function preload() {
|
||||
game.load.image('trsi', 'assets/pics/trsipic1_lazur.jpg');
|
||||
}
|
||||
|
||||
var pic;
|
||||
var cropRect;
|
||||
|
||||
function create() {
|
||||
|
||||
var pic = game.add.sprite(game.world.centerX, 550, 'trsi');
|
||||
pic = game.add.sprite(game.world.centerX, 550, 'trsi');
|
||||
|
||||
pic.anchor.setTo(0.5, 1);
|
||||
|
||||
// By default Sprites ignore the crop setting, you have to explicitly enable it like this:
|
||||
pic.cropEnabled = true;
|
||||
|
||||
// Set the crop rect width to zero
|
||||
pic.crop.width = 0;
|
||||
cropRect = {x : 0, y : 0 , width : 0, height : pic.height};
|
||||
|
||||
// Here we'll tween the crop rect, from a width of zero to full width, and back again
|
||||
game.add.tween(pic.crop).to( { width: pic.width }, 3000, Phaser.Easing.Bounce.Out, true, 0, 1000, true);
|
||||
// Here we'll tween the crop rect, from a width of zero to full width, and back again
|
||||
game.add.tween(cropRect).to( { width: pic.width }, 3000, Phaser.Easing.Bounce.Out, true, 0, 1000, true);
|
||||
|
||||
}
|
||||
|
||||
function update () {
|
||||
// the crop method takes a rectangle object as a parameter
|
||||
pic.crop(cropRect);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ var s;
|
||||
function create() {
|
||||
|
||||
s = game.add.sprite(game.world.centerX, game.world.centerY, 'bot');
|
||||
// s.anchor.setTo(0.5, 0.5);
|
||||
s.anchor.setTo(0.5, 0.5);
|
||||
s.scale.setTo(2, 2);
|
||||
|
||||
s.animations.add('run');
|
||||
@@ -41,8 +41,6 @@ function update() {
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.renderSpriteCorners(s, false, false);
|
||||
game.debug.renderSpriteInfo(s, 20, 32);
|
||||
|
||||
}
|
||||
|
||||
@@ -29,9 +29,9 @@ function update() {
|
||||
function render() {
|
||||
|
||||
game.debug.renderSpriteInfo(sprite, 32, 32);
|
||||
game.debug.renderText('angularVelocity: ' + sprite.body.angularVelocity, 32, 200);
|
||||
game.debug.renderText('angularAcceleration: ' + sprite.body.angularAcceleration, 32, 232);
|
||||
game.debug.renderText('angularDrag: ' + sprite.body.angularDrag, 32, 264);
|
||||
game.debug.renderText('deltaZ: ' + sprite.body.deltaZ(), 32, 296);
|
||||
// game.debug.renderText('angularVelocity: ' + sprite.body.angularVelocity, 32, 200);
|
||||
// game.debug.renderText('angularAcceleration: ' + sprite.body.angularAcceleration, 32, 232);
|
||||
// game.debug.renderText('angularDrag: ' + sprite.body.angularDrag, 32, 264);
|
||||
// game.debug.renderText('deltaZ: ' + sprite.body.deltaZ(), 32, 296);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,23 +1,30 @@
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create });
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create , update : update});
|
||||
|
||||
function preload() {
|
||||
game.load.image('trsi', 'assets/pics/trsipic1_lazur.jpg');
|
||||
}
|
||||
|
||||
var pic;
|
||||
var cropRect;
|
||||
|
||||
function create() {
|
||||
|
||||
var pic = game.add.sprite(game.world.centerX, 550, 'trsi');
|
||||
pic = game.add.sprite(game.world.centerX, 550, 'trsi');
|
||||
|
||||
pic.anchor.setTo(0.5, 1);
|
||||
|
||||
// By default Sprites ignore the crop setting, you have to explicitly enable it like this:
|
||||
pic.cropEnabled = true;
|
||||
|
||||
// Set the crop rect height to zero
|
||||
pic.crop.height = 0;
|
||||
|
||||
cropRect = {x : 0, y : 0 , width : pic.width, height : 0};
|
||||
|
||||
// Here we'll tween the crop rect, from a height of zero to full height, and back again
|
||||
game.add.tween(pic.crop).to( { height: pic.height }, 3000, Phaser.Easing.Bounce.Out, true, 0, 1000, true);
|
||||
game.add.tween(cropRect).to( { height: pic.height }, 3000, Phaser.Easing.Bounce.Out, true, 0, 1000, true);
|
||||
|
||||
}
|
||||
|
||||
function update () {
|
||||
// the crop method takes a rectangle object as a parameter
|
||||
pic.crop(cropRect);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -7,16 +7,16 @@ function preload() {
|
||||
|
||||
}
|
||||
|
||||
var text;
|
||||
var bpmText;
|
||||
|
||||
function create() {
|
||||
|
||||
text = game.add.bitmapText(200, 100, 'Phaser & Pixi\nrocking!', { font: '64px Desyrel', align: 'center' });
|
||||
bmpText = game.add.bitmapText(200, 100, 'desyrel','Phaser & Pixi \nrocking!',64);
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
text.setText('Phaser & Pixi\nrocking!\n' + Math.round(game.time.now));
|
||||
bmpText.setText('Phaser & Pixi\nrocking!\n' + Math.round(game.time.now));
|
||||
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ WebFontConfig = {
|
||||
function preload() {
|
||||
|
||||
// Load the Google WebFont Loader script
|
||||
game.load.script('webfont', '//ajax.googleapis.com/ajax/libs/webfont/1.4.7/webfont.js');
|
||||
game.load.script('webfont', 'http://ajax.googleapis.com/ajax/libs/webfont/1.4.7/webfont.js');
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -15,13 +15,14 @@ function preload() {
|
||||
function create() {
|
||||
|
||||
ball = game.add.sprite(400, 0, 'ball');
|
||||
|
||||
ball.body.gravity.y = 200;
|
||||
ball.body.bounce.y = 1;
|
||||
ball.physicsEnabled = true;
|
||||
|
||||
tilesprite = game.add.tileSprite(300, 450, 200, 100, 'starfield');
|
||||
tilesprite.body.immovable = true;
|
||||
tilesprite.body.setRectangle(200, 100, 0, 0);
|
||||
|
||||
tilesprite.physicsEnabled = true;
|
||||
// tilesprite.body.immovable = true;
|
||||
|
||||
// tilesprite.body.setRectangle(200, 100, 0, 0);
|
||||
|
||||
cursors = game.input.keyboard.createCursorKeys();
|
||||
|
||||
@@ -29,8 +30,6 @@ function create() {
|
||||
|
||||
function update() {
|
||||
|
||||
game.physics.collide(ball, tilesprite);
|
||||
|
||||
if (cursors.left.isDown)
|
||||
{
|
||||
tilesprite.x -= 8;
|
||||
@@ -55,6 +54,6 @@ function update() {
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.renderPhysicsBody(tilesprite.body);
|
||||
// game.debug.renderPhysicsBody(tilesprite);
|
||||
|
||||
}
|
||||
@@ -23,6 +23,7 @@ function create() {
|
||||
// The first parameter is how long to wait before the event fires. In this case 1 second (you could pass in 1000 as the value as well.)
|
||||
// The next two parameters are the function to call ('updateCounter') and the context under which that will happen.
|
||||
|
||||
|
||||
game.time.events.loop(Phaser.Timer.SECOND, updateCounter, this);
|
||||
|
||||
}
|
||||
@@ -31,7 +32,7 @@ function updateCounter() {
|
||||
|
||||
counter++;
|
||||
|
||||
text.content = 'Counter: ' + counter;
|
||||
text.setText('Counter: ' + counter);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -33,9 +33,7 @@ function createBall() {
|
||||
|
||||
var ball = game.add.sprite(game.world.randomX, 0, 'ball');
|
||||
|
||||
ball.body.gravity.y = 200;
|
||||
ball.body.bounce.y = 0.5;
|
||||
ball.body.collideWorldBounds = true;
|
||||
ball.physicsEnabled = true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ function updateCounter(idx) {
|
||||
|
||||
counters[idx]++;
|
||||
|
||||
text[idx].content = 'Counter ' + idx + ' = ' + counters[idx];
|
||||
text[idx].setText('Counter ' + idx + ' = ' + counters[idx]);
|
||||
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ function removeCounter() {
|
||||
|
||||
// Just updates the text
|
||||
text[i].style.fill = '#3344aa';
|
||||
text[i].content = 'Counter ' + i + ' removed';
|
||||
text[i].setText('Counter ' + i + ' removed');
|
||||
i--;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ WebFontConfig = {
|
||||
function preload() {
|
||||
|
||||
// Load the Google WebFont Loader script
|
||||
game.load.script('webfont', '//ajax.googleapis.com/ajax/libs/webfont/1.4.7/webfont.js');
|
||||
game.load.script('webfont', 'http://ajax.googleapis.com/ajax/libs/webfont/1.4.7/webfont.js');
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user