forked from azerion/phaser-input
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
160 lines (142 loc) · 5.63 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, shrink-to-fit=no" />
<title>Login example for Phaser Input</title>
<!-- Include Phaser Responsiveness JS -->
<script type="text/javascript" src="../node_modules/phaser/build/phaser.js"></script>
<script type="text/javascript" src="../node_modules/phaser-nineslice/build/phaser-nineslice.js"></script>
<script type="text/javascript" src="../build/phaser-input.js"></script>
<style type="text/css">
body {
margin: 0;
padding: 0;
}
canvas {
box-shadow: 0px 0px 5px black;
margin: 20px auto;
}
</style>
<!-- Game we want to track -->
<script type="text/javascript">
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { create: create, preload: preload}, true);
Phaser.Device.whenReady(function () {
game.plugins.add(Fabrique.Plugins.InputField);
game.plugins.add(Fabrique.Plugins.NineSlice);
});
function preload() {
game.load.image('bg', 'images/bg.png');
game.load.nineSlice('input', 'images/inputfield.png', 15);
game.load.nineSlice('btn', 'images/btn_clean.png', 20, 23, 27, 28);
}
function create(){
if (!game.device.desktop) {
game.scale.setGameSize(window.innerWidth, window.innerHeight);
}
//let's add a nice background
game.add.image(0, 0, 'bg');
//Oooe, there's a title here!
var login = game.add.text(game.width / 2, 100, 'Log in to this awesome game!', {
font: '30px Arial',
fill: '#ffffff'
});
login.anchor.set(0.5);
//Here's the input field for the user's name
var userBg = game.add.nineSlice(game.width / 2+ 5, 180, 'input', 200, 50);
userBg.anchor.set(0.5);
var user = game.add.inputField(game.width / 2 - 85, 180 - 17, {
font: '18px Arial',
fill: '#212121',
fillAlpha: 0,
fontWeight: 'bold',
width: 150,
max: 10,
padding: 8,
borderWidth: 1,
borderColor: '#000',
borderRadius: 6,
placeHolder: 'Username',
textAlign: 'center',
zoom: true
});
user.setText('prefilled name');
//We'd need a password too
var passBg = game.add.nineSlice(game.width / 2+ 5, 250, 'input', 200, 50);
passBg.anchor.set(0.5);
var password = game.add.inputField(game.width / 2 - 85, 250 - 17, {
font: '18px Arial',
fill: '#212121',
fillAlpha: 0,
fontWeight: 'bold',
width: 150,
padding: 8,
borderWidth: 1,
borderColor: '#000',
borderRadius: 6,
placeHolder: 'Password',
type: Fabrique.InputType.password,
zoom: true
});
//Let's not forget about age?!
var ageBg = game.add.nineSlice(game.width / 2 + 5, 320, 'input', 200, 50);
ageBg.anchor.set(0.5);
var age = game.add.inputField(game.width / 2 - 85, 320 - 17, {
font: '18px Arial',
fill: '#212121',
fillAlpha: 0,
fontWeight: 'bold',
width: 150,
padding: 8,
borderWidth: 1,
borderColor: '#000',
borderRadius: 6,
min: '18',
max: '99',
placeHolder: 'Your age',
type: Fabrique.InputType.number,
zoom: true
});
var submitBtn = game.add.nineSlice(game.width / 2 - 100, 360, 'btn', 100, 70);
var submit = game.add.text(game.width / 2 - 80, 380, 'Submit', {
font: '18px Arial'
});
submitBtn.inputEnabled = true;
submitBtn.input.useHandCursor = true;
submitBtn.events.onInputDown.add(function() {
game.add.text(30, 10, 'Welcome ' + user.value + '!', {
font: '18px Arial'
});
game.add.text(10, 50, 'Your password is: ' + password.value, {
font: '18px Arial'
});
login.destroy();
user.destroy();
password.destroy();
age.destroy();
submit.destroy();
});
var resetBtn = game.add.nineSlice(game.width / 2 + 10, 360, 'btn', 100, 70);
var reset = game.add.text(game.width / 2 + 35, 380, 'Reset', {
font: '18px Arial'
});
resetBtn.inputEnabled = true;
resetBtn.input.useHandCursor = true;
resetBtn.events.onInputDown.add(function() {
user.resetText();
password.resetText();
age.resetText();
});
Fabrique.Plugins.InputField.onKeyboardOpen.add(function () {
console.error("keyboard open", Fabrique.Plugins.InputField.KeyboardOpen)
});
Fabrique.Plugins.InputField.onKeyboardClose.add(function () {
console.error("keyboard close", Fabrique.Plugins.InputField.KeyboardOpen)
});
}
</script>
</head>
<body>
</body>
</html>