Input Component done and new Button object done and included. Also finished the build script.

This commit is contained in:
Richard Davey 2013-09-09 00:30:44 +01:00
parent 50624c1552
commit 9b6c819e0e
16 changed files with 26055 additions and 29119 deletions

37
build/build.php Normal file
View file

@ -0,0 +1,37 @@
<textarea style="width: 800px; height: 800px">
<?php
$js = file('../examples/js.php');
$output = "";
for ($i = 0; $i < count($js); $i++)
{
// <script src="../src/Phaser.js"></script>
$line = trim($js[$i]);
if (strpos($line, '<script') !== false)
{
$line = str_replace('<script src="', '', $line);
$line = str_replace('"></script>', '', $line);
echo $line . "\n";
// Read the file in
$source = file_get_contents($line);
if ($i == 4)
{
// Built at: {buildDate}
$source = str_replace('{buildDate}', date('r'), $source);
}
$output .= $source . "\n";
}
}
//echo $output;
file_put_contents('phaser.js', $output);
?>
</textarea>

File diff suppressed because it is too large Load diff

1
build/phaser-min.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load diff

25389
build/phaser.js Normal file

File diff suppressed because it is too large Load diff

36
examples/a_template.php Normal file
View file

@ -0,0 +1,36 @@
<!DOCTYPE HTML>
<html>
<head>
<title>phaser.js - a new beginning</title>
<?php
require('js.php');
?>
</head>
<body>
<script type="text/javascript">
(function () {
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, render: render });
function preload() {
game.load.image('atari1', 'assets/sprites/atari130xe.png');
}
function create() {
// var tempSprite = game.add.sprite(game.world.randomX, game.world.randomY, game.rnd.pick(images));
}
function render() {
}
})();
</script>
</body>
</html>

View file

@ -0,0 +1,55 @@
<!DOCTYPE HTML>
<html>
<head>
<title>phaser.js - a new beginning</title>
<?php
require('js.php');
?>
</head>
<body>
<script type="text/javascript">
(function () {
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, render: render });
function preload() {
game.load.image('atari1', 'assets/sprites/atari130xe.png');
game.load.image('atari2', 'assets/sprites/atari800xl.png');
game.load.image('atari4', 'assets/sprites/atari800.png');
game.load.image('sonic', 'assets/sprites/sonic_havok_sanity.png');
game.load.image('duck', 'assets/sprites/darkwing_crazy.png');
game.load.image('firstaid', 'assets/sprites/firstaid.png');
game.load.image('diamond', 'assets/sprites/diamond.png');
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
}
function create() {
// This returns an array of all the image keys in the cache
var images = game.cache.getImageKeys();
var test = game.add.group();
// Now let's create some random sprites and enable them all for drag and 'bring to top'
for (var i = 0; i < 20; i++)
{
var tempSprite = test.create(game.world.randomX, game.world.randomY, game.rnd.pick(images));
tempSprite.inputEnabled = true;
tempSprite.input.enableDrag(false, true);
}
}
function render() {
game.debug.renderInputInfo(32, 32);
}
})();
</script>
</body>
</html>

65
examples/button1.php Normal file
View file

@ -0,0 +1,65 @@
<!DOCTYPE HTML>
<html>
<head>
<title>phaser.js - a new beginning</title>
<?php
require('js.php');
?>
</head>
<body>
<script type="text/javascript">
(function () {
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, render: render });
function preload() {
game.load.image('beast', 'assets/pics/shadow_of_the_beast2_karamoon.png');
game.load.spritesheet('button', 'assets/buttons/button_sprite_sheet.png', 193, 71);
}
var image;
var button;
function create() {
// This is just an image that we'll toggle the display of when you click the button
image = game.add.sprite(game.world.centerX, 0, 'beast');
image.anchor.setTo(0.5, 0);
// This button is created from a sprite sheet.
// Frame 0 = the 'down' state
// Frame 1 = the 'out' state
// Frame 2 = the 'over' state
// The function "clickedIt" will be called when the button is clicked or touched
button = game.add.button(game.world.centerX, 400, 'button', clickedIt, this, 2, 1, 0);
// Just makes the button origin set to the middle, we only do this to center the button on-screen, no other reason
button.anchor.setTo(0.5, 0.5);
}
function clickedIt() {
if (image.visible == true)
{
image.visible = false;
}
else
{
image.visible = true;
}
}
function render() {
}
})();
</script>
</body>
</html>

116
examples/js-physics.php Normal file
View file

@ -0,0 +1,116 @@
<?php
// All JS files in build order.
// Much easier for debugging
?>
<script src="../src/pixi/Pixi.js"></script>
<script src="../src/Phaser.js"></script>
<script src="../src/utils/Utils.js"></script>
<script src="../src/pixi/core/Matrix.js"></script>
<script src="../src/pixi/core/Point.js"></script>
<script src="../src/pixi/core/Rectangle.js"></script>
<script src="../src/pixi/display/DisplayObject.js"></script>
<script src="../src/pixi/display/DisplayObjectContainer.js"></script>
<script src="../src/pixi/display/Sprite.js"></script>
<script src="../src/pixi/display/MovieClip.js"></script>
<script src="../src/pixi/display/Stage.js"></script>
<script src="../src/pixi/extras/CustomRenderable.js"></script>
<script src="../src/pixi/extras/Strip.js"></script>
<script src="../src/pixi/extras/Rope.js"></script>
<script src="../src/pixi/extras/Spine.js"></script>
<script src="../src/pixi/extras/TilingSprite.js"></script>
<script src="../src/pixi/filters/FilterBlock.js"></script>
<script src="../src/pixi/filters/MaskFilter.js"></script>
<script src="../src/pixi/primitives/Graphics.js"></script>
<script src="../src/pixi/renderers/canvas/CanvasGraphics.js"></script>
<script src="../src/pixi/renderers/canvas/CanvasRenderer.js"></script>
<script src="../src/pixi/renderers/webgl/WebGLBatch.js"></script>
<script src="../src/pixi/renderers/webgl/WebGLGraphics.js"></script>
<script src="../src/pixi/renderers/webgl/WebGLRenderer.js"></script>
<script src="../src/pixi/renderers/webgl/WebGLRenderGroup.js"></script>
<script src="../src/pixi/renderers/webgl/WebGLShaders.js"></script>
<script src="../src/pixi/text/BitmapText.js"></script>
<script src="../src/pixi/text/Text.js"></script>
<script src="../src/pixi/textures/BaseTexture.js"></script>
<script src="../src/pixi/textures/Texture.js"></script>
<script src="../src/pixi/textures/RenderTexture.js"></script>
<script src="../src/pixi/utils/EventTarget.js"></script>
<script src="../src/pixi/utils/Polyk.js"></script>
<script src="../src/core/Camera.js"></script>
<script src="../src/core/State.js"></script>
<script src="../src/core/StateManager.js"></script>
<script src="../src/core/LinkedList.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/Group.js"></script>
<script src="../src/core/World.js"></script>
<script src="../src/core/Game.js"></script>
<script src="../src/input/Input.js"></script>
<script src="../src/input/Keyboard.js"></script>
<script src="../src/input/Mouse.js"></script>
<script src="../src/input/MSPointer.js"></script>
<script src="../src/input/Pointer.js"></script>
<script src="../src/input/Touch.js"></script>
<script src="../src/input/InputHandler.js"></script>
<script src="../src/system/Canvas.js"></script>
<script src="../src/gameobjects/Events.js"></script>
<script src="../src/gameobjects/GameObjectFactory.js"></script>
<script src="../src/gameobjects/Sprite.js"></script>
<script src="../src/gameobjects/TileSprite.js"></script>
<script src="../src/gameobjects/Text.js"></script>
<script src="../src/system/Canvas.js"></script>
<script src="../src/system/Device.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/math/QuadTree.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>
<script src="../src/tween/Tween.js"></script>
<script src="../src/tween/Easing.js"></script>
<script src="../src/time/Time.js"></script>
<script src="../src/animation/AnimationManager.js"></script>
<script src="../src/animation/Animation.js"></script>
<script src="../src/animation/Frame.js"></script>
<script src="../src/animation/FrameData.js"></script>
<script src="../src/animation/Parser.js"></script>
<script src="../src/loader/Cache.js"></script>
<script src="../src/loader/Loader.js"></script>
<script src="../src/sound/Sound.js"></script>
<script src="../src/sound/SoundManager.js"></script>
<script src="../src/utils/Debug.js"></script>
<script src="../src/physics/arcade/ArcadePhysics.js"></script>
<script src="../src/physics/arcade/Body.js"></script>
<script src="../src/physics/advanced/Math.js"></script>
<script src="../src/physics/advanced/Util.js"></script>
<script src="../src/physics/advanced/Collision.js"></script>
<script src="../src/physics/advanced/Body.js"></script>
<script src="../src/physics/advanced/Joint.js"></script>
<script src="../src/physics/advanced/Shape.js"></script>
<script src="../src/physics/advanced/Contact.js"></script>
<script src="../src/physics/advanced/ContactSolver.js"></script>
<script src="../src/physics/advanced/Space.js"></script>
<script src="../src/physics/advanced/joints/Angle.js"></script>
<script src="../src/physics/advanced/joints/Revolute.js"></script>
<script src="../src/physics/advanced/joints/Weld.js"></script>
<script src="../src/physics/advanced/joints/Wheel.js"></script>
<script src="../src/physics/advanced/joints/Prismatic.js"></script>
<script src="../src/physics/advanced/joints/Distance.js"></script>
<script src="../src/physics/advanced/joints/Rope.js"></script>
<script src="../src/physics/advanced/joints/Mouse.js"></script>
<script src="../src/physics/advanced/shapes/Circle.js"></script>
<script src="../src/physics/advanced/shapes/Segment.js"></script>
<script src="../src/physics/advanced/shapes/Poly.js"></script>
<script src="../src/physics/advanced/shapes/Triangle.js"></script>
<script src="../src/physics/advanced/shapes/Box.js"></script>

View file

@ -2,16 +2,13 @@
// All JS files in build order. // All JS files in build order.
// Much easier for debugging // Much easier for debugging
?> ?>
<script src="../src/Intro.js"></script>
<script src="../src/pixi/Pixi.js"></script>
<script src="../src/Phaser.js"></script> <script src="../src/Phaser.js"></script>
<script src="../src/utils/Utils.js"></script> <script src="../src/utils/Utils.js"></script>
<script src="../src/pixi/Pixi.js"></script>
<script src="../src/pixi/InteractionManager.js"></script>
<script src="../src/pixi/core/Circle.js"></script>
<script src="../src/pixi/core/Ellipse.js"></script>
<script src="../src/pixi/core/Matrix.js"></script> <script src="../src/pixi/core/Matrix.js"></script>
<script src="../src/pixi/core/Point.js"></script> <script src="../src/pixi/core/Point.js"></script>
<script src="../src/pixi/core/Polygon.js"></script>
<script src="../src/pixi/core/Rectangle.js"></script> <script src="../src/pixi/core/Rectangle.js"></script>
<script src="../src/pixi/display/DisplayObject.js"></script> <script src="../src/pixi/display/DisplayObject.js"></script>
<script src="../src/pixi/display/DisplayObjectContainer.js"></script> <script src="../src/pixi/display/DisplayObjectContainer.js"></script>
@ -40,7 +37,6 @@
<script src="../src/pixi/textures/RenderTexture.js"></script> <script src="../src/pixi/textures/RenderTexture.js"></script>
<script src="../src/pixi/utils/EventTarget.js"></script> <script src="../src/pixi/utils/EventTarget.js"></script>
<script src="../src/pixi/utils/Polyk.js"></script> <script src="../src/pixi/utils/Polyk.js"></script>
<script src="../src/pixi/utils/Utils.js"></script>
<script src="../src/core/Camera.js"></script> <script src="../src/core/Camera.js"></script>
<script src="../src/core/State.js"></script> <script src="../src/core/State.js"></script>
@ -67,6 +63,7 @@
<script src="../src/gameobjects/Sprite.js"></script> <script src="../src/gameobjects/Sprite.js"></script>
<script src="../src/gameobjects/TileSprite.js"></script> <script src="../src/gameobjects/TileSprite.js"></script>
<script src="../src/gameobjects/Text.js"></script> <script src="../src/gameobjects/Text.js"></script>
<script src="../src/gameobjects/Button.js"></script>
<script src="../src/system/Canvas.js"></script> <script src="../src/system/Canvas.js"></script>
<script src="../src/system/Device.js"></script> <script src="../src/system/Device.js"></script>
<script src="../src/system/RequestAnimationFrame.js"></script> <script src="../src/system/RequestAnimationFrame.js"></script>
@ -94,27 +91,3 @@
<script src="../src/physics/arcade/ArcadePhysics.js"></script> <script src="../src/physics/arcade/ArcadePhysics.js"></script>
<script src="../src/physics/arcade/Body.js"></script> <script src="../src/physics/arcade/Body.js"></script>
<script src="../src/physics/advanced/Math.js"></script>
<script src="../src/physics/advanced/Util.js"></script>
<script src="../src/physics/advanced/Collision.js"></script>
<script src="../src/physics/advanced/Body.js"></script>
<script src="../src/physics/advanced/Joint.js"></script>
<script src="../src/physics/advanced/Shape.js"></script>
<script src="../src/physics/advanced/Contact.js"></script>
<script src="../src/physics/advanced/ContactSolver.js"></script>
<script src="../src/physics/advanced/Space.js"></script>
<script src="../src/physics/advanced/joints/Angle.js"></script>
<script src="../src/physics/advanced/joints/Revolute.js"></script>
<script src="../src/physics/advanced/joints/Weld.js"></script>
<script src="../src/physics/advanced/joints/Wheel.js"></script>
<script src="../src/physics/advanced/joints/Prismatic.js"></script>
<script src="../src/physics/advanced/joints/Distance.js"></script>
<script src="../src/physics/advanced/joints/Rope.js"></script>
<script src="../src/physics/advanced/joints/Mouse.js"></script>
<script src="../src/physics/advanced/shapes/Circle.js"></script>
<script src="../src/physics/advanced/shapes/Segment.js"></script>
<script src="../src/physics/advanced/shapes/Poly.js"></script>
<script src="../src/physics/advanced/shapes/Triangle.js"></script>
<script src="../src/physics/advanced/shapes/Box.js"></script>

120
examples/js_full.php Normal file
View file

@ -0,0 +1,120 @@
<?php
// All JS files in build order.
// Much easier for debugging
?>
<script src="../src/Phaser.js"></script>
<script src="../src/utils/Utils.js"></script>
<script src="../src/pixi/Pixi.js"></script>
<script src="../src/pixi/InteractionManager.js"></script>
<script src="../src/pixi/core/Circle.js"></script>
<script src="../src/pixi/core/Ellipse.js"></script>
<script src="../src/pixi/core/Matrix.js"></script>
<script src="../src/pixi/core/Point.js"></script>
<script src="../src/pixi/core/Polygon.js"></script>
<script src="../src/pixi/core/Rectangle.js"></script>
<script src="../src/pixi/display/DisplayObject.js"></script>
<script src="../src/pixi/display/DisplayObjectContainer.js"></script>
<script src="../src/pixi/display/Sprite.js"></script>
<script src="../src/pixi/display/MovieClip.js"></script>
<script src="../src/pixi/display/Stage.js"></script>
<script src="../src/pixi/extras/CustomRenderable.js"></script>
<script src="../src/pixi/extras/Strip.js"></script>
<script src="../src/pixi/extras/Rope.js"></script>
<script src="../src/pixi/extras/Spine.js"></script>
<script src="../src/pixi/extras/TilingSprite.js"></script>
<script src="../src/pixi/filters/FilterBlock.js"></script>
<script src="../src/pixi/filters/MaskFilter.js"></script>
<script src="../src/pixi/primitives/Graphics.js"></script>
<script src="../src/pixi/renderers/canvas/CanvasGraphics.js"></script>
<script src="../src/pixi/renderers/canvas/CanvasRenderer.js"></script>
<script src="../src/pixi/renderers/webgl/WebGLBatch.js"></script>
<script src="../src/pixi/renderers/webgl/WebGLGraphics.js"></script>
<script src="../src/pixi/renderers/webgl/WebGLRenderer.js"></script>
<script src="../src/pixi/renderers/webgl/WebGLRenderGroup.js"></script>
<script src="../src/pixi/renderers/webgl/WebGLShaders.js"></script>
<script src="../src/pixi/text/BitmapText.js"></script>
<script src="../src/pixi/text/Text.js"></script>
<script src="../src/pixi/textures/BaseTexture.js"></script>
<script src="../src/pixi/textures/Texture.js"></script>
<script src="../src/pixi/textures/RenderTexture.js"></script>
<script src="../src/pixi/utils/EventTarget.js"></script>
<script src="../src/pixi/utils/Polyk.js"></script>
<script src="../src/pixi/utils/Utils.js"></script>
<script src="../src/core/Camera.js"></script>
<script src="../src/core/State.js"></script>
<script src="../src/core/StateManager.js"></script>
<script src="../src/core/LinkedList.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/Group.js"></script>
<script src="../src/core/World.js"></script>
<script src="../src/core/Game.js"></script>
<script src="../src/input/Input.js"></script>
<script src="../src/input/Keyboard.js"></script>
<script src="../src/input/Mouse.js"></script>
<script src="../src/input/MSPointer.js"></script>
<script src="../src/input/Pointer.js"></script>
<script src="../src/input/Touch.js"></script>
<script src="../src/input/InputHandler.js"></script>
<script src="../src/system/Canvas.js"></script>
<script src="../src/gameobjects/Events.js"></script>
<script src="../src/gameobjects/GameObjectFactory.js"></script>
<script src="../src/gameobjects/Sprite.js"></script>
<script src="../src/gameobjects/TileSprite.js"></script>
<script src="../src/gameobjects/Text.js"></script>
<script src="../src/system/Canvas.js"></script>
<script src="../src/system/Device.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/math/QuadTree.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>
<script src="../src/tween/Tween.js"></script>
<script src="../src/tween/Easing.js"></script>
<script src="../src/time/Time.js"></script>
<script src="../src/animation/AnimationManager.js"></script>
<script src="../src/animation/Animation.js"></script>
<script src="../src/animation/Frame.js"></script>
<script src="../src/animation/FrameData.js"></script>
<script src="../src/animation/Parser.js"></script>
<script src="../src/loader/Cache.js"></script>
<script src="../src/loader/Loader.js"></script>
<script src="../src/sound/Sound.js"></script>
<script src="../src/sound/SoundManager.js"></script>
<script src="../src/utils/Debug.js"></script>
<script src="../src/physics/arcade/ArcadePhysics.js"></script>
<script src="../src/physics/arcade/Body.js"></script>
<script src="../src/physics/advanced/Math.js"></script>
<script src="../src/physics/advanced/Util.js"></script>
<script src="../src/physics/advanced/Collision.js"></script>
<script src="../src/physics/advanced/Body.js"></script>
<script src="../src/physics/advanced/Joint.js"></script>
<script src="../src/physics/advanced/Shape.js"></script>
<script src="../src/physics/advanced/Contact.js"></script>
<script src="../src/physics/advanced/ContactSolver.js"></script>
<script src="../src/physics/advanced/Space.js"></script>
<script src="../src/physics/advanced/joints/Angle.js"></script>
<script src="../src/physics/advanced/joints/Revolute.js"></script>
<script src="../src/physics/advanced/joints/Weld.js"></script>
<script src="../src/physics/advanced/joints/Wheel.js"></script>
<script src="../src/physics/advanced/joints/Prismatic.js"></script>
<script src="../src/physics/advanced/joints/Distance.js"></script>
<script src="../src/physics/advanced/joints/Rope.js"></script>
<script src="../src/physics/advanced/joints/Mouse.js"></script>
<script src="../src/physics/advanced/shapes/Circle.js"></script>
<script src="../src/physics/advanced/shapes/Segment.js"></script>
<script src="../src/physics/advanced/shapes/Poly.js"></script>
<script src="../src/physics/advanced/shapes/Triangle.js"></script>
<script src="../src/physics/advanced/shapes/Box.js"></script>

21
src/Intro.js Normal file
View file

@ -0,0 +1,21 @@
/**
* Phaser - http://www.phaser.io
*
* v1.0.0 - Built at: {buildDate}
*
* @author Richard Davey http://www.photonstorm.com @photonstorm
*
* A feature-packed 2D HTML5 game framework born from the smouldering pits of Flixel and
* constructed via plenty of blood, sweat, tears and coffee by Richard Davey (@photonstorm).
*
* Phaser uses Pixi.js for rendering, created by Mat Groves http://matgroves.com/ @Doormat23.
*
* Follow Phaser development progress at http://www.photonstorm.com
*
* Many thanks to Adam Saltsman (@ADAMATOMIC) for releasing Flixel, from both which Phaser
* and my love of game development originate.
*
* "If you want your children to be intelligent, read them fairy tales."
* "If you want them to be more intelligent, read them more fairy tales."
* -- Albert Einstein
*/

View file

@ -1,25 +1,3 @@
/**
* Phaser - http://www.phaser.io
*
* v1.0.0 - Released at some point during 2013
*
* @author Richard Davey http://www.photonstorm.com @photonstorm
*
* A feature-packed 2D HTML5 game framework born from the smouldering pits of Flixel and
* constructed via plenty of blood, sweat, tears and coffee by Richard Davey (@photonstorm).
*
* Many thanks to Adam Saltsman (@ADAMATOMIC) for releasing Flixel, from both which Phaser
* and my love of game development originate.
*
* Internally Phaser uses pixi.js by Mat Groves http://matgroves.com/ @Doormat23 for rendering.
*
* Follow Phaser development progress at http://www.photonstorm.com
*
* "If you want your children to be intelligent, read them fairy tales."
* "If you want them to be more intelligent, read them more fairy tales."
* -- Albert Einstein
*/
/** /**
* @module Phaser * @module Phaser
*/ */
@ -32,3 +10,8 @@ var Phaser = Phaser || {
WEBGL: 2 WEBGL: 2
}; };
PIXI.InteractionManager = function (dummy) {
// We don't need this in Pixi, so we've removed it to save space
// however the Stage object expects a reference to it, so here is a dummy entry.
};

160
src/gameobjects/Button.js Normal file
View file

@ -0,0 +1,160 @@
/**
* Create a new <code>Button</code> object.
*
* @param game {Phaser.Game} Current game instance.
* @param [x] {number} X position of the button.
* @param [y] {number} Y position of the button.
* @param [key] {string} The image key as defined in the Game.Cache to use as the texture for this button.
* @param [callback] {function} The function to call when this button is pressed
* @param [callbackContext] {object} The context in which the callback will be called (usually 'this')
* @param [overFrame] {string|number} This is the frame or frameName that will be set when this button is in an over state. Give either a number to use a frame ID or a string for a frame name.
* @param [outFrame] {string|number} This is the frame or frameName that will be set when this button is in an out state. Give either a number to use a frame ID or a string for a frame name.
* @param [downFrame] {string|number} This is the frame or frameName that will be set when this button is in a down state. Give either a number to use a frame ID or a string for a frame name.
*/
Phaser.Button = function (game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame) {
x = x || 0;
y = y || 0;
key = key || null;
callback = callback || null;
callbackContext = callbackContext || this;
overFrame = overFrame || null;
outFrame = outFrame || null;
downFrame = downFrame || null;
Phaser.Sprite.call(this, game, x, y, key, outFrame);
// this.texture = PIXI.TextureCache[key];
this._onOverFrameName = null;
this._onOutFrameName = null;
this._onDownFrameName = null;
this._onUpFrameName = null;
this._onOverFrameID = null;
this._onOutFrameID = null;
this._onDownFrameID = null;
this._onUpFrameID = null;
if (typeof overFrame == 'string')
{
this._onOverFrameName = overFrame;
}
else
{
this._onOverFrameID = overFrame;
}
if (typeof outFrame == 'string')
{
this._onOutFrameName = outFrame;
this._onUpFrameName = outFrame;
}
else
{
this._onOutFrameID = outFrame;
this._onUpFrameID = outFrame;
}
if (typeof downFrame == 'string')
{
this._onDownFrameName = downFrame;
}
else
{
this._onDownFrameID = downFrame;
}
// These are the signals the game will subscribe to
this.onInputOver = new Phaser.Signal();
this.onInputOut = new Phaser.Signal();
this.onInputDown = new Phaser.Signal();
this.onInputUp = new Phaser.Signal();
// Set a default signal for them
if (callback)
{
this.onInputUp.add(callback, callbackContext);
}
this.input.start(0, false, true);
// Redirect the input events to here so we can handle animation updates, etc
this.events.onInputOver.add(this.onInputOverHandler, this);
this.events.onInputOut.add(this.onInputOutHandler, this);
this.events.onInputDown.add(this.onInputDownHandler, this);
this.events.onInputUp.add(this.onInputUpHandler, this);
};
Phaser.Button.prototype = Phaser.Utils.extend(true, Phaser.Sprite.prototype, PIXI.Sprite.prototype);
Phaser.Button.prototype.constructor = Phaser.Button;
// Add our own custom methods
Phaser.Button.prototype.onInputOverHandler = function (pointer) {
if (this._onOverFrameName != null)
{
this.frameName = this._onOverFrameName;
}
else if(this._onOverFrameID != null)
{
this.frame = this._onOverFrameID;
}
if (this.onInputOver)
{
this.onInputOver.dispatch(this, pointer);
}
};
Phaser.Button.prototype.onInputOutHandler = function (pointer) {
if (this._onOutFrameName != null)
{
this.frameName = this._onOutFrameName;
}
else if (this._onOutFrameID != null)
{
this.frame = this._onOutFrameID;
}
if (this.onInputOut)
{
this.onInputOut.dispatch(this, pointer);
}
};
Phaser.Button.prototype.onInputDownHandler = function (pointer) {
if (this._onDownFrameName != null)
{
this.frameName = this._onDownFrameName;
}
else if (this._onDownFrameID != null)
{
this.frame = this._onDownFrameID;
}
if (this.onInputDown)
{
this.onInputDown.dispatch(this, pointer);
}
};
Phaser.Button.prototype.onInputUpHandler = function (pointer) {
if (this._onUpFrameName != null)
{
this.frameName = this._onUpFrameName;
}
else if (this._onUpFrameID != null)
{
this.frame = this._onUpFrameID;
}
if (this.onInputUp)
{
this.onInputUp.dispatch(this, pointer);
}
};

View file

@ -79,5 +79,10 @@ Phaser.GameObjectFactory.prototype = {
}, },
button: function (x, y, key, callback, callbackContext, overFrame, outFrame, downFrame) {
return this.world.add(new Phaser.Button(this.game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame));
},
}; };

View file

@ -103,4 +103,45 @@ Phaser.Utils = {
return target; return target;
} }
} };
// Global functions that PIXI needs
/**
* Converts a hex color number to an [R, G, B] array
*
* @method HEXtoRGB
* @param hex {Number}
*/
function HEXtoRGB(hex) {
return [(hex >> 16 & 0xFF) / 255, ( hex >> 8 & 0xFF) / 255, (hex & 0xFF)/ 255];
}
/**
* A polyfill for Function.prototype.bind
*
* @method bind
*/
if (typeof Function.prototype.bind != 'function') {
Function.prototype.bind = (function () {
var slice = Array.prototype.slice;
return function (thisArg) {
var target = this, boundArgs = slice.call(arguments, 1);
if (typeof target != 'function') throw new TypeError();
function bound() {
var args = boundArgs.concat(slice.call(arguments));
target.apply(this instanceof bound ? this : thisArg, args);
}
bound.prototype = (function F(proto) {
proto && (F.prototype = proto);
if (!(this instanceof F)) return new F;
})(target.prototype);
return bound;
};
})();
}