开始学习andEngine(3)
来源:互联网 发布:excel数据转换到word中 编辑:程序博客网 时间:2024/04/25 05:06
public class SpriteExample extends BaseExample {private static final int CAMERA_WIDTH = 480;//照着前一篇文章的例子写就行了,框架都打好了private static final int CAMERA_HEIGHT = 320;private Camera mCamera;private BitmapTextureAtlas mBitmapTextureAtlas;private TextureRegion mFaceTextureRegion;@Overridepublic Engine onLoadEngine() {this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), this.mCamera));}@Overridepublic void onLoadResources() {this.mBitmapTextureAtlas = new BitmapTextureAtlas(32, 32, TextureOptions.BILINEAR_PREMULTIPLYALPHA); //gfx是asset目录下的一个文件夹,里面有“face_box.png”这个图片BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");this.mFaceTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "face_box.png", 0, 0);this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);}@Overridepublic Scene onLoadScene() {this.mEngine.registerUpdateHandler(new FPSLogger());final Scene scene = new Scene();scene.setBackground(new ColorBackground(0.09804f, 0.6274f, 0.8784f));/* Calculate the coordinates for the face, so its centered on the camera. */final int centerX = (CAMERA_WIDTH - this.mFaceTextureRegion.getWidth()) / 2;final int centerY = (CAMERA_HEIGHT - this.mFaceTextureRegion.getHeight()) / 2;/* Create the face and add it to the scene. */final Sprite face = new Sprite(centerX, centerY, this.mFaceTextureRegion);scene.attachChild(face);return scene;}@Overridepublic void onLoadComplete() {}}
我学习的过程是,先试几个例子,学会用了,再问为什么。自己动手试一下SpriteExample.java 这个自带的例子,Sprite类的简单应用,在屏幕上显示一个精灵,可以增强自己的自信心。
ps: BitmapTextureAtlas的参数不能小于图片的大小,且必须为2的整数幂。TextureRegion定义了Texture上的一个矩形区域。Sprites使用TextureRegion使系统知道Sprite显示的是整个Texture的那部分。A TextureRegion defines a rectangle on the Texture. A TextureRegion is used by Sprites to let the system know what part of the big Texture the Sprite is showing
- 开始学习andEngine(3)
- 开始学习andEngine(1)
- 开始学习andEngine(2)
- AndEngine 学习系列1-开始
- 开始学习andEngine(4)--触摸移动精灵
- andengine学习
- AndEngine学习笔记
- AndEngine-----CardinalSplineMoveModifierExample学习
- AndEngine----PathModifierExample学习
- AndEngine----ButtonSprite学习
- AndEngine学习笔记(一)
- AndEngine学习笔记(二)
- 关于学习 AndEngine
- Andengine-学习系列4
- AndEngine学习【一】
- 开通博客, 学习andengine
- AndEngine学习笔记--1
- AndEngine 学习sample搭建
- 收藏专家的博客
- hibernate annotation 定义字段的默认值和显示hql的格式化问题
- Linux驱动程序开发快速参考
- 构建不依赖于cookie的手机端用户登录机制
- VC++编程技巧83例
- 开始学习andEngine(3)
- Linux-mmap函数介绍
- RMAN 备份报错 RMAN-06207 RMAN-06208 解决方法
- c++空类实例大小不是0原因收藏
- ORACLE 数据库导入与导出
- [C++]指针知识点小结
- DB2如何删除用户的所有表
- 周末季
- windows xp 下 批量重命名文件