0
ANDEngine
을 사용하는 아래 코드는 SimpleBaseGameActivity
에서 잘 작동한다고 가정합니다. 여기서 2 Sprite
은 움직이고 움직입니다. 그러나 surfaceGestureDetector
개체를 선언하기 때문에 이미지가 왜곡됩니다. 나는 그 물건을 사용하지도 않았다. 댓글 작성하여surfaceGestureDetector 객체 선언, 전체 이미지 왜곡
gDetector = new SurfaceGestureDetector(this){...}
모든 것이 정상으로 바뀝니다. 누군가가 잘못 된 것을 조언 할 수 있습니까? 감사!
public class MainActivity extends SimpleBaseGameActivity
{
private Camera camera;
private static final int CAMERA_WIDTH = 800;
private static final int CAMERA_HEIGHT = 480;
private BitmapTextureAtlas yourTexture;
private TiledTextureRegion yourTextureRegion;
private SurfaceGestureDetector gDetector;
@Override
public EngineOptions onCreateEngineOptions()
{
camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
EngineOptions engineOptions = new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED,
new FillResolutionPolicy(), camera);
engineOptions.getTouchOptions().setNeedsMultiTouch(true);
return engineOptions;
}
@Override
public void onCreateResources()
{
loadGraphics();
}
private void loadGraphics()
{
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
yourTexture = new BitmapTextureAtlas(getTextureManager(), 50, 200, TextureOptions.BILINEAR);
yourTextureRegion =BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(yourTexture, this, "snowman_animate.png", 0, 0, 1, 4);
yourTexture.load();
}
@Override
public Scene onCreateScene() {
Scene scene = new Scene();
scene.setBackground(new Background(0.6004f, 0.6274f, 0.8784f));
gDetector = new SurfaceGestureDetector(this){
@Override
protected boolean onSwipeUp() {
return false;
}
@Override
protected boolean onSwipeRight() {
return false;
}
@Override
protected boolean onSwipeLeft() {
return false;
}
@Override
protected boolean onSwipeDown() {
return false;
}
@Override
protected boolean onSingleTap() {
return false;
}
@Override
protected boolean onDoubleTap() {
return false;
}
};
MySprite yourSprite = new MySprite(200, 400, yourTextureRegion, this.getVertexBufferObjectManager());
MySprite yourSprite2 = new MySprite(300, 200, yourTextureRegion, this.getVertexBufferObjectManager());
long[] frameDurration = {250, 250, 250, 250};
yourSprite.animate(frameDurration);
yourSprite2.animate(frameDurration);
scene.attachChild(yourSprite);
scene.attachChild(yourSprite2);
return scene;
}
private static class MySprite extends AnimatedSprite {
private final PhysicsHandler mPhysicsHandler;
public MySprite
(final float pX, final float pY, final TiledTextureRegion pTextureRegion, final VertexBufferObjectManager pVertexBufferObjectManager) {
super(pX, pY, pTextureRegion, pVertexBufferObjectManager);
this.mPhysicsHandler = new PhysicsHandler(this);
this.registerUpdateHandler(this.mPhysicsHandler);
this.mPhysicsHandler.setVelocity(0, 120);
}
@Override
protected void onManagedUpdate(final float pSecondsElapsed) {
if(this.mY < 0) {
this.mPhysicsHandler.setVelocityY(120);
} else if(this.mY + this.getHeight() > CAMERA_HEIGHT) {
this.mPhysicsHandler.setVelocityY(-120);
}
super.onManagedUpdate(pSecondsElapsed);
}
}
}