mirror of
https://github.com/wassname/phaser.git
synced 2026-07-14 01:10:16 +08:00
The start of World, also moved Game/Stage into core.
This commit is contained in:
+10
-9
@@ -42,19 +42,22 @@
|
||||
<script src="../src/pixi/utils/Polyk.js"></script>
|
||||
<script src="../src/pixi/utils/Utils.js"></script>
|
||||
|
||||
<script src="../src/core/StateManager.js"></script>
|
||||
<script src="../src/core/State.js"></script>
|
||||
<script src="../src/system/RequestAnimationFrame.js"></script>
|
||||
<script src="../src/core/StateManager.js"></script>
|
||||
<script src="../src/core/Signal.js"></script>
|
||||
<script src="../src/core/SignalBinding.js"></script>
|
||||
<script src="../src/core/Plugin.js"></script>
|
||||
<script src="../src/core/PluginManager.js"></script>
|
||||
<script src="../src/core/Stage.js"></script>
|
||||
<script src="../src/core/World.js"></script>
|
||||
<script src="../src/core/Game.js"></script>
|
||||
<script src="../src/system/Canvas.js"></script>
|
||||
<script src="../src/system/Device.js"></script>
|
||||
<script src="../src/core/SignalBinding.js"></script>
|
||||
<script src="../src/core/Signal.js"></script>
|
||||
<script src="../src/core/PluginManager.js"></script>
|
||||
<script src="../src/core/Plugin.js"></script>
|
||||
<script src="../src/system/RequestAnimationFrame.js"></script>
|
||||
<script src="../src/math/RandomDataGenerator.js"></script>
|
||||
<script src="../src/math/Math.js"></script>
|
||||
<script src="../src/geom/Point.js"></script>
|
||||
<script src="../src/geom/Circle.js"></script>
|
||||
<script src="../src/geom/Point.js"></script>
|
||||
<script src="../src/geom/Rectangle.js"></script>
|
||||
<script src="../src/net/Net.js"></script>
|
||||
<script src="../src/tween/TweenManager.js"></script>
|
||||
@@ -67,5 +70,3 @@
|
||||
<script src="../src/animation/Parser.js"></script>
|
||||
<script src="../src/loader/Cache.js"></script>
|
||||
<script src="../src/loader/Loader.js"></script>
|
||||
<script src="../src/Stage.js"></script>
|
||||
<script src="../src/Game.js"></script>
|
||||
|
||||
+9
-19
@@ -12,37 +12,27 @@
|
||||
|
||||
(function () {
|
||||
|
||||
// var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update });
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update }, false, true);
|
||||
|
||||
var bunny;
|
||||
|
||||
function preload() {
|
||||
|
||||
console.log('***> preload called');
|
||||
game.load.image('cockpit', 'assets/pics/cockpit.png');
|
||||
game.load.image('overdose', 'assets/pics/lance-overdose-loader_eye.png');
|
||||
|
||||
game.load.image('bunny', 'assets/sprites/bunny.png');
|
||||
}
|
||||
|
||||
function create() {
|
||||
|
||||
console.log('***> create called');
|
||||
|
||||
// Create a basetexture
|
||||
var base = new PIXI.BaseTexture(game.cache.getImage('overdose'));
|
||||
var base = new PIXI.BaseTexture(game.cache.getImage('bunny'));
|
||||
var texture = new PIXI.Texture(base);
|
||||
bunny = new PIXI.Sprite(texture);
|
||||
|
||||
// center the sprites anchor point
|
||||
bunny.anchor.x = 0.5;
|
||||
bunny.anchor.y = 0.5;
|
||||
|
||||
// move the sprite t the center of the screen
|
||||
bunny.position.x = 200;
|
||||
bunny.position.y = 150;
|
||||
bunny.position.x = game.world.centerX;
|
||||
bunny.position.y = game.world.centerY;
|
||||
|
||||
game.stage._s.addChild(bunny);
|
||||
game.world.add(bunny);
|
||||
|
||||
}
|
||||
|
||||
@@ -50,9 +40,9 @@
|
||||
|
||||
if (game.paused == false)
|
||||
{
|
||||
bunny.rotation += 0.1;
|
||||
bunny.scale.x += 0.01;
|
||||
bunny.scale.y += 0.01;
|
||||
bunny.rotation += 0.01;
|
||||
// bunny.scale.x += 0.01;
|
||||
// bunny.scale.y += 0.01;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -257,13 +257,12 @@ Phaser.Game.prototype = {
|
||||
this.isBooted = true;
|
||||
|
||||
this.device = new Phaser.Device();
|
||||
this.math = Phaser.Math;
|
||||
|
||||
this.setUpRenderer();
|
||||
|
||||
this.net = new Phaser.Net(this);
|
||||
this.math = Phaser.Math;
|
||||
this.world = new Phaser.World(this);
|
||||
this.stage = new Phaser.Stage(this);
|
||||
// this.world = new Phaser.World(this, width, height);
|
||||
// this.add = new Phaser.GameObjectFactory(this);
|
||||
this.cache = new Phaser.Cache(this);
|
||||
this.load = new Phaser.Loader(this);
|
||||
@@ -274,11 +273,11 @@ Phaser.Game.prototype = {
|
||||
this.rnd = new Phaser.RandomDataGenerator([(Date.now() * Math.random()).toString()]);
|
||||
// this.physics = new Phaser.Physics.PhysicsManager(this);
|
||||
this.plugins = new Phaser.PluginManager(this, this);
|
||||
this.net = new Phaser.Net(this);
|
||||
|
||||
this.load.onLoadComplete.add(this.loadComplete, this);
|
||||
|
||||
this.state.boot();
|
||||
// this.world.boot();
|
||||
this.stage.boot();
|
||||
// this.input.boot();
|
||||
|
||||
@@ -309,7 +308,7 @@ Phaser.Game.prototype = {
|
||||
{
|
||||
this.renderType = Phaser.CANVAS;
|
||||
this.renderer = new PIXI.CanvasRenderer(this.width, this.height, null, this.transparent);
|
||||
Phaser.Canvas.setSmoothingEnabled(this.renderer.view, this.antialias);
|
||||
Phaser.Canvas.setSmoothingEnabled(this.renderer.context, this.antialias);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -368,7 +367,7 @@ Phaser.Game.prototype = {
|
||||
|
||||
this.state.preRender();
|
||||
|
||||
this.renderer.render(this.stage._s);
|
||||
this.renderer.render(this.world._stage);
|
||||
|
||||
this.plugins.render();
|
||||
|
||||
@@ -385,7 +384,7 @@ Phaser.Game.prototype = {
|
||||
this.plugins.postUpdate();
|
||||
|
||||
this.plugins.preRender();
|
||||
this.renderer.render(this.stage._s);
|
||||
this.renderer.render(this.world._stage);
|
||||
this.plugins.render();
|
||||
this.state.loadRender();
|
||||
this.plugins.postRender();
|
||||
@@ -18,7 +18,6 @@ Phaser.Stage = function (game) {
|
||||
Phaser.Stage.prototype = {
|
||||
|
||||
_onChange: null,
|
||||
_s: null,
|
||||
|
||||
bounds: null,
|
||||
offset: null,
|
||||
@@ -30,8 +29,6 @@ Phaser.Stage.prototype = {
|
||||
Phaser.Canvas.getOffset(this.game.renderer.view, this.offset);
|
||||
this.bounds = new Phaser.Rectangle(this.offset.x, this.offset.y, this.game.width, this.game.height);
|
||||
|
||||
this._s = new PIXI.Stage(0x000000);
|
||||
|
||||
var _this = this;
|
||||
|
||||
this._onChange = function (event) {
|
||||
@@ -0,0 +1,116 @@
|
||||
Phaser.World = function (game) {
|
||||
|
||||
this.game = game;
|
||||
this.bounds = new Phaser.Rectangle(0, 0, game.width, game.height);
|
||||
|
||||
this._stage = new PIXI.Stage(0x000000);
|
||||
|
||||
this._container = new PIXI.DisplayObjectContainer();
|
||||
|
||||
this._stage.addChild(this._container);
|
||||
|
||||
};
|
||||
|
||||
Phaser.World.prototype = {
|
||||
|
||||
_stage: null,
|
||||
_container: null,
|
||||
|
||||
bounds: null,
|
||||
|
||||
add: function (sprite) {
|
||||
this._container.addChild(sprite);
|
||||
},
|
||||
|
||||
/**
|
||||
* Updates the size of this world.
|
||||
*
|
||||
* @param width {number} New width of the world.
|
||||
* @param height {number} New height of the world.
|
||||
* @param [updateCameraBounds] {bool} Update camera bounds automatically or not. Default to true.
|
||||
*/
|
||||
setSize: function (width, height, updateCameraBounds) {
|
||||
|
||||
if (typeof updateCameraBounds === "undefined") { updateCameraBounds = true; }
|
||||
|
||||
this.bounds.width = width;
|
||||
this.bounds.height = height;
|
||||
|
||||
if (updateCameraBounds == true)
|
||||
{
|
||||
// this.game.camera.setBounds(0, 0, width, height);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
// Getters / Setters
|
||||
|
||||
Object.defineProperty(Phaser.World.prototype, "width", {
|
||||
|
||||
get: function () {
|
||||
return this.bounds.width;
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
this.bounds.width = value;
|
||||
},
|
||||
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
Object.defineProperty(Phaser.World.prototype, "height", {
|
||||
|
||||
get: function () {
|
||||
return this.bounds.height;
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
this.bounds.height = value;
|
||||
},
|
||||
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
Object.defineProperty(Phaser.World.prototype, "centerX", {
|
||||
|
||||
get: function () {
|
||||
return this.bounds.halfWidth;
|
||||
},
|
||||
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
Object.defineProperty(Phaser.World.prototype, "centerY", {
|
||||
|
||||
get: function () {
|
||||
return this.bounds.halfHeight;
|
||||
},
|
||||
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
Object.defineProperty(Phaser.World.prototype, "randomX", {
|
||||
|
||||
get: function () {
|
||||
return Math.round(Math.random() * this.bounds.width);
|
||||
},
|
||||
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
Object.defineProperty(Phaser.World.prototype, "randomY", {
|
||||
|
||||
get: function () {
|
||||
return Math.round(Math.random() * this.bounds.height);
|
||||
},
|
||||
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Reference in New Issue
Block a user