我正在尝试创建一个简单的场景并展示它,但它不起作用,我找不到我做错了什么。
这是我的主要活动
public class MainActivity extends BaseGameActivity implements IOnSceneTouchListener{
final static String TAG = "BounceTest";
Scene scene;
float downX;
float downY;
@Override
public EngineOptions onCreateEngineOptions() {
Log.d(TAG, "onCreateEngineOptions");
return new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new FillResolutionPolicy(), new Camera(0, 0, 800, 480));
}
@Override
public void onCreateResources(OnCreateResourcesCallback pOnCreateResourcesCallback) throws Exception {
Log.d(TAG, "onCreateResources");
}
@Override
public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback) throws Exception {
Log.d(TAG, "onCreateScene");
scene = new Scene(){
@Override
protected void onManagedUpdate(float pSecondsElapsed) {
Log.d(TAG, "onManagedUpdate");
super.onManagedUpdate(pSecondsElapsed);
}
};
this.getEngine().setScene(scene);
scene.setOnSceneTouchListener(this);
}
@Override
public void onPopulateScene(Scene pScene, OnPopulateSceneCallback pOnPopulateSceneCallback) throws Exception {
Log.d(TAG, "onPopulateScene");
Rectangle floor = new Rectangle(-200, 0, 1000, 20, this.getVertexBufferObjectManager());
Rectangle square = new Rectangle(0, 20, 20, 20, this.getVertexBufferObjectManager());
scene.attachChild(floor);
scene.attachChild(square);
}
@Override
public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) {
Log.d(TAG, "onSceneTouchEvent");
if(pSceneTouchEvent.getAction() == TouchEvent.ACTION_DOWN){
downX = pSceneTouchEvent.getX();
downY = pSceneTouchEvent.getY();
}else if(pSceneTouchEvent.getAction() == TouchEvent.ACTION_UP){
float upX = pSceneTouchEvent.getX();
float upY = pSceneTouchEvent.getY();
float xDiff = downX - upX;
float yDiff = downY - upY;
float dragLength = (float)Math.sqrt(xDiff*xDiff+yDiff*yDiff);
Log.d(TAG, "dragLength:"+dragLength);
}
return false;
}
}
我在手机上只能看到黑屏(矩形不存在),“onManagedUpdate”不显示,触摸屏幕不会调用 onSceneTouchEvent。
为什么呢?