mirror of
https://github.com/wassname/phaser.git
synced 2026-07-23 13:00:41 +08:00
Group nearly done. Sprite.anchor appears to be broken though, must fix.
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 675 B |
@@ -0,0 +1,81 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>phaser.js - a new beginning</title>
|
||||
<?php
|
||||
require('js.php');
|
||||
?>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<textarea id="output" style="width: 1400px; height: 600px"></textarea>
|
||||
<br />
|
||||
<input type="button" id="grab" value="Grab" />
|
||||
<input type="button" id="refresh" value="Refresh" />
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
var game = new Phaser.Game(50, 31, Phaser.CANVAS, '', { preload: preload, create: create });
|
||||
|
||||
function preload() {
|
||||
game.load.image('piccie', 'assets/bd/burd.png');
|
||||
}
|
||||
|
||||
var logo;
|
||||
var args;
|
||||
|
||||
function create() {
|
||||
|
||||
logo = game.add.sprite(0, 0, 'piccie');
|
||||
|
||||
document.getElementById('grab').onclick = canvasToConsole;
|
||||
document.getElementById('refresh').onclick = refreshConsole;
|
||||
|
||||
}
|
||||
|
||||
function refreshConsole () {
|
||||
|
||||
args[0] = document.getElementById('output').value;
|
||||
console.clear();
|
||||
console.log.apply(console, args);
|
||||
console.log(args.toString());
|
||||
|
||||
}
|
||||
|
||||
function canvasToConsole () {
|
||||
|
||||
var txt = "";
|
||||
var prev;
|
||||
args = [""];
|
||||
var lfb = game.renderer.context.getImageData(0, 0, game.width, game.height).data;
|
||||
|
||||
for (var i = 0, j = 0; i < 1500; i++, j++)
|
||||
{
|
||||
if (!(i % 50)) // if(i && !(i % 50)) if don't like to start with a "\n"
|
||||
txt += prev = "\n";
|
||||
|
||||
var col = "background: rgb(" + [lfb[j++], lfb[j++], lfb[j++]] + ")";
|
||||
if (col == prev)
|
||||
{
|
||||
txt += " ";
|
||||
}
|
||||
else
|
||||
{
|
||||
txt += "%c ";
|
||||
args.push(col);
|
||||
prev = col;
|
||||
}
|
||||
}
|
||||
|
||||
args[0] = txt;
|
||||
document.getElementById('output').innerText = args[0];
|
||||
console.clear();
|
||||
console.log.apply(console, args);
|
||||
// console.log(args[0]);
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
+33
-7
@@ -16,6 +16,7 @@
|
||||
|
||||
function preload() {
|
||||
game.load.image('diamond', 'assets/sprites/diamond.png');
|
||||
game.load.image('carrot', 'assets/sprites/carrot.png');
|
||||
}
|
||||
|
||||
var g;
|
||||
@@ -24,26 +25,51 @@
|
||||
|
||||
function create() {
|
||||
|
||||
g = new Phaser.Group(game, 'aliens');
|
||||
t = game.add.sprite(100, 100, 'carrot');
|
||||
t.name = 'c0';
|
||||
t.body.bounce.y = Math.random();
|
||||
t.body.collideWorldBounds = true;
|
||||
|
||||
g = game.add.group();
|
||||
// g.x = 400;
|
||||
// g.y = 300;
|
||||
// g._container.anchor.x = 0.5;
|
||||
// g._container.anchor.y = 0.5;
|
||||
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
s = g.createSprite(100 + i * 64, 300, 'diamond');
|
||||
s.name = 'diamond' + i;
|
||||
s.body.collideWorldBounds = true;
|
||||
s.body.bounce.y = Math.random();
|
||||
var x = (i * 64);
|
||||
s = g.create(x, 0, 'diamond');
|
||||
s.name = 'd' + i;
|
||||
s.anchor.setTo(0.5, 0.5);
|
||||
}
|
||||
|
||||
g.getRandom().y += 200;
|
||||
// g.forEach(setAlpha, this);
|
||||
|
||||
//g.setAll('body.velocity.y', 250);
|
||||
// g.dump();
|
||||
|
||||
// g.replace(s, t);
|
||||
|
||||
// g.dump();
|
||||
|
||||
// g.callAll('dump', game, 123, 456, 789);
|
||||
|
||||
// g.getRandom().y += 200;
|
||||
|
||||
// g.setAll('body.velocity.y', 250);
|
||||
// g.divideAll('y', 2);
|
||||
// g.multiplyAll('y', 3);
|
||||
|
||||
}
|
||||
|
||||
function setAlpha (sprite) {
|
||||
sprite.alpha = 0.4;
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
// g.addAll('angle', 10);
|
||||
g.angle++;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>phaser.js - a new beginning</title>
|
||||
<?php
|
||||
require('js.php');
|
||||
?>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<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('alien', 'assets/sprites/space-baddie.png');
|
||||
game.load.image('ship', 'assets/sprites/shmup-ship.png');
|
||||
}
|
||||
|
||||
var player;
|
||||
var aliens;
|
||||
|
||||
function create() {
|
||||
|
||||
player = game.add.sprite(400, 500, 'ship');
|
||||
// player.anchor.setTo(0.5, 0.5);
|
||||
|
||||
aliens = game.add.group();
|
||||
|
||||
for (var y = 0; y < 4; y++)
|
||||
{
|
||||
for (var x = 0; x < 10; x++)
|
||||
{
|
||||
aliens.create(x * 48, y * 64, 'alien');
|
||||
}
|
||||
}
|
||||
|
||||
aliens.x = 100;
|
||||
|
||||
var tween = game.add.tween(aliens).to({x: 200}, 2000, Phaser.Easing.Linear.None, true, 0, 1000, true);
|
||||
tween.onComplete.add(descend, this);
|
||||
|
||||
}
|
||||
|
||||
function descend() {
|
||||
aliens.y += 10;
|
||||
}
|
||||
|
||||
function update() {
|
||||
}
|
||||
|
||||
function render() {
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user