phaser/examples/input/game scale.js

63 lines
1.3 KiB
JavaScript
Raw Normal View History

2013-10-22 02:58:20 +00:00
var game = new Phaser.Game(320, 240, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
// This sets a limit on the up-scale
game.stage.scale.maxWidth = 800;
game.stage.scale.maxHeight = 600;
// Then we tell Phaser that we want it to scale up to whatever the browser can handle, but to do it proportionally
game.stage.scaleMode = Phaser.StageScaleMode.SHOW_ALL;
game.load.image('melon', 'assets/sprites/melon.png');
}
2014-02-21 17:58:52 +00:00
var cursors;
2013-10-22 02:58:20 +00:00
function create() {
//We increase the size of our game world
game.world.setBounds(0,0,2000, 2000);
for (var i = 0; i < 1000; i++)
{
//And spread some sprites inside it
game.add.sprite(game.world.randomX, game.world.randomY, 'melon');
}
2014-02-21 17:58:52 +00:00
cursors = game.input.keyboard.createCursorKeys();
2013-10-22 02:58:20 +00:00
}
function update() {
//This allows us to move the game camera using the keyboard
2014-02-21 17:58:52 +00:00
if (cursors.left.isDown)
2013-10-22 02:58:20 +00:00
{
game.camera.x -= 4;
}
2014-02-21 17:58:52 +00:00
else if (cursors.right.isDown)
2013-10-22 02:58:20 +00:00
{
game.camera.x += 4;
}
2014-02-21 17:58:52 +00:00
if (cursors.up.isDown)
2013-10-22 02:58:20 +00:00
{
game.camera.y -= 4;
}
2014-02-21 17:58:52 +00:00
else if (cursors.down.isDown)
2013-10-22 02:58:20 +00:00
{
game.camera.y += 4;
}
}
function render() {
game.debug.inputInfo(16, 16);
2013-10-22 02:58:20 +00:00
}