您的位置:首页 > 其它

飞机

2016-07-27 17:51 225 查看
public class MainActivity extends BaseGameActivity {

 private static final int CAMERA_WIDTH =
800;

 private static final int CAMERA_HEIGHT =
480;

 private RepeatingSpriteBackground
background;

 private Camera mCamera;

 private TiledTextureRegion
mFaceTextureRegion;

 private Font mfont,autofont;

 Text textCenter,autotext;

 Boolean is=false;

 Sprite face;

 @Override

 public EngineOptions onCreateEngineOptions()
{

  // TODO 自动生成的方法存根

  mCamera = new
Camera(0,0,CAMERA_WIDTH,CAMERA_HEIGHT);

  EngineOptions mEngineOptions =
new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED,

    new
RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), mCamera);

  

  return mEngineOptions;

 }

 @Override

 public void
onCreateResources(OnCreateResourcesCallback
pOnCreateResourcesCallback)

   throws
Exception {

  // TODO 自动生成的方法存根

  this.background = new
RepeatingSpriteBackground(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();

  BitmapTextureAtlas
mfonttexture=new BitmapTextureAtlas(

    getTextureManager(),
256, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);

   mfont=new
Font(getFontManager(),mfonttexture,

    Typeface.create(Typeface.DEFAULT,
Typeface.BOLD),20,true,Color.RED);

  mfonttexture.load();

  mfont.load();

  BitmapTextureAtlas
autofonttexture=new BitmapTextureAtlas(

    getTextureManager(),
256, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);

   autofont=new
Font(getFontManager(),autofonttexture,

    Typeface.create(Typeface.DEFAULT,
Typeface.BOLD),20,true,Color.RED);

  autofonttexture.load();

  autofont.load();

  pOnCreateResourcesCallback.onCreateResourcesFinished();

  

 }

 @Override

 public void onCreateScene(OnCreateSceneCallback
pOnCreateSceneCallback) throws Exception {

  // TODO 自动生成的方法存根

  Scene scene=new Scene();

  scene.setBackground(background); 

   final Dong as=new
Dong(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(float
arg0) {

   // 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,

   OnPopulateSceneCallback
pOnPopulateSceneCallback)

   throws
Exception {

  // TODO 自动生成的方法存根

  pOnPopulateSceneCallback.onPopulateSceneFinished();

 }

 

 public class Dong extends AnimatedSprite
implements IOnSceneTouchListener{

    private
PhysicsHandler mphy;

    private
float mvel=200;

    private
float mvely=200;

    private
static final int maxvx=500;

    private
static final int maxvy=500;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: