mirror of
https://github.com/wassname/phaser.git
synced 2026-07-05 17:30:19 +08:00
Physics integration and a fix to Tween that stopped the repeat/yoyo from working.
This commit is contained in:
+16
-31
@@ -16,56 +16,41 @@
|
||||
|
||||
function preload() {
|
||||
game.load.atlasJSONHash('bot', 'assets/sprites/running_bot.png', 'assets/sprites/running_bot.json');
|
||||
game.load.image('bunny', 'assets/sprites/bunny.png');
|
||||
}
|
||||
|
||||
var s;
|
||||
var bunny;
|
||||
var bot;
|
||||
|
||||
function create() {
|
||||
|
||||
game.world._stage.backgroundColorString = '#182d3b';
|
||||
|
||||
s = game.add.sprite(game.world.centerX, game.world.centerY, 'bot');
|
||||
// s.anchor.setTo(0.5, 0.5);
|
||||
bunny = game.add.sprite(500, game.world.centerY, 'bunny');
|
||||
bunny.anchor.setTo(0.5, 0.5);
|
||||
|
||||
// s.body.offset.setTo(0, 0);
|
||||
bot = game.add.sprite(150, game.world.centerY, 'bot');
|
||||
bot.anchor.setTo(0.5, 0.5);
|
||||
bot.animations.add('run');
|
||||
bot.animations.play('run', 10, true);
|
||||
|
||||
|
||||
// s.scale.setTo(2, 2);
|
||||
|
||||
s.animations.add('run');
|
||||
s.animations.play('run', 10, true);
|
||||
game.add.tween(bot.scale).to({ x: 3, y: 3 }, 2000, Phaser.Easing.Linear.None, true, 0, 1000, true);
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
bunny.angle += 1;
|
||||
bot.angle += 1;
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.renderSpriteCorners(s, true, true);
|
||||
// game.debug.renderRectangle(s.body.bounds, 'rgba(255,0,0,0.3)');
|
||||
game.debug.renderSpriteInfo(s, 20, 32);
|
||||
game.debug.renderSpriteCorners(bunny, true, true);
|
||||
game.debug.renderSpriteCorners(bot, true, true);
|
||||
game.debug.renderSpriteInfo(bunny, 20, 32);
|
||||
game.debug.renderSpriteInfo(bot, 20, 132);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
<!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.atlasJSONHash('bot', 'assets/sprites/running_bot.png', 'assets/sprites/running_bot.json');
|
||||
game.load.image('bunny', 'assets/sprites/mana_card.png');
|
||||
}
|
||||
|
||||
var bunny;
|
||||
var bot;
|
||||
|
||||
function create() {
|
||||
|
||||
game.world._stage.backgroundColorString = '#182d3b';
|
||||
|
||||
bunny = game.add.sprite(500, game.world.centerY, 'bunny');
|
||||
|
||||
bunny.body.offset.setTo();
|
||||
|
||||
bot = game.add.sprite(150, game.world.centerY, 'bot');
|
||||
bot.anchor.setTo(0.5, 0.5);
|
||||
bot.animations.add('run');
|
||||
bot.animations.play('run', 10, true);
|
||||
|
||||
game.add.tween(bot.scale).to({ x: 3, y: 3 }, 2000, Phaser.Easing.Linear.None, true, 0, 1000, true);
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
bunny.angle += 1;
|
||||
bot.angle += 1;
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.renderSpriteCorners(bunny, true, true);
|
||||
game.debug.renderSpriteCorners(bot, true, true);
|
||||
|
||||
game.debug.renderRectangle(bunny.body.hitArea);
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,53 @@
|
||||
<!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.atlasJSONHash('bot', 'assets/sprites/running_bot.png', 'assets/sprites/running_bot.json');
|
||||
game.load.image('bunny', 'assets/sprites/mana_card.png');
|
||||
}
|
||||
|
||||
var bunny;
|
||||
var bot;
|
||||
|
||||
function create() {
|
||||
|
||||
game.world._stage.backgroundColorString = '#182d3b';
|
||||
|
||||
bunny = game.add.sprite(200, 200, 'bunny');
|
||||
|
||||
bunny.body.acceleration.x = 10;
|
||||
// bunny.body.velocity.y = 20;
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.renderSpriteCorners(bunny, true, true);
|
||||
game.debug.renderRectangle(bunny.body.hitArea);
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user