Skip to content

Commit 45ab467

Browse files
committed
ScaleManager.fullScreenTarget allows you to change the DOM element that the fullscreen API is called on (feature request phaserjs#526)
1 parent c73b4ea commit 45ab467

5 files changed

Lines changed: 128 additions & 46 deletions

File tree

Gruntfile.js

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,16 @@ module.exports = function (grunt) {
2525
'* By Richard Davey http://www.photonstorm.com @photonstorm\n' +
2626
'*\n' +
2727
'* Phaser is a fun, free and fast 2D game framework for making HTML5 games \n' +
28-
'* for desktop and mobile web browsers, supporting Canvas and WebGL rendering.\n' +
28+
'* for desktop and mobile web browsers, supporting Canvas and WebGL.\n' +
2929
'*\n' +
3030
'* Phaser uses Pixi.js for rendering, created by Mat Groves http://matgroves.com @Doormat23\n' +
31-
'* Phaser uses p2.js for physics, created by Stefan Hedman https://github.com/schteppe/p2.js @schteppe\n' +
31+
'* Phaser uses p2.js for full-body physics, created by Stefan Hedman https://github.com/schteppe/p2.js @schteppe\n' +
32+
'* Phaser contains a port of N+ Physics, converted by Richard Davey, original by http://www.metanetsoftware.com\n' +
3233
'*\n' +
3334
'* Many thanks to Adam Saltsman (@ADAMATOMIC) for releasing Flixel, from which both Phaser\n' +
34-
'* and my love of framework development originate.\n' +
35+
'* and my love of framework development can be traced.\n' +
3536
'*\n' +
36-
'* Follow Phaser development progress at http://phaser.io\n' +
37+
'* Follow development at http://phaser.io and on our forum\n' +
3738
'*\n' +
3839
'* "If you want your children to be intelligent, read them fairy tales."\n' +
3940
'* "If you want them to be more intelligent, read them more fairy tales."\n' +
@@ -43,10 +44,6 @@ module.exports = function (grunt) {
4344
release_dir: 'build',
4445
compile_dir: 'dist',
4546

46-
p2: [
47-
'src/p2.js'
48-
],
49-
5047
pixi: [
5148
'src/pixi/Intro.js',
5249
'src/pixi/Pixi.js',
@@ -186,21 +183,6 @@ module.exports = function (grunt) {
186183
'src/physics/arcade/World.js',
187184
'src/physics/arcade/Body.js',
188185

189-
'src/physics/ninja/World.js',
190-
'src/physics/ninja/Body.js',
191-
'src/physics/ninja/AABB.js',
192-
'src/physics/ninja/Tile.js',
193-
'src/physics/ninja/Circle.js',
194-
195-
'src/physics/p2/World.js',
196-
'src/physics/p2/PointProxy.js',
197-
'src/physics/p2/InversePointProxy.js',
198-
'src/physics/p2/Body.js',
199-
'src/physics/p2/Spring.js',
200-
'src/physics/p2/Material.js',
201-
'src/physics/p2/ContactMaterial.js',
202-
'src/physics/p2/CollisionGroup.js',
203-
204186
'src/particles/Particles.js',
205187
'src/particles/arcade/ArcadeParticles.js',
206188
'src/particles/arcade/Emitter.js',
@@ -214,6 +196,26 @@ module.exports = function (grunt) {
214196
'src/Outro.js'
215197
],
216198

199+
p2: [
200+
'src/physics/p2/p2.js'
201+
'src/physics/p2/World.js',
202+
'src/physics/p2/PointProxy.js',
203+
'src/physics/p2/InversePointProxy.js',
204+
'src/physics/p2/Body.js',
205+
'src/physics/p2/Spring.js',
206+
'src/physics/p2/Material.js',
207+
'src/physics/p2/ContactMaterial.js',
208+
'src/physics/p2/CollisionGroup.js',
209+
],
210+
211+
ninja: [
212+
'src/physics/ninja/World.js',
213+
'src/physics/ninja/Body.js',
214+
'src/physics/ninja/AABB.js',
215+
'src/physics/ninja/Tile.js',
216+
'src/physics/ninja/Circle.js',
217+
],
218+
217219
clean: ['<%= compile_dir %>'],
218220

219221
concat: {
@@ -230,7 +232,13 @@ module.exports = function (grunt) {
230232
dest: '<%= compile_dir %>/pixi.js'
231233
},
232234

233-
// Phaser, stand-alone (no bundled libs)
235+
// Our custom version of Ninja Physics
236+
ninja: {
237+
src: ['<%= ninja %>'],
238+
dest: '<%= compile_dir %>/ninja.js'
239+
},
240+
241+
// Phaser with no bundled libs
234242
phaser: {
235243
options: {
236244
banner: '<%= banner %>'
@@ -244,7 +252,7 @@ module.exports = function (grunt) {
244252
options: {
245253
banner: '<%= banner %>'
246254
},
247-
src: ['<%= compile_dir %>/p2.js', '<%= compile_dir %>/pixi.js', '<%= compile_dir %>/phaser-no-libs.js'],
255+
src: ['<%= compile_dir %>/pixi.js', '<%= compile_dir %>/phaser-no-libs.js', '<%= compile_dir %>/ninja.js', '<%= compile_dir %>/p2.js'],
248256
dest: '<%= compile_dir %>/phaser.js'
249257
}
250258

@@ -268,6 +276,14 @@ module.exports = function (grunt) {
268276
dest: '<%= compile_dir %>/pixi.min.js'
269277
},
270278

279+
ninja: {
280+
options: {
281+
banner: '/* Ninja Physics for Phaser v<%= pkg.version %> - http://phaser.io - @photonstorm - (c) 2014 Photon Storm Ltd. */\n'
282+
},
283+
src: ['<%= concat.ninja.dest %>'],
284+
dest: '<%= compile_dir %>/ninja.min.js'
285+
},
286+
271287
phaser: {
272288
options: {
273289
banner: '/* Phaser (no libs) v<%= pkg.version %> - http://phaser.io - @photonstorm - (c) 2014 Photon Storm Ltd. */\n'
@@ -301,6 +317,8 @@ module.exports = function (grunt) {
301317
{ src: ['dist/phaser-no-libs.min.js'], dest: 'build/custom/phaser-no-libs.min.js' },
302318
{ src: ['dist/pixi.js'], dest: 'build/custom/pixi.js' },
303319
{ src: ['dist/pixi.min.js'], dest: 'build/custom/pixi.min.js' }
320+
{ src: ['dist/ninja.js'], dest: 'build/custom/ninja.js' },
321+
{ src: ['dist/ninja.min.js'], dest: 'build/custom/ninja.min.js' }
304322
]
305323
}
306324
},

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ New features:
145145
* Group.xy(index, x, y) allows you to set the x and y coordinates of a Group child at the given index.
146146
* Group.reverse() reverses the display order of all children in the Group.
147147
* Tweens are now bound to their own TweenManager, not always the global game one. So you can create your own managers now (for you clark :)
148-
* json is now the default tilemap format when not defined (thanks RyanDansie, #528)
148+
* ScaleManager.fullScreenTarget allows you to change the DOM element that the fullscreen API is called on (feature request #526)
149149

150150

151151
Updates:
@@ -175,6 +175,7 @@ Updates:
175175
* Keyboard.event now stores the most recent DOM keyboard event.
176176
* Animation.stop has a new parameter: dispatchComplete. If true it'll dispatch an Animation.onComplete event.
177177
* TileSprites now have a physics body property and call it in the pre and post updates. As with all physics bodies it's null by default.
178+
* json is now the default tilemap format when not defined (thanks RyanDansie, #528)
178179

179180

180181
Bug Fixes:

build/config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
echo <<<EOL
88
9-
<script src="$path/src/p2.js"></script>
9+
<script src="$path/src/physics/p2/p2.js"></script>
1010
1111
<script src="$path/src/pixi/Pixi.js"></script>
1212
<script src="$path/src/pixi/core/Point.js"></script>

src/core/ScaleManager.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@ Phaser.ScaleManager = function (game, width, height) {
120120
*/
121121
this.hasResized = new Phaser.Signal();
122122

123+
/**
124+
* This is the DOM element that will have the Full Screen mode called on it. It defaults to the game canvas, but can be retargetted to any valid DOM element.
125+
* If you adjust this property it's up to you to see it has the correct CSS applied, and that you have contained the game canvas correctly.
126+
* Note that if you use a scale property of EXACT_FIT then fullScreenTarget will have its width and height style set to 100%.
127+
* @property {any} fullScreenTarget
128+
*/
129+
this.fullScreenTarget = this.game.canvas;
130+
123131
/**
124132
* @property {Phaser.Signal} enterFullScreen - The event that is dispatched when the browser enters full screen mode (if it supports the FullScreen API).
125133
*/
@@ -277,11 +285,11 @@ Phaser.ScaleManager.prototype = {
277285

278286
if (this.game.device.fullscreenKeyboard)
279287
{
280-
this.game.canvas[this.game.device.requestFullscreen](Element.ALLOW_KEYBOARD_INPUT);
288+
this.fullScreenTarget[this.game.device.requestFullscreen](Element.ALLOW_KEYBOARD_INPUT);
281289
}
282290
else
283291
{
284-
this.game.canvas[this.game.device.requestFullscreen]();
292+
this.fullScreenTarget[this.game.device.requestFullscreen]();
285293
}
286294

287295
},
@@ -292,7 +300,7 @@ Phaser.ScaleManager.prototype = {
292300
*/
293301
stopFullScreen: function () {
294302

295-
this.game.canvas[this.game.device.cancelFullscreen]();
303+
this.fullScreenTarget[this.game.device.cancelFullscreen]();
296304

297305
},
298306

@@ -310,8 +318,8 @@ Phaser.ScaleManager.prototype = {
310318
{
311319
if (this.fullScreenScaleMode === Phaser.ScaleManager.EXACT_FIT)
312320
{
313-
this.game.canvas.style['width'] = '100%';
314-
this.game.canvas.style['height'] = '100%';
321+
this.fullScreenTarget.style['width'] = '100%';
322+
this.fullScreenTarget.style['height'] = '100%';
315323

316324
this.width = window.outerWidth;
317325
this.height = window.outerHeight;
@@ -334,8 +342,8 @@ Phaser.ScaleManager.prototype = {
334342
}
335343
else
336344
{
337-
this.game.canvas.style['width'] = this.game.width + 'px';
338-
this.game.canvas.style['height'] = this.game.height + 'px';
345+
this.fullScreenTarget.style['width'] = this.game.width + 'px';
346+
this.fullScreenTarget.style['height'] = this.game.height + 'px';
339347

340348
this.width = this._width;
341349
this.height = this._height;

src/p2.js renamed to src/physics/p2/p2.js

Lines changed: 67 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1953,6 +1953,33 @@ function Narrowphase(){
19531953
*/
19541954
this.restitution = 0;
19551955

1956+
/**
1957+
* The stiffness value to use in the next contact equations.
1958+
* @property {Number} stiffness
1959+
*/
1960+
this.stiffness = 1e7;
1961+
1962+
/**
1963+
* The stiffness value to use in the next contact equations.
1964+
* @property {Number} stiffness
1965+
*/
1966+
this.relaxation = 3;
1967+
1968+
/**
1969+
* The stiffness value to use in the next friction equations.
1970+
* @property frictionStiffness
1971+
* @type {Number}
1972+
*/
1973+
this.frictionStiffness = 1e7;
1974+
1975+
/**
1976+
* The relaxation value to use in the next friction equations.
1977+
* @property frictionRelaxation
1978+
* @type {Number}
1979+
*/
1980+
this.frictionRelaxation = 3;
1981+
1982+
19561983
// Keep track of the colliding bodies last step
19571984
this.collidingBodiesLastStep = { keys:[] };
19581985
};
@@ -2041,6 +2068,8 @@ Narrowphase.prototype.createContactEquation = function(bodyA,bodyB,shapeA,shapeB
20412068
c.shapeB = shapeB;
20422069
c.restitution = this.restitution;
20432070
c.firstImpact = !this.collidedLastStep(bodyA,bodyB);
2071+
c.stiffness = this.stiffness;
2072+
c.relaxation = this.relaxation;
20442073
c.enabled = true;
20452074

20462075
if(bodyA.allowSleep && (bodyA.motionState == Body.DYNAMIC) && !(bodyB.motionState == Body.STATIC || bodyB.sleepState === Body.SLEEPY))
@@ -2068,6 +2097,8 @@ Narrowphase.prototype.createFrictionEquation = function(bodyA,bodyB,shapeA,shape
20682097
c.frictionCoefficient = this.frictionCoefficient;
20692098
c.relativeVelocity = this.surfaceVelocity;
20702099
c.enabled = true;
2100+
c.frictionStiffness = this.frictionStiffness;
2101+
c.frictionRelaxation = this.frictionRelaxation;
20712102
return c;
20722103
};
20732104

@@ -5439,8 +5470,8 @@ ContactEquation.prototype.computeB = function(a,b,h){
54395470
Gq = 0;
54405471
GW = (1/b)*(1+this.restitution) * this.computeGW();
54415472
} else {
5442-
GW = this.computeGW();
54435473
Gq = vec2.dot(n,penetrationVec);
5474+
GW = this.computeGW();
54445475
}
54455476

54465477
var GiMf = this.computeGiMf();
@@ -6946,9 +6977,19 @@ function Body(options){
69466977
this.wlambda = 0;
69476978

69486979
/**
6949-
* The angle of the body
6980+
* The angle of the body, in radians.
69506981
* @property angle
69516982
* @type {number}
6983+
* @example
6984+
* // The angle property is not normalized to the interval 0 to 2*pi, it can be any value.
6985+
* // If you need a value between 0 and 2*pi, use the following function to normalize it.
6986+
* function normalizeAngle(angle){
6987+
* angle = angle % (2*Math.PI);
6988+
* if(angle < 0){
6989+
* angle += (2*Math.PI);
6990+
* }
6991+
* return angle;
6992+
* }
69526993
*/
69536994
this.angle = options.angle || 0;
69546995

@@ -8803,7 +8844,7 @@ GSSolver.prototype.solve = function(h,world){
88038844
lambda = this.lambda;
88048845
if(!useGlobalParams){
88058846
for(var i=0, c; c = equations[i]; i++){
8806-
if(h !== c.h) c.updateSpookParams(h);
8847+
c.updateSpookParams(h);
88078848
Bs[i] = c.computeB(c.a,c.b,h);
88088849
invCs[i] = c.computeInvC(c.eps);
88098850
}
@@ -9465,6 +9506,10 @@ function World(options){
94659506
*/
94669507
this.defaultRestitution = 0.0;
94679508

9509+
this.defaultMaterial = new Material();
9510+
9511+
this.defaultContactMaterial = new ContactMaterial(this.defaultMaterial,this.defaultMaterial);
9512+
94689513
/**
94699514
* For keeping track of what time step size we used last step
94709515
* @property lastTimeStep
@@ -9863,20 +9908,26 @@ World.prototype.internalStep = function(dt){
98639908
xj = bj.shapeOffsets[l],
98649909
aj = bj.shapeAngles[l];
98659910

9911+
/*
98669912
var mu = this.defaultFriction,
98679913
restitution = this.defaultRestitution,
98689914
surfaceVelocity = 0;
9915+
*/
98699916

9917+
var cm = this.defaultContactMaterial;
98709918
if(si.material && sj.material){
9871-
var cm = this.getContactMaterial(si.material,sj.material);
9872-
if(cm){
9919+
var tmp = this.getContactMaterial(si.material,sj.material);
9920+
if(tmp){
9921+
cm = tmp;
9922+
/*
98739923
mu = cm.friction;
98749924
restitution = cm.restitution;
98759925
surfaceVelocity = cm.surfaceVelocity;
9926+
*/
98769927
}
98779928
}
98789929

9879-
this.runNarrowphase(np,bi,si,xi,ai,bj,sj,xj,aj,mu,restitution,surfaceVelocity,glen);
9930+
this.runNarrowphase(np,bi,si,xi,ai,bj,sj,xj,aj,cm,glen);
98809931
}
98819932
}
98829933
}
@@ -10031,7 +10082,7 @@ World.integrateBody = function(body,dt){
1003110082
* @param {Number} aj
1003210083
* @param {Number} mu
1003310084
*/
10034-
World.prototype.runNarrowphase = function(np,bi,si,xi,ai,bj,sj,xj,aj,mu,restitution,surfaceVelocity,glen){
10085+
World.prototype.runNarrowphase = function(np,bi,si,xi,ai,bj,sj,xj,aj,cm,glen){ /* mu,restitution,surfaceVelocity */
1003510086

1003610087
if(!((si.collisionGroup & sj.collisionMask) !== 0 && (sj.collisionGroup & si.collisionMask) !== 0))
1003710088
return;
@@ -10051,18 +10102,22 @@ World.prototype.runNarrowphase = function(np,bi,si,xi,ai,bj,sj,xj,aj,mu,restitut
1005110102
var ajw = aj + bj.angle;
1005210103

1005310104
// Run narrowphase
10054-
np.enableFriction = mu > 0;
10055-
np.frictionCoefficient = mu;
10105+
np.enableFriction = cm.friction > 0;
10106+
np.frictionCoefficient = cm.friction;
1005610107
var reducedMass;
1005710108
if(bi.motionState == Body.STATIC || bi.motionState == Body.KINEMATIC)
1005810109
reducedMass = bj.mass;
1005910110
else if(bj.motionState == Body.STATIC || bj.motionState == Body.KINEMATIC)
1006010111
reducedMass = bi.mass;
1006110112
else
1006210113
reducedMass = (bi.mass*bj.mass)/(bi.mass+bj.mass);
10063-
np.slipForce = mu*glen*reducedMass;
10064-
np.restitution = restitution;
10065-
np.surfaceVelocity = surfaceVelocity;
10114+
np.slipForce = cm.friction*glen*reducedMass;
10115+
np.restitution = cm.restitution;
10116+
np.surfaceVelocity = cm.surfaceVelocity;
10117+
np.frictionStiffness = cm.frictionStiffness;
10118+
np.frictionRelaxation = cm.frictionRelaxation;
10119+
np.stiffness = cm.stiffness;
10120+
np.relaxation = cm.relaxation;
1006610121

1006710122
var resolver = np[si.type | sj.type],
1006810123
numContacts = 0;

0 commit comments

Comments
 (0)