Skip to content

Commit 8cfe963

Browse files
authored
Merge pull request #30 from orange-games/dev
v2 release
2 parents d8df76f + 2655eb6 commit 8cfe963

13 files changed

+449
-281
lines changed

README.md

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ Key features:
1212
* Easy configurable
1313
* Production hardened
1414

15-
15+
*Imporant*
16+
From here on this library will be published and updated under [@orange-games/phaser-input](https://www.npmjs.com/package/@orange-games/phaser-input) at NPM, the old [phaser-input](https://www.npmjs.com/package/phaser-input) will no longer be maintained.
17+
If you are comming from v1 you can read the migration guide at the bottom
1618
Getting Started
1719
---------------
1820
First you want to get a fresh copy of the plugin. You can get it from this repo or from npm, ain't that handy.
@@ -27,7 +29,7 @@ Next up you'd want to add it to your list of js sources you load into your game
2729

2830
After adding the script to the page you can activate it by enabling the plugin:
2931
```javascript
30-
game.add.plugin(Fabrique.Plugins.InputField);
32+
game.add.plugin(PhaserInput.Plugin);
3133
```
3234

3335
Usage
@@ -51,7 +53,7 @@ var password = game.add.inputField(10, 90, {
5153
borderColor: '#000',
5254
borderRadius: 6,
5355
placeHolder: 'Password',
54-
type: Fabrique.InputType.password
56+
type: PhaserInput.InputType.password
5557
});
5658
```
5759
### Using zoom
@@ -61,17 +63,17 @@ First of all, it's only meant for mobile. Second; it modifies the scale and pivo
6163

6264
Also, when the keyboard is shown, sometimes a resize event will be triggered.
6365

64-
Ideally you use a custom resize event, check for the static property `Fabrique.Plugins.InputField.KeyboardOpen` and don't resize when it's set to true.
66+
Ideally you use a custom resize event, check for the static property `PhaserInput.KeyboardOpen` and don't resize when it's set to true.
6567

6668
### Using keyboard open/close signals
6769
Current version includes two event dispatchers that notify when a device keyboard is opened or closed.
6870

6971
You can add listeners which trigger events based on this feedback.
7072

7173
```javascript
72-
Fabrique.Plugins.InputField.onKeyboardClose.addOnce(function() {
73-
this.resizeBackgroundImage();
74-
});
74+
PhaserInput.onKeyboardClose.addOnce(function() {
75+
this.resizeBackgroundImage();
76+
});
7577
```
7678

7779
### Capture input events
@@ -125,6 +127,17 @@ Tested on:
125127
* Chrome 48+
126128
* iOS 9+
127129

130+
Migrating from v1
131+
-----------------
132+
the API of the objects is the same as before but the namespace changed. We decided to remove the Fabrique namespace, and house the plugin in it's own (PhaserInput).
133+
so:
134+
Fabrique.Plugins.Input
135+
becomes:
136+
PhaserInput.Plugin
137+
138+
and all other references of Fabrique.Plugins can be replaced with PhaserInput.
139+
If you are still unsure how or what, both the example and this readme have been adjusted to work with the new namespace.
140+
128141
FAQ
129142
---
130143
### I Don't see the cursor blinking!
@@ -138,6 +151,25 @@ update: function () {
138151
},
139152
```
140153

154+
### How do I focus on the element!
155+
Normally the element is only focused trough user interaction (due to mobile limitations) you can get around this by manually calling the focus method yourself:
156+
```javascript
157+
var input = game.add.inputField(10, 90);
158+
//start with focus on the element
159+
input.startFocus();
160+
161+
//and then end the focus
162+
input.endFocus();
163+
```
164+
Please note that this will not work on mobile wihtout a user interaction
165+
166+
### Can I change the width later on in the code?
167+
Well thanks for asking, yes you can!
168+
```javascript
169+
var input = game.add.inputField(10, 90);
170+
input.width = 200;
171+
```
172+
141173
Credits
142174
-------
143175
phaser-input is inspired by [CanvasInput](https://github.com/goldfire/CanvasInput)

build/phaser-input.d.ts

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference path="../node_modules/phaser/typescript/pixi.d.ts" />
22
/// <reference path="../node_modules/phaser/typescript/phaser.d.ts" />
3-
declare module Fabrique {
3+
declare module PhaserInput {
44
enum InputType {
55
text = 0,
66
password = 1,
@@ -32,7 +32,7 @@ declare module Fabrique {
3232
setCaretPosition(pos: number): void;
3333
}
3434
}
35-
declare module Fabrique {
35+
declare module PhaserInput {
3636
interface InputOptions extends Phaser.PhaserTextStyle {
3737
x?: number;
3838
y?: number;
@@ -68,7 +68,9 @@ declare module Fabrique {
6868
private selection;
6969
private windowScale;
7070
blockInput: boolean;
71+
width: number;
7172
constructor(game: Phaser.Game, x: number, y: number, inputOptions?: InputOptions);
73+
private updateTextAlignment();
7274
private checkDown(e);
7375
private blink;
7476
private cnt;
@@ -89,12 +91,22 @@ declare module Fabrique {
8991
setText(text?: string): void;
9092
}
9193
}
92-
declare module Fabrique {
94+
declare module PhaserInput {
9395
class InputBox extends Phaser.Graphics {
96+
private bgColor;
97+
private borderRadius;
98+
private borderColor;
99+
private borderWidth;
100+
private boxAlpha;
101+
private boxHeight;
102+
private padding;
103+
private boxWidth;
94104
constructor(game: Phaser.Game, inputOptions: InputOptions);
105+
resize(newWidth: number): void;
106+
private drawBox();
95107
}
96108
}
97-
declare module Fabrique {
109+
declare module PhaserInput {
98110
class SelectionHighlight extends Phaser.Graphics {
99111
private inputOptions;
100112
constructor(game: Phaser.Game, inputOptions: InputOptions);
@@ -107,30 +119,36 @@ declare module Fabrique {
107119
}): number;
108120
}
109121
}
110-
declare module Fabrique {
122+
declare module PhaserInput {
111123
class TextMask extends Phaser.Graphics {
124+
private maskWidth;
125+
private maskHeight;
112126
constructor(game: Phaser.Game, inputOptions: InputOptions);
127+
resize(newWidth: number): void;
128+
private drawMask();
113129
}
114130
}
115-
declare module Fabrique {
116-
module Plugins {
117-
interface InputFieldObjectFactory extends Phaser.GameObjectFactory {
118-
inputField: (x: number, y: number, inputOptions?: Fabrique.InputOptions, group?: Phaser.Group) => Fabrique.InputField;
119-
}
120-
interface InputFieldObjectCreator extends Phaser.GameObjectCreator {
121-
inputField: (x: number, y: number, inputOptions?: Fabrique.InputOptions) => Fabrique.InputField;
122-
}
123-
interface InputFieldGame extends Phaser.Game {
124-
add: InputFieldObjectFactory;
125-
make: InputFieldObjectCreator;
126-
}
127-
class InputField extends Phaser.Plugin {
128-
static Zoomed: boolean;
129-
static KeyboardOpen: boolean;
130-
static onKeyboardOpen: Phaser.Signal;
131-
static onKeyboardClose: Phaser.Signal;
132-
constructor(game: Phaser.Game, parent: Phaser.PluginManager);
133-
private addInputFieldFactory();
134-
}
131+
declare module PhaserInput {
132+
var Zoomed: boolean;
133+
var KeyboardOpen: boolean;
134+
const onKeyboardOpen: Phaser.Signal;
135+
const onKeyboardClose: Phaser.Signal;
136+
interface InputFieldObjectFactory extends Phaser.GameObjectFactory {
137+
inputField: (x: number, y: number, inputOptions?: PhaserInput.InputOptions, group?: Phaser.Group) => PhaserInput.InputField;
138+
}
139+
interface InputFieldObjectCreator extends Phaser.GameObjectCreator {
140+
inputField: (x: number, y: number, inputOptions?: PhaserInput.InputOptions) => PhaserInput.InputField;
141+
}
142+
interface InputFieldGame extends Phaser.Game {
143+
add: InputFieldObjectFactory;
144+
make: InputFieldObjectCreator;
145+
}
146+
class Plugin extends Phaser.Plugin {
147+
static Zoomed: boolean;
148+
static KeyboardOpen: boolean;
149+
static onKeyboardOpen: Phaser.Signal;
150+
static onKeyboardClose: Phaser.Signal;
151+
constructor(game: Phaser.Game, parent: Phaser.PluginManager);
152+
private addInputFieldFactory();
135153
}
136154
}

0 commit comments

Comments
 (0)