mirror of
https://github.com/photonstorm/phaser
synced 2024-11-24 21:53:59 +00:00
Great new thrust ship example added for ScrollZones. Also added rotationOffset value to GameObject base class.
This commit is contained in:
parent
00fb20f8c2
commit
6466361f5f
10 changed files with 129 additions and 24 deletions
|
@ -79,6 +79,11 @@ module Phaser {
|
|||
*/
|
||||
public velocityFromAngle(angle: number, speed: number): Point {
|
||||
|
||||
if (isNaN(speed))
|
||||
{
|
||||
speed = 0;
|
||||
}
|
||||
|
||||
var a: number = this._game.math.degreesToRadians(angle);
|
||||
|
||||
return new Point((Math.cos(a) * speed), (Math.sin(a) * speed));
|
||||
|
|
|
@ -76,6 +76,11 @@ module Phaser {
|
|||
public origin: MicroPoint;
|
||||
public z: number = 0;
|
||||
|
||||
// This value is added to the angle of the GameObject.
|
||||
// For example if you had a sprite drawn facing straight up then you could set
|
||||
// rotationOffset to 90 and it would correspond correctly with Phasers rotation system
|
||||
public rotationOffset: number = 0;
|
||||
|
||||
// Physics properties
|
||||
public immovable: bool;
|
||||
|
||||
|
|
|
@ -224,14 +224,14 @@ module Phaser {
|
|||
}
|
||||
|
||||
// Rotation - needs to work from origin point really, but for now from center
|
||||
if (this.angle !== 0 || this.flipped == true)
|
||||
if (this.angle !== 0 || this.rotationOffset !== 0 || this.flipped == true)
|
||||
{
|
||||
this._game.stage.context.save();
|
||||
this._game.stage.context.translate(this._dx + (this._dw / 2), this._dy + (this._dh / 2));
|
||||
|
||||
if (this.angle !== 0)
|
||||
if (this.angle !== 0 || this.rotationOffset !== 0)
|
||||
{
|
||||
this._game.stage.context.rotate(this.angle * (Math.PI / 180));
|
||||
this._game.stage.context.rotate((this.rotationOffset + this.angle) * (Math.PI / 180));
|
||||
}
|
||||
|
||||
this._dx = -(this._dw / 2);
|
||||
|
|
|
@ -3,7 +3,7 @@ Phaser
|
|||
|
||||
Version 0.9.3
|
||||
|
||||
21st April 2013
|
||||
23rd April 2013
|
||||
|
||||
By Richard Davey, [Photon Storm](http://www.photonstorm.com)
|
||||
|
||||
|
@ -25,9 +25,9 @@ V0.9.3
|
|||
* Re-built Tilemap handling from scratch to allow for proper layered maps (as exported from Tiled / Mappy)
|
||||
* Tilemap no longer requires a buffer per Camera (in prep for WebGL support)
|
||||
* Added shiftSinTable and shiftCosTable to the GameMath class to allow for quick iteration through the data tables.
|
||||
* Added the new ScrollZone game object. Endlessly useful but especially for scrolling backdrops. Created several example tests.
|
||||
* Added the new ScrollZone game object. Endlessly useful but especially for scrolling backdrops. Created 6 example tests.
|
||||
* Removed the need for DynamicTextures to require a key property and updated test cases.
|
||||
|
||||
* Add the rotationOffset value to GameObject (and thus Sprite). Useful if your graphics need to rotate but don't weren't drawn facing zero degrees (to the right).
|
||||
|
||||
V0.9.2
|
||||
|
||||
|
|
|
@ -467,6 +467,10 @@ var Phaser;
|
|||
_super.call(this, game);
|
||||
this._angle = 0;
|
||||
this.z = 0;
|
||||
// This value is added to the angle of the GameObject.
|
||||
// For example if you had a sprite drawn facing straight up then you could set
|
||||
// rotationOffset to 90 and it would correspond correctly with Phasers rotation system
|
||||
this.rotationOffset = 0;
|
||||
this.moves = true;
|
||||
// Input
|
||||
this.inputEnabled = false;
|
||||
|
@ -1541,11 +1545,11 @@ var Phaser;
|
|||
this._dy -= (camera.worldView.y * this.scrollFactor.y);
|
||||
}
|
||||
// Rotation - needs to work from origin point really, but for now from center
|
||||
if(this.angle !== 0 || this.flipped == true) {
|
||||
if(this.angle !== 0 || this.rotationOffset !== 0 || this.flipped == true) {
|
||||
this._game.stage.context.save();
|
||||
this._game.stage.context.translate(this._dx + (this._dw / 2), this._dy + (this._dh / 2));
|
||||
if(this.angle !== 0) {
|
||||
this._game.stage.context.rotate(this.angle * (Math.PI / 180));
|
||||
if(this.angle !== 0 || this.rotationOffset !== 0) {
|
||||
this._game.stage.context.rotate((this.rotationOffset + this.angle) * (Math.PI / 180));
|
||||
}
|
||||
this._dx = -(this._dw / 2);
|
||||
this._dy = -(this._dh / 2);
|
||||
|
@ -6983,6 +6987,9 @@ var Phaser;
|
|||
* @return A Point where Point.x contains the velocity x value and Point.y contains the velocity y value
|
||||
*/
|
||||
function (angle, speed) {
|
||||
if(isNaN(speed)) {
|
||||
speed = 0;
|
||||
}
|
||||
var a = this._game.math.degreesToRadians(angle);
|
||||
return new Phaser.Point((Math.cos(a) * speed), (Math.sin(a) * speed));
|
||||
};
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
}
|
||||
function create() {
|
||||
var zone = myGame.createScrollZone('starray');
|
||||
// Hide the default region (the full image)
|
||||
zone.currentRegion.visible = false;
|
||||
var y = 0;
|
||||
var speed = 16;
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
var zone: Phaser.ScrollZone = myGame.createScrollZone('starray');
|
||||
|
||||
// Hide the default region (the full image)
|
||||
zone.currentRegion.visible = false;
|
||||
|
||||
var y:number = 0;
|
||||
|
|
|
@ -3,19 +3,49 @@
|
|||
(function () {
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
function init() {
|
||||
myGame.loader.addImageFile('nashwan', 'assets/sprites/xenon2_ship.png');
|
||||
myGame.loader.addImageFile('starfield', 'assets/misc/starfield.jpg');
|
||||
myGame.loader.addImageFile('jet', 'assets/sprites/jets.png');
|
||||
myGame.loader.load();
|
||||
}
|
||||
var scroller;
|
||||
var emitter;
|
||||
var ship;
|
||||
var speed = 0;
|
||||
function create() {
|
||||
// 512 x 512
|
||||
scroller = myGame.createScrollZone('starfield', 0, 0, 1024, 512);
|
||||
// Some sin/cos data for the movement
|
||||
myGame.math.sinCosGenerator(256, 4, 4, 2);
|
||||
scroller = myGame.createScrollZone('starfield', 0, 0, 1024, 1024);
|
||||
emitter = myGame.createEmitter(myGame.stage.centerX + 16, myGame.stage.centerY + 12);
|
||||
emitter.makeParticles('jet', 250, 0, false, 0);
|
||||
//emitter.lifespan
|
||||
ship = myGame.createSprite(myGame.stage.centerX, myGame.stage.centerY, 'nashwan');
|
||||
// We do this because the ship was drawn facing up, but 0 degrees is pointing to the right
|
||||
ship.rotationOffset = 90;
|
||||
}
|
||||
function update() {
|
||||
scroller.currentRegion.scrollSpeed.x = myGame.math.shiftSinTable();
|
||||
scroller.currentRegion.scrollSpeed.y = myGame.math.shiftCosTable();
|
||||
ship.angularVelocity = 0;
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||
ship.angularVelocity = -200;
|
||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
||||
ship.angularVelocity = 200;
|
||||
}
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.UP)) {
|
||||
speed += 0.1;
|
||||
if(speed > 10) {
|
||||
speed = 10;
|
||||
}
|
||||
} else {
|
||||
speed -= 0.1;
|
||||
if(speed < 0) {
|
||||
speed = 0;
|
||||
}
|
||||
}
|
||||
var motion = myGame.motion.velocityFromAngle(ship.angle, speed);
|
||||
scroller.setSpeed(motion.x, motion.y);
|
||||
// emit particles
|
||||
if(speed > 2) {
|
||||
emitter.setXSpeed(-(motion.x * 20), -(motion.x * 30));
|
||||
emitter.setYSpeed(-(motion.y * 20), -(motion.y * 30));
|
||||
emitter.emitParticle();
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
|
|
@ -7,29 +7,78 @@
|
|||
|
||||
function init() {
|
||||
|
||||
myGame.loader.addImageFile('nashwan', 'assets/sprites/xenon2_ship.png');
|
||||
myGame.loader.addImageFile('starfield', 'assets/misc/starfield.jpg');
|
||||
myGame.loader.addImageFile('jet', 'assets/sprites/jets.png');
|
||||
|
||||
myGame.loader.load();
|
||||
|
||||
}
|
||||
|
||||
var scroller: Phaser.ScrollZone;
|
||||
var emitter: Phaser.Emitter;
|
||||
var ship: Phaser.Sprite;
|
||||
|
||||
var speed: number = 0;
|
||||
|
||||
function create() {
|
||||
|
||||
// 512 x 512
|
||||
scroller = myGame.createScrollZone('starfield', 0, 0, 1024, 512);
|
||||
scroller = myGame.createScrollZone('starfield', 0, 0, 1024, 1024);
|
||||
|
||||
// Some sin/cos data for the movement
|
||||
myGame.math.sinCosGenerator(256, 4, 4, 2);
|
||||
emitter = myGame.createEmitter(myGame.stage.centerX + 16, myGame.stage.centerY + 12);
|
||||
emitter.makeParticles('jet', 250, 0, false, 0);
|
||||
//emitter.lifespan
|
||||
|
||||
|
||||
ship = myGame.createSprite(myGame.stage.centerX, myGame.stage.centerY, 'nashwan');
|
||||
|
||||
// We do this because the ship was drawn facing up, but 0 degrees is pointing to the right
|
||||
ship.rotationOffset = 90;
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
scroller.currentRegion.scrollSpeed.x = myGame.math.shiftSinTable();
|
||||
scroller.currentRegion.scrollSpeed.y = myGame.math.shiftCosTable();
|
||||
ship.angularVelocity = 0;
|
||||
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
ship.angularVelocity = -200;
|
||||
}
|
||||
else if (myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
{
|
||||
ship.angularVelocity = 200;
|
||||
}
|
||||
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
{
|
||||
speed += 0.1;
|
||||
|
||||
if (speed > 10)
|
||||
{
|
||||
speed = 10;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
speed -= 0.1;
|
||||
|
||||
if (speed < 0) {
|
||||
speed = 0;
|
||||
}
|
||||
}
|
||||
|
||||
var motion:Phaser.Point = myGame.motion.velocityFromAngle(ship.angle, speed);
|
||||
|
||||
scroller.setSpeed(motion.x, motion.y);
|
||||
|
||||
// emit particles
|
||||
if (speed > 2)
|
||||
{
|
||||
emitter.setXSpeed(-(motion.x * 20), -(motion.x * 30));
|
||||
emitter.setYSpeed(-(motion.y * 20), -(motion.y * 30));
|
||||
emitter.emitParticle();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -467,6 +467,10 @@ var Phaser;
|
|||
_super.call(this, game);
|
||||
this._angle = 0;
|
||||
this.z = 0;
|
||||
// This value is added to the angle of the GameObject.
|
||||
// For example if you had a sprite drawn facing straight up then you could set
|
||||
// rotationOffset to 90 and it would correspond correctly with Phasers rotation system
|
||||
this.rotationOffset = 0;
|
||||
this.moves = true;
|
||||
// Input
|
||||
this.inputEnabled = false;
|
||||
|
@ -1541,11 +1545,11 @@ var Phaser;
|
|||
this._dy -= (camera.worldView.y * this.scrollFactor.y);
|
||||
}
|
||||
// Rotation - needs to work from origin point really, but for now from center
|
||||
if(this.angle !== 0 || this.flipped == true) {
|
||||
if(this.angle !== 0 || this.rotationOffset !== 0 || this.flipped == true) {
|
||||
this._game.stage.context.save();
|
||||
this._game.stage.context.translate(this._dx + (this._dw / 2), this._dy + (this._dh / 2));
|
||||
if(this.angle !== 0) {
|
||||
this._game.stage.context.rotate(this.angle * (Math.PI / 180));
|
||||
if(this.angle !== 0 || this.rotationOffset !== 0) {
|
||||
this._game.stage.context.rotate((this.rotationOffset + this.angle) * (Math.PI / 180));
|
||||
}
|
||||
this._dx = -(this._dw / 2);
|
||||
this._dy = -(this._dh / 2);
|
||||
|
@ -6983,6 +6987,9 @@ var Phaser;
|
|||
* @return A Point where Point.x contains the velocity x value and Point.y contains the velocity y value
|
||||
*/
|
||||
function (angle, speed) {
|
||||
if(isNaN(speed)) {
|
||||
speed = 0;
|
||||
}
|
||||
var a = this._game.math.degreesToRadians(angle);
|
||||
return new Phaser.Point((Math.cos(a) * speed), (Math.sin(a) * speed));
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue