mirror of
https://github.com/wassname/phaser.git
synced 2026-06-27 16:10:15 +08:00
Updated physics body to use localTransform. Updated tanks demo.
This commit is contained in:
@@ -41,7 +41,7 @@ Version 1.0.7 (in progress in the dev branch)
|
||||
* Added World.postUpdate - all sprite position changes, as a result of physics, happen here before the render.
|
||||
* Complete overhaul of Physics.Arcade.Body - now significantly more stable and faster too.
|
||||
* Updated ArcadePhysics.separateX/Y to use new body system - much better results now.
|
||||
* QuadTree bug found in 1.0.5 now fixed. The QuadTree is updated properly now using worldTransform values.
|
||||
* QuadTree bug found in 1.0.5 now fixed. The QuadTree is updated properly now using localTransform values.
|
||||
* Fixed the Bounce.In and Bounce.InOut tweens (thanks XekeDeath)
|
||||
* Renamed Phaser.Text.text to Phaser.Text.content to avoid conflict and overwrite from Pixi local var.
|
||||
* Renamed Phaser.Text.style to Phaser.Text.font to avoid conflict and overwrite from Pixi local var.
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 905 B |
@@ -5,8 +5,6 @@
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create,update : update });
|
||||
|
||||
function preload() {
|
||||
@@ -14,41 +12,34 @@
|
||||
game.load.spritesheet('button', 'assets/buttons/button_sprite_sheet.png', 193, 71);
|
||||
game.load.image('background','assets/misc/starfield.jpg');
|
||||
|
||||
|
||||
}
|
||||
var button,
|
||||
background;
|
||||
|
||||
var button;
|
||||
var background;
|
||||
|
||||
function create() {
|
||||
|
||||
game.stage.backgroundColor = '#cccccc';
|
||||
|
||||
// the numbers given in parameters are the indexes of the frames, in this order :
|
||||
// over,out,down
|
||||
button = game.add.button(game.world.centerX, game.world.centerY, 'button', actionOnClick, this, 1, 0, 2);
|
||||
// The numbers given in parameters are the indexes of the frames, in this order: over, out, down
|
||||
button = game.add.button(game.world.centerX, game.world.centerY, 'button', actionOnClick, this, 2, 1, 0);
|
||||
|
||||
//set the anchor of the sprite in the center, otherwise it would rotate around the top-left corner
|
||||
// Set the anchor of the sprite in the center, otherwise it would rotate around the top-left corner
|
||||
button.anchor.setTo(0.5,0.5);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
function actionOnClick () {
|
||||
|
||||
alert("Though I'm turning around, you can still click on me");
|
||||
|
||||
|
||||
}
|
||||
|
||||
function update () {
|
||||
|
||||
button.angle+=1;
|
||||
button.angle += 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<?php
|
||||
|
||||
+36
-35
@@ -10,33 +10,30 @@
|
||||
function preload() {
|
||||
|
||||
game.load.atlas('tank', 'assets/games/tanks/tanks.png', 'assets/games/tanks/tanks.json');
|
||||
game.load.image('bullet', 'assets/sprites/enemy-bullet.png');
|
||||
game.load.image('bullet', 'assets/games/tanks/bullet.png');
|
||||
game.load.image('earth', 'assets/games/tanks/scorched_earth.png');
|
||||
|
||||
}
|
||||
|
||||
var tank;
|
||||
var turret;
|
||||
var shadow;
|
||||
|
||||
var currentSpeed = 0;
|
||||
|
||||
var land;
|
||||
|
||||
var cursors;
|
||||
var bullets;
|
||||
var shadow;
|
||||
var tank;
|
||||
var turret;
|
||||
|
||||
var enemy;
|
||||
|
||||
var currentSpeed = 0;
|
||||
var cursors;
|
||||
|
||||
var bullets;
|
||||
var fireRate = 100;
|
||||
var nextFire = 0;
|
||||
|
||||
function create() {
|
||||
|
||||
// Resize our game world to be a 2000x2000 square
|
||||
// game.world.setBounds(-1000, -1000, 2000, 2000);
|
||||
game.world.setBounds(0, 0, 1000, 1000);
|
||||
|
||||
console.log(game.world.bounds.right, 'bot', this.game.world.bounds.bottom);
|
||||
console.log(game.camera.bounds.right, 'cbot', this.game.camera.bounds.bottom);
|
||||
game.world.setBounds(-1000, -1000, 2000, 2000);
|
||||
|
||||
// Our tiled scrolling background
|
||||
land = game.add.tileSprite(0, 0, 800, 600, 'earth');
|
||||
@@ -46,17 +43,6 @@
|
||||
shadow = game.add.sprite(0, 0, 'tank', 'shadow');
|
||||
shadow.anchor.setTo(0.5, 0.5);
|
||||
|
||||
// The base of our tank
|
||||
tank = game.add.sprite(0, 0, 'tank', 'tank1');
|
||||
tank.anchor.setTo(0.5, 0.5);
|
||||
tank.animations.add('move', ['tank1', 'tank2', 'tank3', 'tank4', 'tank5', 'tank6'], 20, true);
|
||||
tank.play('move');
|
||||
|
||||
// This will force it to decelerate and limit its speed
|
||||
tank.body.drag.setTo(200, 200);
|
||||
tank.body.maxVelocity.setTo(400, 400);
|
||||
tank.body.collideWorldBounds = true;
|
||||
|
||||
// Our bullet group
|
||||
bullets = game.add.group();
|
||||
bullets.createMultiple(50, 'bullet');
|
||||
@@ -64,12 +50,30 @@
|
||||
bullets.setAll('anchor.y', 0.5);
|
||||
bullets.setAll('outOfBoundsKill', true);
|
||||
|
||||
// The base of our tank
|
||||
tank = game.add.sprite(0, 0, 'tank', 'tank1');
|
||||
tank.anchor.setTo(0.5, 0.5);
|
||||
tank.animations.add('move', ['tank1', 'tank2', 'tank3', 'tank4', 'tank5', 'tank6'], 20, true);
|
||||
// tank.play('move');
|
||||
|
||||
// This will force it to decelerate and limit its speed
|
||||
tank.body.drag.setTo(200, 200);
|
||||
tank.body.maxVelocity.setTo(400, 400);
|
||||
tank.body.collideWorldBounds = true;
|
||||
|
||||
|
||||
// Finally the turret that we place on-top of the tank body
|
||||
turret = game.add.sprite(0, 0, 'tank', 'turret');
|
||||
turret.anchor.setTo(0.5, 0.5);
|
||||
turret.anchor.setTo(0.3, 0.5);
|
||||
|
||||
enemy = game.add.sprite(900, 400, 'tank', 'tank1');
|
||||
enemy.anchor.setTo(0.5, 0.5);
|
||||
enemy.body.immovable = true;
|
||||
enemy.body.collideWorldBounds = true;
|
||||
|
||||
game.camera.follow(tank);
|
||||
// game.camera.deadzone = new Phaser.Rectangle(100, 100, 600, 400);
|
||||
game.camera.deadzone = new Phaser.Rectangle(100, 100, 600, 400);
|
||||
game.camera.focusOnXY(0, 0);
|
||||
|
||||
cursors = game.input.keyboard.createCursorKeys();
|
||||
|
||||
@@ -77,6 +81,8 @@
|
||||
|
||||
function update() {
|
||||
|
||||
game.physics.collide(tank, enemy);
|
||||
|
||||
if (cursors.left.isDown)
|
||||
{
|
||||
tank.angle -= 4;
|
||||
@@ -139,7 +145,7 @@
|
||||
|
||||
bullet.reset(turret.x, turret.y);
|
||||
|
||||
game.physics.moveToPointer(bullet, 1000);
|
||||
bullet.rotation = game.physics.moveToPointer(bullet, 1000);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -151,15 +157,10 @@
|
||||
// game.debug.renderText('sr: ' + tank.body.right, 32, 100);
|
||||
// game.debug.renderText('sb: ' + tank.body.bottom, 32, 132);
|
||||
|
||||
game.debug.renderSpriteCorners(tank, true, true);
|
||||
// game.debug.renderSpriteCorners(tank, true, true);
|
||||
|
||||
game.debug.renderCameraInfo(game.camera, 500, 32);
|
||||
|
||||
game.debug.renderLocalTransformInfo(tank, 32, 32);
|
||||
game.debug.renderWorldTransformInfo(tank, 32, 200);
|
||||
|
||||
|
||||
// game.debug.renderSpriteInfo(sprite, 32, 450);
|
||||
game.debug.renderSpriteInfo(tank, 32, 450);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1286,8 +1286,8 @@ Phaser.Physics.Arcade.prototype = {
|
||||
|
||||
pointer = pointer || this.game.input.activePointer;
|
||||
|
||||
this._dx = displayObject.x - pointer.x;
|
||||
this._dy = displayObject.y - pointer.y;
|
||||
this._dx = displayObject.worldX - pointer.x;
|
||||
this._dy = displayObject.worldY - pointer.y;
|
||||
|
||||
return Math.sqrt(this._dx * this._dx + this._dy * this._dy);
|
||||
|
||||
@@ -1340,8 +1340,8 @@ Phaser.Physics.Arcade.prototype = {
|
||||
|
||||
pointer = pointer || this.game.input.activePointer;
|
||||
|
||||
this._dx = pointer.x - displayObject.x;
|
||||
this._dy = pointer.y - displayObject.y;
|
||||
this._dx = pointer.worldX - displayObject.x;
|
||||
this._dy = pointer.worldY - displayObject.y;
|
||||
|
||||
return Math.atan2(this._dy, this._dx);
|
||||
|
||||
|
||||
@@ -105,8 +105,8 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
|
||||
this.embedded = false;
|
||||
|
||||
this.preX = (this.sprite.worldTransform[2] - (this.sprite.anchor.x * this.width)) + this.offset.x;
|
||||
this.preY = (this.sprite.worldTransform[5] - (this.sprite.anchor.y * this.height)) + this.offset.y;
|
||||
this.preX = (this.sprite.localTransform[2] - (this.sprite.anchor.x * this.width)) + this.offset.x;
|
||||
this.preY = (this.sprite.localTransform[5] - (this.sprite.anchor.y * this.height)) + this.offset.y;
|
||||
this.preRotation = this.sprite.angle;
|
||||
|
||||
this.x = this.preX;
|
||||
@@ -221,12 +221,12 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
this.angularVelocity = 0;
|
||||
this.angularAcceleration = 0;
|
||||
|
||||
this.preX = (this.sprite.worldTransform[2] - (this.sprite.anchor.x * this.width)) + this.offset.x;
|
||||
this.preY = (this.sprite.worldTransform[5] - (this.sprite.anchor.y * this.height)) + this.offset.y;
|
||||
this.preX = (this.sprite.localTransform[2] - (this.sprite.anchor.x * this.width)) + this.offset.x;
|
||||
this.preY = (this.sprite.localTransform[5] - (this.sprite.anchor.y * this.height)) + this.offset.y;
|
||||
this.preRotation = this.sprite.angle;
|
||||
|
||||
this.x = (this.sprite.worldTransform[2] - (this.sprite.anchor.x * this.width)) + this.offset.x;
|
||||
this.y = (this.sprite.worldTransform[5] - (this.sprite.anchor.y * this.height)) + this.offset.y;
|
||||
this.x = (this.sprite.localTransform[2] - (this.sprite.anchor.x * this.width)) + this.offset.x;
|
||||
this.y = (this.sprite.localTransform[5] - (this.sprite.anchor.y * this.height)) + this.offset.y;
|
||||
this.rotation = this.sprite.angle;
|
||||
|
||||
},
|
||||
|
||||
@@ -539,8 +539,6 @@ Phaser.Utils.Debug.prototype = {
|
||||
this.line('scaleY: ' + sprite.localTransform[4]);
|
||||
this.line('transX: ' + sprite.localTransform[2]);
|
||||
this.line('transY: ' + sprite.localTransform[5]);
|
||||
this.line('sX: ' + sprite._sx);
|
||||
this.line('sY: ' + sprite._sy);
|
||||
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user