mirror of
https://github.com/photonstorm/phaser
synced 2024-11-10 07:04:31 +00:00
Added basic Webcam plugin.
Added Device.getUserMedia detection. Updated config.php so you can toggle physics engines on/off via flags. Updated Gruntfile.js so it builds a Phaser + Pixi but no Physics libs.
This commit is contained in:
parent
511b2f017a
commit
a7ff5f884c
5 changed files with 183 additions and 28 deletions
22
Gruntfile.js
22
Gruntfile.js
|
@ -276,6 +276,15 @@ module.exports = function (grunt) {
|
|||
dest: '<%= compile_dir %>/phaser-no-libs.js'
|
||||
},
|
||||
|
||||
// Phaser with pixi but no physics libs
|
||||
phaserNoPhysics: {
|
||||
options: {
|
||||
banner: '<%= banner %>'
|
||||
},
|
||||
src: ['<%= compile_dir %>/pixi.js', '<%= compile_dir %>/phaser-no-libs.js'],
|
||||
dest: '<%= compile_dir %>/phaser-no-physics.js'
|
||||
},
|
||||
|
||||
// One ring to rule them all
|
||||
standalone: {
|
||||
options: {
|
||||
|
@ -321,6 +330,14 @@ module.exports = function (grunt) {
|
|||
dest: '<%= compile_dir %>/phaser-no-libs.min.js'
|
||||
},
|
||||
|
||||
phaserNoPhysics: {
|
||||
options: {
|
||||
banner: '/* Phaser (no physics) v<%= pkg.version %> - http://phaser.io - @photonstorm - (c) 2014 Photon Storm Ltd. */\n'
|
||||
},
|
||||
src: ['<%= concat.phaserNoPhysics.dest %>'],
|
||||
dest: '<%= compile_dir %>/phaser-no-physics.min.js'
|
||||
},
|
||||
|
||||
standalone: {
|
||||
options: {
|
||||
sourceMap: true,
|
||||
|
@ -347,7 +364,10 @@ module.exports = function (grunt) {
|
|||
{ src: ['dist/pixi.js'], dest: 'build/custom/pixi.js' },
|
||||
{ src: ['dist/pixi.min.js'], dest: 'build/custom/pixi.min.js' },
|
||||
{ src: ['dist/ninja.js'], dest: 'build/custom/ninja.js' },
|
||||
{ src: ['dist/ninja.min.js'], dest: 'build/custom/ninja.min.js' }
|
||||
{ src: ['dist/ninja.min.js'], dest: 'build/custom/ninja.min.js' },
|
||||
{ src: ['dist/phaser-no-physics.js'], dest: 'build/custom/phaser-no-physics.js' },
|
||||
{ src: ['dist/phaser-no-physics.min.js'], dest: 'build/custom/phaser-no-physics.min.js' }
|
||||
|
||||
]
|
||||
}
|
||||
},
|
||||
|
|
|
@ -76,6 +76,14 @@ Updated:
|
|||
* P2.removeBody will check if the body is part of the world before removing, this avoids a TypeError from the p2 layer.
|
||||
* Tilemap.createFromObjects has a new parameter: adjustY, which is true by default. Because Tiled uses a bottom-left coordinate system Phaser used to set the Sprite anchor to 0,1 to compensate. If adjustY is true it now reduces the y value by the object height instead.
|
||||
* Swapped the order of the _pollGamepads gamepads check, to stop the Chrome 'webkitGamepads is deprecated' error in the console.
|
||||
* Lots of TypeScript definitions updates (thanks as always to clark for these)
|
||||
* Removed Device.patchAndroidClearRectBug as it's no longer used internally.
|
||||
* Math.wrapAngle now supports radians (thanks Cryszon, #597)
|
||||
|
||||
|
||||
New Features:
|
||||
|
||||
* Device.getUserMedia boolean added, useful if you need access to the webcam or microphone.
|
||||
|
||||
|
||||
TODO:
|
||||
|
|
|
@ -4,9 +4,27 @@
|
|||
$path = '..';
|
||||
}
|
||||
|
||||
echo <<<EOL
|
||||
if (!isset($p2))
|
||||
{
|
||||
$p2 = true;
|
||||
}
|
||||
|
||||
<script src="$path/src/physics/p2/p2.js"></script>
|
||||
if (!isset($ninja))
|
||||
{
|
||||
$ninja = true;
|
||||
}
|
||||
|
||||
if (!isset($arcade))
|
||||
{
|
||||
$arcade = true;
|
||||
}
|
||||
|
||||
if ($p2)
|
||||
{
|
||||
echo " <script src=\"$path/src/physics/p2/p2.js\"></script>";
|
||||
}
|
||||
|
||||
echo <<<EOL
|
||||
|
||||
<script src="$path/src/pixi/Pixi.js"></script>
|
||||
<script src="$path/src/pixi/core/Point.js"></script>
|
||||
|
@ -137,14 +155,30 @@
|
|||
|
||||
<script src="$path/src/physics/Physics.js"></script>
|
||||
|
||||
<script src="$path/src/particles/Particles.js"></script>
|
||||
<script src="$path/src/particles/arcade/ArcadeParticles.js"></script>
|
||||
<script src="$path/src/particles/arcade/Emitter.js"></script>
|
||||
|
||||
<script src="$path/src/tilemap/Tile.js"></script>
|
||||
<script src="$path/src/tilemap/Tilemap.js"></script>
|
||||
<script src="$path/src/tilemap/TilemapLayer.js"></script>
|
||||
<script src="$path/src/tilemap/TilemapParser.js"></script>
|
||||
<script src="$path/src/tilemap/Tileset.js"></script>
|
||||
EOL;
|
||||
|
||||
if ($arcade)
|
||||
{
|
||||
echo <<<EOL
|
||||
|
||||
<script src="$path/src/physics/arcade/World.js"></script>
|
||||
<script src="$path/src/physics/arcade/Body.js"></script>
|
||||
EOL;
|
||||
}
|
||||
|
||||
<script src="$path/src/physics/ninja/World.js"></script>
|
||||
<script src="$path/src/physics/ninja/Body.js"></script>
|
||||
<script src="$path/src/physics/ninja/AABB.js"></script>
|
||||
<script src="$path/src/physics/ninja/Tile.js"></script>
|
||||
<script src="$path/src/physics/ninja/Circle.js"></script>
|
||||
|
||||
if ($p2)
|
||||
{
|
||||
echo <<<EOL
|
||||
|
||||
<script src="$path/src/physics/p2/World.js"></script>
|
||||
<script src="$path/src/physics/p2/PointProxy.js"></script>
|
||||
|
@ -160,20 +194,22 @@
|
|||
<script src="$path/src/physics/p2/LockConstraint.js"></script>
|
||||
<script src="$path/src/physics/p2/PrismaticConstraint.js"></script>
|
||||
<script src="$path/src/physics/p2/RevoluteConstraint.js"></script>
|
||||
|
||||
<script src="$path/src/particles/Particles.js"></script>
|
||||
<script src="$path/src/particles/arcade/ArcadeParticles.js"></script>
|
||||
<script src="$path/src/particles/arcade/Emitter.js"></script>
|
||||
|
||||
<script src="$path/src/tilemap/Tile.js"></script>
|
||||
<script src="$path/src/tilemap/Tilemap.js"></script>
|
||||
<script src="$path/src/tilemap/TilemapLayer.js"></script>
|
||||
<script src="$path/src/tilemap/TilemapParser.js"></script>
|
||||
<script src="$path/src/tilemap/Tileset.js"></script>
|
||||
EOL;
|
||||
}
|
||||
|
||||
/*
|
||||
if ($ninja)
|
||||
{
|
||||
echo <<<EOL
|
||||
|
||||
*/
|
||||
<script src="$path/src/physics/arcade/World.js"></script>
|
||||
<script src="$path/src/physics/arcade/Body.js"></script>
|
||||
|
||||
<script src="$path/src/physics/ninja/World.js"></script>
|
||||
<script src="$path/src/physics/ninja/Body.js"></script>
|
||||
<script src="$path/src/physics/ninja/AABB.js"></script>
|
||||
<script src="$path/src/physics/ninja/Tile.js"></script>
|
||||
<script src="$path/src/physics/ninja/Circle.js"></script>
|
||||
EOL;
|
||||
}
|
||||
|
||||
?>
|
92
plugins/Webcam.js
Normal file
92
plugins/Webcam.js
Normal file
|
@ -0,0 +1,92 @@
|
|||
/**
|
||||
* Provides access to the Webcam (if available)
|
||||
*/
|
||||
Phaser.Plugin.Webcam = function (game, parent) {
|
||||
|
||||
Phaser.Plugin.call(this, game, parent);
|
||||
|
||||
if (!game.device.getUserMedia)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
|
||||
|
||||
this.context = null;
|
||||
this.stream = null;
|
||||
|
||||
this.video = document.createElement('video');
|
||||
this.video.autoplay = true;
|
||||
|
||||
};
|
||||
|
||||
Phaser.Plugin.Webcam.prototype = Object.create(Phaser.Plugin.prototype);
|
||||
Phaser.Plugin.Webcam.prototype.constructor = Phaser.Plugin.Webcam;
|
||||
|
||||
Phaser.Plugin.Webcam.prototype.start = function (width, height, context) {
|
||||
|
||||
console.log('Webcam start', width, height);
|
||||
|
||||
this.context = context;
|
||||
|
||||
if (!this.stream)
|
||||
{
|
||||
navigator.getUserMedia( { video: { mandatory: { minWidth: width, minHeight: height } } }, this.connectCallback.bind(this), this.errorCallback.bind(this));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Phaser.Plugin.Webcam.prototype.stop = function () {
|
||||
|
||||
if (this.stream)
|
||||
{
|
||||
this.stream.stop();
|
||||
this.stream = null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Phaser.Plugin.Webcam.prototype.connectCallback = function (stream) {
|
||||
|
||||
this.stream = stream;
|
||||
|
||||
this.video.src = window.URL.createObjectURL(this.stream);
|
||||
|
||||
};
|
||||
|
||||
Phaser.Plugin.Webcam.prototype.errorCallback = function (e) {
|
||||
|
||||
console.log('Video Stream rejected', e);
|
||||
|
||||
};
|
||||
|
||||
Phaser.Plugin.Webcam.prototype.grab = function (context, x, y) {
|
||||
|
||||
if (this.stream)
|
||||
{
|
||||
context.drawImage(this.video, x, y);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Phaser.Plugin.Webcam.prototype.update = function () {
|
||||
|
||||
if (this.stream)
|
||||
{
|
||||
this.context.drawImage(this.video, 0, 0);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @name Phaser.Plugin.Webcam#active
|
||||
* @property {boolean} active - Is this Webcam plugin capturing a video stream or not?
|
||||
* @readonly
|
||||
*/
|
||||
Object.defineProperty(Phaser.Plugin.Webcam.prototype, "active", {
|
||||
|
||||
get: function() {
|
||||
return (this.stream);
|
||||
}
|
||||
|
||||
});
|
|
@ -18,13 +18,6 @@ Phaser.Device = function (game) {
|
|||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* An optional 'fix' for the horrendous Android stock browser bug https://code.google.com/p/android/issues/detail?id=39247
|
||||
* @property {boolean} patchAndroidClearRectBug - Description.
|
||||
* @default
|
||||
*/
|
||||
this.patchAndroidClearRectBug = false;
|
||||
|
||||
// Operating System
|
||||
|
||||
/**
|
||||
|
@ -161,6 +154,12 @@ Phaser.Device = function (game) {
|
|||
*/
|
||||
this.vibration = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} getUserMedia - Does the device support the getUserMedia API?
|
||||
* @default
|
||||
*/
|
||||
this.getUserMedia = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} quirksMode - Is the browser running in strict mode (false) or quirks mode? (true)
|
||||
* @default
|
||||
|
@ -468,7 +467,7 @@ Phaser.Device.prototype = {
|
|||
|
||||
this.quirksMode = (document.compatMode === 'CSS1Compat') ? false : true;
|
||||
|
||||
|
||||
this.getUserMedia = !!(navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia);
|
||||
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in a new issue