Lots of new examples and updates.

This commit is contained in:
photonstorm
2013-10-09 04:31:08 +01:00
parent 1c577d3674
commit 83a00862be
42 changed files with 829 additions and 280 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 233 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 232 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 250 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 245 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 296 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 299 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 248 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 251 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 270 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 678 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

+84
View File
@@ -0,0 +1,84 @@
{"frames": [
{
"filename": "shadow",
"frame": {"x":0,"y":0,"w":80,"h":80},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":80,"h":80},
"sourceSize": {"w":80,"h":80}
},
{
"filename": "tank1",
"frame": {"x":190,"y":52,"w":54,"h":52},
"rotated": false,
"trimmed": true,
"spriteSourceSize": {"x":3,"y":5,"w":54,"h":52},
"sourceSize": {"w":64,"h":64}
},
{
"filename": "tank2",
"frame": {"x":136,"y":52,"w":54,"h":52},
"rotated": false,
"trimmed": true,
"spriteSourceSize": {"x":3,"y":5,"w":54,"h":52},
"sourceSize": {"w":64,"h":64}
},
{
"filename": "tank3",
"frame": {"x":80,"y":54,"w":56,"h":54},
"rotated": false,
"trimmed": true,
"spriteSourceSize": {"x":2,"y":4,"w":56,"h":54},
"sourceSize": {"w":64,"h":64}
},
{
"filename": "tank4",
"frame": {"x":190,"y":0,"w":54,"h":52},
"rotated": false,
"trimmed": true,
"spriteSourceSize": {"x":3,"y":5,"w":54,"h":52},
"sourceSize": {"w":64,"h":64}
},
{
"filename": "tank5",
"frame": {"x":136,"y":0,"w":54,"h":52},
"rotated": false,
"trimmed": true,
"spriteSourceSize": {"x":3,"y":5,"w":54,"h":52},
"sourceSize": {"w":64,"h":64}
},
{
"filename": "tank6",
"frame": {"x":80,"y":0,"w":56,"h":54},
"rotated": false,
"trimmed": true,
"spriteSourceSize": {"x":2,"y":4,"w":56,"h":54},
"sourceSize": {"w":64,"h":64}
},
{
"filename": "tracks",
"frame": {"x":48,"y":80,"w":24,"h":12},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":24,"h":12},
"sourceSize": {"w":24,"h":12}
},
{
"filename": "turret",
"frame": {"x":0,"y":80,"w":48,"h":28},
"rotated": false,
"trimmed": true,
"spriteSourceSize": {"x":1,"y":2,"w":48,"h":28},
"sourceSize": {"w":50,"h":32}
}],
"meta": {
"app": "http://www.codeandweb.com/texturepacker ",
"version": "1.0",
"image": "tanks.png",
"format": "RGBA8888",
"size": {"w":244,"h":108},
"scale": "1",
"smartupdate": "$TexturePacker:SmartUpdate:99b2f74fa157c5b63e72b0d68be078b4:1/1$"
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

+172
View File
@@ -0,0 +1,172 @@
<?xml version="1.0" encoding="UTF-8"?>
<data version="1.0">
<struct type="Settings">
<key>fileFormatVersion</key>
<int>1</int>
<key>variation</key>
<string>main</string>
<key>verbose</key>
<false/>
<key>autoSDSettings</key>
<array/>
<key>allowRotation</key>
<false/>
<key>quiet</key>
<false/>
<key>premultiplyAlpha</key>
<false/>
<key>shapeDebug</key>
<false/>
<key>dpi</key>
<uint>72</uint>
<key>dataFormat</key>
<string>json-array</string>
<key>textureFileName</key>
<filename>tanks.png</filename>
<key>flipPVR</key>
<false/>
<key>ditherType</key>
<enum type="SettingsBase::DitherType">NearestNeighbour</enum>
<key>backgroundColor</key>
<uint>0</uint>
<key>libGdx</key>
<struct type="LibGDX">
<key>filtering</key>
<struct type="LibGDXFiltering">
<key>x</key>
<enum type="LibGDXFiltering::Filtering">Linear</enum>
<key>y</key>
<enum type="LibGDXFiltering::Filtering">Linear</enum>
</struct>
</struct>
<key>shapePadding</key>
<uint>0</uint>
<key>jpgQuality</key>
<uint>80</uint>
<key>pngOptimizationLevel</key>
<uint>0</uint>
<key>textureSubPath</key>
<string></string>
<key>textureFormat</key>
<enum type="SettingsBase::TextureFormat">png</enum>
<key>borderPadding</key>
<uint>0</uint>
<key>maxTextureSize</key>
<QSize>
<key>width</key>
<int>512</int>
<key>height</key>
<int>512</int>
</QSize>
<key>fixedTextureSize</key>
<QSize>
<key>width</key>
<int>-1</int>
<key>height</key>
<int>-1</int>
</QSize>
<key>reduceBorderArtifacts</key>
<false/>
<key>algorithmSettings</key>
<struct type="AlgorithmSettings">
<key>algorithm</key>
<enum type="AlgorithmSettings::AlgorithmId">MaxRects</enum>
<key>freeSizeMode</key>
<enum type="AlgorithmSettings::AlgorithmFreeSizeMode">Best</enum>
<key>sizeConstraints</key>
<enum type="AlgorithmSettings::SizeConstraints">AnySize</enum>
<key>forceSquared</key>
<false/>
<key>forceWordAligned</key>
<false/>
<key>maxRects</key>
<struct type="AlgorithmMaxRectsSettings">
<key>heuristic</key>
<enum type="AlgorithmMaxRectsSettings::Heuristic">Best</enum>
</struct>
<key>basic</key>
<struct type="AlgorithmBasicSettings">
<key>sortBy</key>
<enum type="AlgorithmBasicSettings::SortBy">Name</enum>
<key>order</key>
<enum type="AlgorithmBasicSettings::Order">Ascending</enum>
</struct>
</struct>
<key>andEngine</key>
<struct type="AndEngine">
<key>minFilter</key>
<enum type="AndEngine::MinFilter">Linear</enum>
<key>packageName</key>
<string>Texture</string>
<key>javaFileName</key>
<filename>tanks.java</filename>
<key>wrap</key>
<struct type="AndEngineWrap">
<key>s</key>
<enum type="AndEngineWrap::Wrap">Clamp</enum>
<key>t</key>
<enum type="AndEngineWrap::Wrap">Clamp</enum>
</struct>
<key>magFilter</key>
<enum type="AndEngine::MagFilter">MagLinear</enum>
</struct>
<key>dataFileName</key>
<filename>tanks.json</filename>
<key>multiPack</key>
<false/>
<key>mainExtension</key>
<string></string>
<key>forceIdenticalLayout</key>
<false/>
<key>outputFormat</key>
<enum type="SettingsBase::OutputFormat">RGBA8888</enum>
<key>contentProtection</key>
<struct type="ContentProtection">
<key>key</key>
<string></string>
</struct>
<key>autoAliasEnabled</key>
<true/>
<key>trimSpriteNames</key>
<true/>
<key>globalSpriteSettings</key>
<struct type="SpriteSettings">
<key>scale</key>
<double>1</double>
<key>scaleMode</key>
<enum type="ScaleMode">Smooth</enum>
<key>innerPadding</key>
<uint>0</uint>
<key>extrude</key>
<uint>0</uint>
<key>trimThreshold</key>
<uint>1</uint>
<key>trimMode</key>
<enum type="SpriteSettings::TrimMode">Trim</enum>
<key>heuristicMask</key>
<false/>
</struct>
<key>fileList</key>
<array>
<filename>shadow.png</filename>
<filename>tank1.png</filename>
<filename>tank2.png</filename>
<filename>tank3.png</filename>
<filename>tank4.png</filename>
<filename>tank5.png</filename>
<filename>tank6.png</filename>
<filename>tracks.png</filename>
<filename>turret.png</filename>
</array>
<key>ignoreFileList</key>
<array/>
<key>replaceList</key>
<array/>
<key>ignoredWarnings</key>
<array/>
<key>commonDivisorX</key>
<uint>1</uint>
<key>commonDivisorY</key>
<uint>1</uint>
</struct>
</data>
Binary file not shown.

After

Width:  |  Height:  |  Size: 468 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 573 B

+170
View File
@@ -0,0 +1,170 @@
<?php
$title = "Tanks";
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.atlas('tank', 'assets/games/tanks/tanks.png', 'assets/games/tanks/tanks.json');
game.load.image('bullet', 'assets/sprites/enemy-bullet.png');
game.load.image('earth', 'assets/games/tanks/scorched_earth.png');
}
var tank;
var turret;
var shadow;
var currentSpeed = 0;
var land;
var cursors;
var bullets;
var fireRate = 100;
var nextFire = 0;
function create() {
// Resize our game world to be a 2000x2000 square
// game.world.setBounds(-1000, -1000, 2000, 2000);
game.world.setBounds(0, 0, 1000, 1000);
console.log(game.world.bounds.right, 'bot', this.game.world.bounds.bottom);
console.log(game.camera.bounds.right, 'cbot', this.game.camera.bounds.bottom);
// Our tiled scrolling background
land = game.add.tileSprite(0, 0, 800, 600, 'earth');
land.fixedToCamera = true;
// A shadow below our tank
shadow = game.add.sprite(0, 0, 'tank', 'shadow');
shadow.anchor.setTo(0.5, 0.5);
// The base of our tank
tank = game.add.sprite(0, 0, 'tank', 'tank1');
tank.anchor.setTo(0.5, 0.5);
tank.animations.add('move', ['tank1', 'tank2', 'tank3', 'tank4', 'tank5', 'tank6'], 20, true);
tank.play('move');
// This will force it to decelerate and limit its speed
tank.body.drag.setTo(200, 200);
tank.body.maxVelocity.setTo(400, 400);
tank.body.collideWorldBounds = true;
// Our bullet group
bullets = game.add.group();
bullets.createMultiple(50, 'bullet');
bullets.setAll('anchor.x', 0.5);
bullets.setAll('anchor.y', 0.5);
bullets.setAll('outOfBoundsKill', true);
// Finally the turret that we place on-top of the tank body
turret = game.add.sprite(0, 0, 'tank', 'turret');
turret.anchor.setTo(0.5, 0.5);
game.camera.follow(tank);
// game.camera.deadzone = new Phaser.Rectangle(100, 100, 600, 400);
cursors = game.input.keyboard.createCursorKeys();
}
function update() {
if (cursors.left.isDown)
{
tank.angle -= 4;
}
else if (cursors.right.isDown)
{
tank.angle += 4;
}
if (cursors.up.isDown)
{
// The speed we'll travel at
currentSpeed = 300;
}
else
{
if (currentSpeed > 0)
{
currentSpeed -= 4;
}
}
if (currentSpeed > 0)
{
game.physics.velocityFromRotation(tank.rotation, currentSpeed, tank.body.velocity);
// Scroll the background (note the negative offset to ensure it moves the direction we're facing, not coming from)
// land.tilePosition.x -= (tank.body.velocity.x / 50);
// land.tilePosition.y -= (tank.body.velocity.y / 50);
}
land.tilePosition.x = -game.camera.x;
land.tilePosition.y = -game.camera.y;
// Position all the parts and align rotations
shadow.x = tank.x;
shadow.y = tank.y;
shadow.rotation = tank.rotation;
turret.x = tank.x;
turret.y = tank.y;
turret.rotation = game.physics.angleToPointer(turret);
if (game.input.activePointer.isDown)
{
// Boom!
fire();
}
}
function fire() {
if (game.time.now > nextFire && bullets.countDead() > 0)
{
nextFire = game.time.now + fireRate;
var bullet = bullets.getFirstDead();
bullet.reset(turret.x, turret.y);
game.physics.moveToPointer(bullet, 1000);
}
}
function render() {
// game.debug.renderText('Active Bullets: ' + bullets.countLiving() + ' / ' + bullets.total, 32, 32);
// game.debug.renderText('sr: ' + tank.body.right, 32, 100);
// game.debug.renderText('sb: ' + tank.body.bottom, 32, 132);
game.debug.renderSpriteCorners(tank, true, true);
game.debug.renderCameraInfo(game.camera, 500, 32);
game.debug.renderLocalTransformInfo(tank, 32, 32);
game.debug.renderWorldTransformInfo(tank, 32, 200);
// game.debug.renderSpriteInfo(sprite, 32, 450);
}
</script>
<?php
require('../foot.php');
?>
@@ -0,0 +1,41 @@
<?php
$title = "Accelerate to the Active Pointer";
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('arrow', 'assets/sprites/arrow.png');
}
var sprite;
function create() {
game.stage.backgroundColor = '#0072bc';
sprite = game.add.sprite(400, 300, 'arrow');
sprite.anchor.setTo(0.5, 0.5);
}
function update() {
sprite.rotation = game.physics.accelerateToPointer(sprite, this.game.input.activePointer, 500, 500, 500);
}
function render() {
game.debug.renderSpriteInfo(sprite, 32, 32);
}
</script>
<?php
require('../foot.php');
?>
+51
View File
@@ -0,0 +1,51 @@
<?php
$title = "Angle between two Sprites";
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('arrow', 'assets/sprites/longarrow.png');
game.load.image('ball', 'assets/sprites/pangball.png');
}
var arrow;
var target;
function create() {
game.stage.backgroundColor = '#0072bc';
arrow = game.add.sprite(200, 250, 'arrow');
arrow.anchor.setTo(0.1, 0.5);
target = game.add.sprite(600, 400, 'ball');
target.anchor.setTo(0.5, 0.5);
target.inputEnabled = true;
target.input.enableDrag(true);
}
function update() {
arrow.rotation = game.physics.angleBetween(arrow, target);
}
function render() {
game.debug.renderText("Drag the ball", 32, 32);
game.debug.renderSpriteInfo(arrow, 32, 100);
}
</script>
<?php
require('../foot.php');
?>
+1 -1
View File
@@ -26,7 +26,7 @@
// This will update the sprite.rotation so that it points to the currently active pointer
// On a Desktop that is the mouse, on mobile the most recent finger press.
sprite.rotation = game.physics.angleBetweenPointer(sprite);
sprite.rotation = game.physics.angleToPointer(sprite);
}
+5 -11
View File
@@ -5,7 +5,7 @@
<script type="text/javascript">
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render: render });
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update });
function preload() {
game.load.image('arrow', 'assets/sprites/longarrow.png');
@@ -39,16 +39,10 @@
// This will update the sprite.rotation so that it points to the currently active pointer
// On a Desktop that is the mouse, on mobile the most recent finger press.
sprite1.rotation = game.physics.angleBetweenPointer(sprite1);
sprite2.rotation = game.physics.angleBetweenPointer(sprite2);
sprite3.rotation = game.physics.angleBetweenPointer(sprite3);
sprite4.rotation = game.physics.angleBetweenPointer(sprite4);
}
function render() {
// game.debug.renderSpriteInfo(sprite1, 32, 32);
sprite1.rotation = game.physics.angleToPointer(sprite1);
sprite2.rotation = game.physics.angleToPointer(sprite2);
sprite3.rotation = game.physics.angleToPointer(sprite3);
sprite4.rotation = game.physics.angleToPointer(sprite4);
}
@@ -1,5 +1,5 @@
<?php
$title = "Shoot at the Mouse";
$title = "Shoot the Pointer";
require('../head.php');
?>
@@ -8,8 +8,10 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.image('arrow', 'assets/sprites/arrow.png');
game.load.image('bullet', 'assets/sprites/purple_ball.png');
}
var sprite;
@@ -35,7 +37,7 @@
function update() {
sprite.rotation = game.physics.angleBetweenPointer(sprite);
sprite.rotation = game.physics.angleToPointer(sprite);
if (game.input.activePointer.isDown)
{
@@ -54,8 +56,7 @@
bullet.reset(sprite.x, sprite.y);
bullet.rotation = game.physics.moveTowardsPointer(bullet, 300);
bullet.rotation = game.physics.moveToPointer(bullet, 300);
}
}
@@ -63,9 +64,7 @@
function render() {
game.debug.renderText('Active Bullets: ' + bullets.countLiving() + ' / ' + bullets.total, 32, 32);
game.debug.renderSpriteInfo(sprite, 32, 450);
game.debug.renderSpriteCorners(sprite);
}