mirror of
https://github.com/wassname/phaser.git
synced 2026-07-16 01:20:13 +08:00
Much more stable collision, just need to refactor the Tilemap handling - see if I can optimise it a bit too.
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
$title = "Camera Cull";
|
||||
require('../head.php');
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
(function () {
|
||||
|
||||
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,70 @@
|
||||
<?php
|
||||
$title = "Moving the Camera";
|
||||
require('../head.php');
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
(function () {
|
||||
|
||||
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.setSize(2000, 2000);
|
||||
|
||||
for (var i = 0; i < 50; i++)
|
||||
{
|
||||
var s = game.add.sprite(game.world.randomX, game.world.randomY, 'mushroom');
|
||||
s.scrollFactor.setTo(0.5, 0.5);
|
||||
}
|
||||
|
||||
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');
|
||||
s.scrollFactor.setTo(2, 2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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,72 @@
|
||||
<?php
|
||||
$title = "Vertical bounding box";
|
||||
require('../head.php');
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
(function () {
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.image('atari', 'assets/sprites/atari130xe.png');
|
||||
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
|
||||
|
||||
}
|
||||
|
||||
var sprite1;
|
||||
var sprite2;
|
||||
|
||||
function create() {
|
||||
|
||||
game.stage.backgroundColor = '#2d2d2d';
|
||||
|
||||
sprite1 = game.add.sprite(300, 50, 'atari');
|
||||
sprite1.name = 'atari';
|
||||
sprite1.body.velocity.y = 100;
|
||||
|
||||
// This adjusts the collision body size.
|
||||
// 100x100 is the new width/height.
|
||||
// See the offset bounding box for another example.
|
||||
sprite1.body.setSize(220, 50, 0, 0);
|
||||
|
||||
sprite2 = game.add.sprite(400, 500, 'mushroom');
|
||||
sprite2.name = 'mushroom';
|
||||
sprite2.body.immovable = true;
|
||||
// sprite2.body.velocity.x = -100;
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
// object1, object2, collideCallback, processCallback, callbackContext
|
||||
game.physics.collide(sprite1, sprite2, collisionHandler, null, this);
|
||||
|
||||
}
|
||||
|
||||
function collisionHandler (obj1, obj2) {
|
||||
|
||||
game.stage.backgroundColor = '#992d2d';
|
||||
|
||||
console.log(obj1.name + ' collided with ' + obj2.name);
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.renderSpriteInfo(sprite1, 32, 32);
|
||||
game.debug.renderSpriteCollision(sprite1, 32, 400);
|
||||
|
||||
game.debug.renderSpriteBody(sprite1);
|
||||
game.debug.renderSpriteBody(sprite2);
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
</script>
|
||||
|
||||
<?php
|
||||
require('../foot.php');
|
||||
?>
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
(function () {
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update, render: render });
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create });
|
||||
|
||||
var p;
|
||||
|
||||
@@ -19,23 +19,17 @@
|
||||
|
||||
function create() {
|
||||
|
||||
game.stage.backgroundColor = 0x337799;
|
||||
game.stage.backgroundColor = 0x2d2d2d;
|
||||
|
||||
p = game.add.sprite(0, 0, 'diamond');
|
||||
p = game.add.sprite(100, 100, 'diamond');
|
||||
|
||||
game.add.tween(p).to({ x: 700 }, 1000, Phaser.Easing.Linear.None, true)
|
||||
game.add.tween(p).to({ x: 600 }, 2000, Phaser.Easing.Linear.None, true)
|
||||
.to({ y: 300 }, 1000, Phaser.Easing.Linear.None)
|
||||
.to({ x: 0 }, 1000, Phaser.Easing.Linear.None)
|
||||
.to({ y: 0 }, 1000, Phaser.Easing.Linear.None)
|
||||
.to({ x: 100 }, 2000, Phaser.Easing.Linear.None)
|
||||
.to({ y: 100 }, 1000, Phaser.Easing.Linear.None)
|
||||
.loop();
|
||||
}
|
||||
|
||||
function update() {
|
||||
}
|
||||
|
||||
function render() {
|
||||
}
|
||||
|
||||
})();
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user