-
Notifications
You must be signed in to change notification settings - Fork 325
Expand file tree
/
Copy pathSurfaceGestureExample.java
More file actions
160 lines (128 loc) · 5.31 KB
/
SurfaceGestureExample.java
File metadata and controls
160 lines (128 loc) · 5.31 KB
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
package org.andengine.examples;
import org.andengine.engine.camera.Camera;
import org.andengine.engine.handler.timer.ITimerCallback;
import org.andengine.engine.handler.timer.TimerHandler;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.EngineOptions.ScreenOrientation;
import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.andengine.entity.modifier.ScaleModifier;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.scene.background.Background;
import org.andengine.entity.text.Text;
import org.andengine.entity.text.Text.TextOptions;
import org.andengine.entity.util.FPSLogger;
import org.andengine.input.touch.detector.SurfaceGestureDetector.SurfaceGestureDetectorAdapter;
import org.andengine.opengl.font.Font;
import org.andengine.opengl.font.FontFactory;
import org.andengine.opengl.texture.TextureOptions;
import org.andengine.ui.activity.SimpleBaseGameActivity;
import org.andengine.util.HorizontalAlign;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.Toast;
/**
* (c) 2012 Ryan Antiquiera
*
* @author Ryan Antiquiera
* @since 15:44:58 - 03.14.2012
*/
public class SurfaceGestureExample extends SimpleBaseGameActivity {
// ===========================================================
// Constants
// ===========================================================
private static final int CAMERA_WIDTH = 720;
private static final int CAMERA_HEIGHT = 480;
// ===========================================================
// Fields
// ===========================================================
private SurfaceGestureDetectorAdapter mSGDA;
private Font mFont;
private Scene mScene;
// ===========================================================
// Constructors
// ===========================================================
// ===========================================================
// Getter & Setter
// ===========================================================
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
@Override
protected void onCreate(final Bundle pSavedInstanceState) {
super.onCreate(pSavedInstanceState);
this.mSGDA = new SurfaceGestureDetectorAdapter(){
@Override
protected boolean onSingleTap() {
onSurfaceGesture("Tap");
return false;
}
@Override
protected boolean onSwipeDown() {
onSurfaceGesture("Swipe\nDown");
return false;
}
@Override
protected boolean onSwipeLeft() {
onSurfaceGesture("Swipe\nLeft");
return false;
}
@Override
protected boolean onSwipeRight() {
onSurfaceGesture("Swipe\nRight");
return false;
}
@Override
protected boolean onSwipeUp() {
onSurfaceGesture("Swipe\nUp");
return false;
}
@Override
protected boolean onDoubleTap() {
onSurfaceGesture("Double\nTap");
return false;
}
};
this.mSGDA.setEnabled(true);
}
@Override
protected void onCreateResources() {
/* Load the font we are going to use. */
FontFactory.setAssetBasePath("font/");
this.mFont = FontFactory.createFromAsset(this.getFontManager(), this.getTextureManager(), 512, 512, TextureOptions.BILINEAR, this.getAssets(), "Plok.ttf", 32, true, Color.WHITE);
this.mFont.load();
}
@Override
public EngineOptions onCreateEngineOptions() {
Toast.makeText(this, "Try tap, double tap, and swipe!", Toast.LENGTH_LONG).show();
final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
return new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera);
}
@Override
protected Scene onCreateScene() {
this.mEngine.registerUpdateHandler(new FPSLogger());
this.mScene = new Scene();
this.mScene.setBackground(new Background(0.09804f, 0.6274f, 0.8784f));
this.mScene.setOnSceneTouchListener(this.mSGDA);
return this.mScene;
}
// ===========================================================
// Methods
// ===========================================================
void onSurfaceGesture(CharSequence text) {
final Text gestureText = new Text(0, 0, this.mFont, text, new TextOptions(HorizontalAlign.CENTER), this.getVertexBufferObjectManager());
gestureText.setPosition((CAMERA_WIDTH - gestureText.getWidth()) * 0.5f, (CAMERA_HEIGHT - gestureText.getHeight()) * 0.5f);
gestureText.setScale(0.0f);
gestureText.registerEntityModifier(new ScaleModifier(0.5f, 0.0f, 2f));
this.mScene.attachChild(gestureText);
this.mScene.registerUpdateHandler(new TimerHandler(1.5f, new ITimerCallback() {
@Override
public void onTimePassed(final TimerHandler pTimerHandler) {
SurfaceGestureExample.this.mScene.unregisterUpdateHandler(pTimerHandler);
SurfaceGestureExample.this.mScene.detachChild(gestureText);
}
}));
}
// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
}