mirror of
https://github.com/wassname/phaser.git
synced 2026-06-27 16:10:15 +08:00
Velocity integration tidied up. Now moving to sync Body with Sprite center point.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
@@ -40,3 +40,12 @@ function collisionHandler (obj1, obj2) {
|
||||
game.stage.backgroundColor = '#992d2d';
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
// game.debug.renderBodyInfo(sprite1, 16, 16);
|
||||
|
||||
game.debug.renderPolygon(sprite1.body.polygons);
|
||||
game.debug.renderPolygon(sprite2.body.polygons);
|
||||
|
||||
}
|
||||
@@ -15,6 +15,8 @@ function create() {
|
||||
|
||||
aliens = game.add.group();
|
||||
|
||||
game.physics.gravity.y = 100;
|
||||
|
||||
for (var i = 0; i < 50; i++)
|
||||
{
|
||||
var s = aliens.create(game.world.randomX, game.world.randomY, 'baddie');
|
||||
@@ -27,6 +29,7 @@ function create() {
|
||||
}
|
||||
|
||||
car = game.add.sprite(400, 300, 'car');
|
||||
car.name = 'car';
|
||||
car.anchor.setTo(0.5, 0.5);
|
||||
car.body.collideWorldBounds = true;
|
||||
// car.body.bounce.setTo(0.8, 0.8);
|
||||
@@ -62,7 +65,17 @@ function update() {
|
||||
|
||||
function render() {
|
||||
|
||||
for (var i = 0; i < aliens._container.children.length; i++)
|
||||
{
|
||||
game.debug.renderPolygon(aliens._container.children[i].body.polygons);
|
||||
}
|
||||
|
||||
game.debug.renderPolygon(car.body.polygons);
|
||||
|
||||
// game.debug.renderBodyInfo(aliens._container.children[0], 32, 32);
|
||||
game.debug.renderBodyInfo(aliens._container.children[0], 32, 32);
|
||||
|
||||
// game.debug.renderBodyInfo(car, 16, 24);
|
||||
game.debug.renderBodyInfo(aliens.getFirstAlive(), 16, 24);
|
||||
// game.debug.renderBodyInfo(aliens.getFirstAlive(), 16, 24);
|
||||
|
||||
}
|
||||
|
||||
@@ -67,10 +67,8 @@ function create() {
|
||||
|
||||
function launch() {
|
||||
|
||||
game.time._x = true;
|
||||
|
||||
// sprite.body.velocity.x = -200;
|
||||
// sprite.body.velocity.y = -200;
|
||||
sprite.body.velocity.x = -200;
|
||||
sprite.body.velocity.y = -200;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -29,17 +29,19 @@ function create() {
|
||||
|
||||
function move() {
|
||||
|
||||
console.log('moving');
|
||||
|
||||
if (sprite.x === 100)
|
||||
{
|
||||
// Here you'll notice we are using a relative value for the tween.
|
||||
// You can specify a number as a string with either + or - at the start of it.
|
||||
// When the tween starts it will take the sprites current X value and add +300 to it.
|
||||
|
||||
game.add.tween(sprite).to( { x: '+300' }, 2000, Phaser.Easing.Linear.None, true);
|
||||
// game.add.tween(sprite).to( { x: '+300' }, 2000, Phaser.Easing.Linear.None, true);
|
||||
}
|
||||
else if (sprite.x === 400)
|
||||
{
|
||||
game.add.tween(sprite).to( { x: '-300' }, 2000, Phaser.Easing.Linear.None, true);
|
||||
// game.add.tween(sprite).to( { x: '-300' }, 2000, Phaser.Easing.Linear.None, true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -48,10 +50,17 @@ function render() {
|
||||
|
||||
if (sprite.x === 100 || sprite.x === 400)
|
||||
{
|
||||
game.debug.renderText('Click sprite to tween', 32, 32);
|
||||
// game.debug.renderText('Click sprite to tween', 32, 32);
|
||||
}
|
||||
|
||||
game.debug.renderText('x: ' + arrowStart.x, arrowStart.x, arrowStart.y - 4);
|
||||
game.debug.renderText('x: ' + arrowEnd.x, arrowEnd.x, arrowEnd.y - 4);
|
||||
|
||||
game.debug.renderText('sprite.x: ' + sprite.x + ' deltaX: ' + sprite.deltaX, 32, 32);
|
||||
game.debug.renderText('sprite.y: ' + sprite.y + ' deltaY: ' + sprite.deltaY, 32, 48);
|
||||
|
||||
game.debug.renderPolygon(sprite.body.polygons);
|
||||
|
||||
game.debug.renderPoint(sprite.center);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user