mirror of
https://github.com/wassname/phaser.git
synced 2026-08-15 12:45:11 +08:00
Added Sprite.fixedToCamera, fixed Angular Velocity and Acceleration, fixed jittery Camera, added skipQuadTree flag and created lots more examples.
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
$title = "Cursor Key Movement";
|
||||
require('../head.php');
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
window.onload = function () {
|
||||
|
||||
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.AUTO, '', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.stage.backgroundColor = '#007236';
|
||||
|
||||
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
|
||||
game.load.image('phaser', 'assets/sprites/sonic_havok_sanity.png');
|
||||
|
||||
}
|
||||
|
||||
var cursors;
|
||||
|
||||
function create() {
|
||||
|
||||
// Modify the world and camera bounds
|
||||
game.world.setBounds(-1000, -1000, 2000, 2000);
|
||||
|
||||
for (var i = 0; i < 100; i++)
|
||||
{
|
||||
game.add.sprite(game.world.randomX, game.world.randomY, 'mushroom');
|
||||
}
|
||||
|
||||
// This will create a new object called "cursors", inside it will contain 4 objects: up, down, left and right.
|
||||
// These are all Phaser.Key objects, so anything you can do with a Key object you can do with these.
|
||||
cursors = game.input.keyboard.createCursorKeys();
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
// For example this checks if the up or down keys are pressed and moves the camera accordingly.
|
||||
if (cursors.up.isDown)
|
||||
{
|
||||
// If the shift key is also pressed then the world is rotated
|
||||
if (cursors.up.shiftKey)
|
||||
{
|
||||
game.world.rotation += 0.05;
|
||||
}
|
||||
else
|
||||
{
|
||||
game.camera.y -= 4;
|
||||
}
|
||||
}
|
||||
else if (cursors.down.isDown)
|
||||
{
|
||||
if (cursors.down.shiftKey)
|
||||
{
|
||||
game.world.rotation -= 0.05;
|
||||
}
|
||||
else
|
||||
{
|
||||
game.camera.y += 4;
|
||||
}
|
||||
}
|
||||
|
||||
if (cursors.left.isDown)
|
||||
{
|
||||
game.camera.x -= 4;
|
||||
}
|
||||
else if (cursors.right.isDown)
|
||||
{
|
||||
game.camera.x += 4;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.renderCameraInfo(game.camera, 32, 32);
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
</script>
|
||||
|
||||
<?php
|
||||
require('../foot.php');
|
||||
?>
|
||||
Reference in New Issue
Block a user