public class MainActivity extends BaseGameActivity {
private static final int CAMERA_WIDTH =800;
private static final int CAMERA_HEIGHT =480;
private RepeatingSpriteBackgroundbackground;
private Camera mCamera;
private TiledTextureRegionmFaceTextureRegion;
private Font mfont,autofont;
Text textCenter,autotext;
Boolean is=false;
Sprite face;
@Override
public EngineOptions onCreateEngineOptions(){
// TODO 自动生成的方法存根
mCamera = newCamera(0,0,CAMERA_WIDTH,CAMERA_HEIGHT);
EngineOptions mEngineOptions =new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED,
newRatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), mCamera);
return mEngineOptions;
}
@Override
public voidonCreateResources(OnCreateResourcesCallbackpOnCreateResourcesCallback)
throwsException {
// TODO 自动生成的方法存根
this.background = newRepeatingSpriteBackground(CAMERA_WIDTH,CAMERA_HEIGHT,
getTextureManager(),AssetBitmapTextureAtlasSource.create(
this.getAssets(), "background.png"),
getVertexBufferObjectManager());
BitmapTextureAtlas mTexture =new BitmapTextureAtlas(getTextureManager(),
400,118,TextureOptions.BILINEAR_PREMULTIPLYALPHA);
mFaceTextureRegion =BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(mTexture,
this,"face.png",0 ,0,3,1);//2列1行
mTexture.load();
BitmapTextureAtlasmfonttexture=new BitmapTextureAtlas(
getTextureManager(),256, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
mfont=newFont(getFontManager(),mfonttexture,
Typeface.create(Typeface.DEFAULT,Typeface.BOLD),20,true,Color.RED);
mfonttexture.load();
mfont.load();
BitmapTextureAtlasautofonttexture=new BitmapTextureAtlas(
getTextureManager(),256, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
autofont=newFont(getFontManager(),autofonttexture,
Typeface.create(Typeface.DEFAULT,Typeface.BOLD),20,true,Color.RED);
autofonttexture.load();
autofont.load();
pOnCreateResourcesCallback.onCreateResourcesFinished();
}
@Override
public void onCreateScene(OnCreateSceneCallbackpOnCreateSceneCallback) throws Exception {
// TODO 自动生成的方法存根
Scene scene=new Scene();
scene.setBackground(background);
final Dong as=newDong(20,
100,mFaceTextureRegion, getVertexBufferObjectManager());
textCenter = new Text(10, 10,mfont,
"Velocity_X:\nVelocity_Y:\n"+
"Accleration_X:\nAccleration_Y:",getVertexBufferObjectManager());
autotext=new Text(110, 10,autofont, "Velocity_X:\nVelocity_Y:\n"+
"Accleration_X:\n Accleration_Y: ",getVertexBufferObjectManager());
//as.move();
scene.setOnSceneTouchListener(as);
scene.attachChild(textCenter);
scene.attachChild(autotext);
scene.registerUpdateHandler(new IUpdateHandler(){
@Override
public void reset() {
// TODO自动生成的方法存根
}
@Override
public void onUpdate(floatarg0) {
// TODO自动生成的方法存根
autotext.setText(String.valueOf(as.mvel)+"\n"+
String.valueOf(as.mvely)+"\n "+String.valueOf(as.AccelerationX)+"\n "+
String.valueOf(as.AccelerationY)
);
}
});
scene.attachChild(as);
pOnCreateSceneCallback.onCreateSceneFinished(scene);
}
@Override
public void onPopulateScene(Scene pScene,
OnPopulateSceneCallbackpOnPopulateSceneCallback)
throwsException {
// TODO 自动生成的方法存根
pOnPopulateSceneCallback.onPopulateSceneFinished();
}
public class Dong extends AnimatedSpriteimplements IOnSceneTouchListener{
privatePhysicsHandler mphy;
privatefloat mvel=200;
privatefloat mvely=200;
privatestatic final int maxvx=500;