Reputation: 1
I'm developing an Android app using AndEngine, and I'm trying to see if there is a feature, or function, or workaround to simply be able to zoom the whole page on multi-touch (like when you want to zoom a picture on your phone). Can someone help on that.
For simplicity, let's assume we want to add a multi-touch zoom feature to the AndEngine's Lines example as the simplest example. Following is the code and screenshot.
package org.andengine.examples;
import java.util.Random;
import org.andengine.engine.camera.Camera;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.andengine.entity.primitive.Line;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.util.FPSLogger;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.ui.activity.SimpleBaseGameActivity;
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 11:54:51 - 03.04.2010
*/
public class LineExample extends SimpleBaseGameActivity {
// ===========================================================
// Constants
// ===========================================================
/* Initializing the Random generator produces a comparable result over different versions. */
private static final long RANDOM_SEED = 1234567890;
private static final int CAMERA_WIDTH = 720;
private static final int CAMERA_HEIGHT = 480;
private static final int LINE_COUNT = 100;
@Override
public EngineOptions onCreateEngineOptions() {
final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
return new EngineOptions(true, ScreenOrientation.LANDSCAPE_SENSOR, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera);
}
@Override
public void onCreateResources() {
}
@Override
public Scene onCreateScene() {
this.mEngine.registerUpdateHandler(new FPSLogger());
final Scene scene = new Scene();
scene.getBackground().setColor(0.09804f, 0.6274f, 0.8784f);
final Random random = new Random(RANDOM_SEED);
final VertexBufferObjectManager vertexBufferObjectManager = this.getVertexBufferObjectManager();
for(int i = 0; i < LINE_COUNT; i++) {
final float x1 = random.nextFloat() * CAMERA_WIDTH;
final float x2 = random.nextFloat() * CAMERA_WIDTH;
final float y1 = random.nextFloat() * CAMERA_HEIGHT;
final float y2 = random.nextFloat() * CAMERA_HEIGHT;
final float lineWidth = random.nextFloat() * 5;
final Line line = new Line(x1, y1, x2, y2, lineWidth, vertexBufferObjectManager);
line.setColor(random.nextFloat(), random.nextFloat(), random.nextFloat());
scene.attachChild(line);
}
return scene;
}
}
Upvotes: 2
Views: 166
Reputation: 1199
It is possible to apply pinch to zoom camera.
Here's example: http://berenoune.blogspot.com/2013/11/andengine-gles2-anchorcenter-branch.html?m=1
Upvotes: 1