forked from nicolasgramlich/AndEngineExamples
-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathETC1TextureExample.java
More file actions
145 lines (119 loc) · 4.82 KB
/
ETC1TextureExample.java
File metadata and controls
145 lines (119 loc) · 4.82 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
package org.andengine.examples;
import java.io.IOException;
import java.io.InputStream;
import org.andengine.engine.camera.SmoothCamera;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.andengine.entity.scene.IOnSceneTouchListener;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.scene.background.Background;
import org.andengine.entity.sprite.Sprite;
import org.andengine.entity.util.FPSLogger;
import org.andengine.examples.adt.ZoomState;
import org.andengine.input.touch.TouchEvent;
import org.andengine.opengl.texture.ITexture;
import org.andengine.opengl.texture.TextureOptions;
import org.andengine.opengl.texture.compressed.etc1.ETC1Texture;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.opengl.texture.region.TextureRegionFactory;
import org.andengine.ui.activity.SimpleBaseGameActivity;
import org.andengine.util.debug.Debug;
import android.widget.Toast;
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga
*
* @author Nicolas Gramlich
* @since 11:54:51 - 03.04.2010
*/
public class ETC1TextureExample extends SimpleBaseGameActivity {
// ===========================================================
// Constants
// ===========================================================
private static final int CAMERA_WIDTH = 720;
private static final int CAMERA_HEIGHT = 480;
// ===========================================================
// Fields
// ===========================================================
private SmoothCamera mSmoothCamera;
private ITexture mTexture;
private ITextureRegion mHouseTextureRegion;
private ZoomState mZoomState = ZoomState.NONE;
// ===========================================================
// Constructors
// ===========================================================
// ===========================================================
// Getter & Setter
// ===========================================================
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
@Override
public EngineOptions onCreateEngineOptions() {
Toast.makeText(this, "Click the top half of the screen to zoom in or the bottom half to zoom out!", Toast.LENGTH_LONG).show();
this.mSmoothCamera = new SmoothCamera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT, 0, 0, 0.1f) {
@Override
public void onUpdate(final float pSecondsElapsed) {
switch (ETC1TextureExample.this.mZoomState) {
case IN:
this.setZoomFactor(this.getZoomFactor() + 0.1f * pSecondsElapsed);
break;
case OUT:
this.setZoomFactor(this.getZoomFactor() - 0.1f * pSecondsElapsed);
break;
default:
break;
}
super.onUpdate(pSecondsElapsed);
}
};
return new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), this.mSmoothCamera);
}
@Override
public void onCreateResources() {
try {
this.mTexture = new ETC1Texture(this.getTextureManager(), TextureOptions.BILINEAR) {
@Override
protected InputStream getInputStream() throws IOException {
return ETC1TextureExample.this.getResources().openRawResource(R.raw.house_etc1);
}
};
this.mTexture.load();
this.mHouseTextureRegion = TextureRegionFactory.extractFromTexture(this.mTexture, 0, 0, 512, 512);
} catch (final Throwable e) {
Debug.e(e);
}
}
@Override
public Scene onCreateScene() {
this.mEngine.registerUpdateHandler(new FPSLogger());
final Scene scene = new Scene();
scene.setBackground(new Background(0.09804f, 0.6274f, 0.8784f));
final float centerX = (CAMERA_WIDTH - this.mHouseTextureRegion.getWidth()) / 2;
final float centerY = (CAMERA_HEIGHT - this.mHouseTextureRegion.getHeight()) / 2;
scene.attachChild(new Sprite(centerX, centerY, this.mHouseTextureRegion, this.getVertexBufferObjectManager()));
scene.setOnSceneTouchListener(new IOnSceneTouchListener() {
@Override
public boolean onSceneTouchEvent(final Scene pScene, final TouchEvent pSceneTouchEvent) {
if (pSceneTouchEvent.isActionDown() || pSceneTouchEvent.isActionMove()) {
if(pSceneTouchEvent.getY() < CAMERA_HEIGHT / 2) {
ETC1TextureExample.this.mZoomState = ZoomState.IN;
} else {
ETC1TextureExample.this.mZoomState = ZoomState.OUT;
}
} else {
ETC1TextureExample.this.mZoomState = ZoomState.NONE;
}
return true;
}
});
return scene;
}
// ===========================================================
// Methods
// ===========================================================
// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
}