飞机
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;
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;
相关文章推荐
- 监听屏幕点击次数并显示
- andengine背景设置另一种方法
- Struts2学习(四)OGNL标签介绍
- andengine背景
- Java跳出循环-break和continue语句
- Xcode中Build Configuration配置使用
- 深入理解RxJava的Side Effect Methods
- C++中输出指定位数的小数
- 架构图
- ios数据存储——数据库:SQlite3以及第三方库FMDB
- SqlServer与MySql的一些常用用法的差别
- android 命令隐藏导航栏以及显示电量
- 如何在windows上清除putty的密钥缓存
- 前端代码规范
- TCP协议详解(含长连接短连接的详解)
- 在android AndroidManifest.xml文件中怎样设置访问网络的权限
- MRC和ARC时期的@property参数
- Spring 使用注解方式进行事务管理
- 夜间与日间模式的切换
- C++中引用(&)的用法和应用实例