我正在使用AndEngine开发Android应用,我试图查看是否有功能,功能或解决方法,只需能够在多点触控上缩放整个页面(如当你想缩放手机上的图片时)。有人可以提供帮助。
为简单起见,我们假设我们想要在AndEngine的Line示例中添加多点触控缩放功能作为最简单的示例。以下是代码和截图。
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;
}
}
答案 0 :(得分:1)