mirror of
https://github.com/wassname/phaser.git
synced 2026-08-11 11:23:06 +08:00
Small new demo and refactored collision list - now far less comparisons to perform!
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>phaser.js - oh balls</title>
|
||||
<script src="phaser-min.js"></script>
|
||||
<style type="text/css">
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: sans-serif;
|
||||
}
|
||||
|
||||
p {
|
||||
padding: 16px;
|
||||
margin: 0px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="game"></div>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
(function () {
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'game', { preload: preload, create: create, update: update });
|
||||
|
||||
var p;
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.spritesheet('balls', 'assets/balls.png', 17, 17);
|
||||
|
||||
}
|
||||
|
||||
function create() {
|
||||
|
||||
game.stage.backgroundColor = 0x337799;
|
||||
|
||||
p = game.add.emitter(100, 100, 250);
|
||||
p.makeParticles('balls', [0,1,2,3,4,5]);
|
||||
p.minParticleSpeed.setTo(-100, -100);
|
||||
p.maxParticleSpeed.setTo(100, -200);
|
||||
p.gravity = 10;
|
||||
p.start(false, 3000, 10);
|
||||
|
||||
game.add.tween(p).to({ x: 700 }, 1000, Phaser.Easing.Quadratic.InOut, true, 0, 1000, true);
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
p.y = game.input.y;
|
||||
|
||||
if (p.y < 100)
|
||||
{
|
||||
p.y = 100;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
</script>
|
||||
|
||||
<p>Mouse to move</p>
|
||||
<p>Created with <a href="https://github.com/photonstorm/phaser">Phaser 1.0</a> by <a href="https://twitter.com/photonstorm">@photonstorm</a></p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
+15
-12
@@ -19,12 +19,12 @@
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.image('carrot', 'assets/sprites/carrot.png');
|
||||
game.load.image('star', 'assets/misc/star_particle.png');
|
||||
game.load.image('diamond', 'assets/sprites/diamond.png');
|
||||
game.load.image('dude', 'assets/sprites/phaser-dude.png');
|
||||
game.load.image('coke', 'assets/sprites/cokecan.png');
|
||||
game.load.atlasJSONHash('pixies', 'assets/sprites/pixi_monsters.png', 'assets/sprites/pixi_monsters.json');
|
||||
// game.load.image('carrot', 'assets/sprites/carrot.png');
|
||||
// game.load.image('star', 'assets/misc/star_particle.png');
|
||||
// game.load.image('diamond', 'assets/sprites/diamond.png');
|
||||
// game.load.image('dude', 'assets/sprites/phaser-dude.png');
|
||||
// game.load.image('coke', 'assets/sprites/cokecan.png');
|
||||
// game.load.atlasJSONHash('pixies', 'assets/sprites/pixi_monsters.png', 'assets/sprites/pixi_monsters.json');
|
||||
game.load.spritesheet('balls', 'assets/sprites/balls.png', 17, 17);
|
||||
|
||||
}
|
||||
@@ -33,18 +33,18 @@
|
||||
|
||||
game.stage.backgroundColor = 0x337799;
|
||||
|
||||
p = game.add.emitter(200, 100, 250);
|
||||
p = game.add.emitter(100, 100, 250);
|
||||
|
||||
// p.width = 200;
|
||||
// p.height = 200;
|
||||
|
||||
// keys, frames, quantity, collide
|
||||
// p.makeParticles(['diamond', 'carrot', 'star']);
|
||||
// p.makeParticles('balls', [0,1,2,3,4,5]);
|
||||
p.makeParticles('pixies', [0,1,2,3]);
|
||||
p.makeParticles('balls', [0,1,2,3,4,5]);
|
||||
// p.makeParticles('pixies', [0,1,2,3]);
|
||||
|
||||
p.minParticleScale = 0.1;
|
||||
p.maxParticleScale = 0.5;
|
||||
// p.minParticleScale = 0.1;
|
||||
// p.maxParticleScale = 0.5;
|
||||
|
||||
// Steady constant stream at 250ms delay and 10 seconds lifespan
|
||||
// p.start(false, 10000, 250, 100);
|
||||
@@ -56,11 +56,14 @@
|
||||
p.gravity = 10;
|
||||
p.start(false, 3000, 10);
|
||||
|
||||
game.add.tween(p).to({ emitX: 400 }, 1000, Phaser.Easing.Quadratic.InOut, true, 0, 1000, true);
|
||||
game.add.tween(p).to({ x: 700 }, 1000, Phaser.Easing.Quadratic.InOut, true, 0, 1000, true);
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
p.y = game.math.min(100, game.input.y);
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
+11
-17
@@ -12,7 +12,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, update: update });
|
||||
|
||||
function preload() {
|
||||
|
||||
@@ -22,10 +22,8 @@
|
||||
|
||||
}
|
||||
|
||||
var p;
|
||||
var balls;
|
||||
var map;
|
||||
var test = [];
|
||||
var g;
|
||||
|
||||
function create() {
|
||||
|
||||
@@ -36,22 +34,21 @@
|
||||
map = game.add.tilemap(0, 0, 'level1');
|
||||
map.setCollisionByIndex([9,10,11,14,15,16,18,19,22,23,24,32,37,38], true, true, true, true);
|
||||
|
||||
p = game.add.emitter(300, 50, 500);
|
||||
p.bounce = 0.5;
|
||||
p.makeParticles('balls', [0,1,2,3,4,5], 500, 1);
|
||||
p.minParticleSpeed.setTo(-150, 150);
|
||||
p.maxParticleSpeed.setTo(100, 100);
|
||||
p.gravity = 8;
|
||||
p.start(false, 5000, 50);
|
||||
balls = game.add.emitter(300, 50, 500);
|
||||
balls.bounce = 0.5;
|
||||
balls.makeParticles('balls', [0,1,2,3,4,5], 500, 1);
|
||||
balls.minParticleSpeed.setTo(-150, 150);
|
||||
balls.maxParticleSpeed.setTo(100, 100);
|
||||
balls.gravity = 8;
|
||||
balls.start(false, 5000, 50);
|
||||
|
||||
game.add.tween(p).to({ x: 4000 }, 7500, Phaser.Easing.Quadratic.InOut, true, 0, 1000, true);
|
||||
game.add.tween(balls).to({ x: 4000 }, 7500, Phaser.Easing.Sinusoidal.InOut, true, 0, 1000, true);
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
map.collide(g);
|
||||
map.collide(p);
|
||||
game.physics.collide(balls, map);
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
@@ -73,9 +70,6 @@
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
}
|
||||
|
||||
})();
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user