AndEngine Example(1):LineExample
2014-03-14 18:08
239 查看
目标:
1.使得程序可以正常运行
2.搭建最简单的场景
3.理解Scene,Camera等几个基本的概念
4.理解整个的基本流程
----------------------------------------------------
新建一个Android工程,自动创建Activity,然后为其命名为LineExample。(如果改名了,不要忘记修改Manifest)
将下面的代码复制进去,
然后添加andengine.jar到libs中。
运行。
onCreateEngineOptions()将会创建一个EngineOptions 对象
EngineOptions 引擎的参数,创建它的时候,需要给定:屏幕方向,分辨率比率策略,和相机(这个相机是一个抽象的概念,并不是实际的硬件)
onCreateScene() 创建一个场景
这里,我们创建了一个场景,并且往里面加入了实体(Line is a Entity)
Line extends Shape
Shape extends Entity
VertexBufferObjectManager 是一个管理者,它管理这些实体对象的buffer。
--------------------------------------------------------------------------
扩展阅读:绘制是如何进行的?
EngineRenderer implements GLSurfaceView.Renderer
凡是对于OpenGL有一定了解的应该知道
GLSurfaceView.Renderer中有一个回调函数: public void onDrawFrame(final GL10 pGL)
继承类在此回调中调用了
(1) Engine.onDrawFrame
(2) Engine.onUpdateDrawHandlers(pGLState, this.mCamera)
(3) DrawHandlerList.onDraw(final GLState pGLState, final Camera pCamera)
(4) IDrawHandler.onDraw(final GLState pGLState, final Camera pCamera)
(5) interface IEntity extends IDrawHandler
(6) class Entity implements IEntity
(7) Entity.onDraw(final GLState pGLState, final Camera pCamera)
(8) Entity.onManagedDraw(final GLState pGLState, final Camera pCamera)
1.使得程序可以正常运行
2.搭建最简单的场景
3.理解Scene,Camera等几个基本的概念
4.理解整个的基本流程
----------------------------------------------------
新建一个Android工程,自动创建Activity,然后为其命名为LineExample。(如果改名了,不要忘记修改Manifest)
将下面的代码复制进去,
然后添加andengine.jar到libs中。
运行。
package org.andengine.examples; import java.util.Random; import org.andengine.engine.camera.Camera; import org.andengine.engine.options.EngineOptions; import org.andengine.engine.options.ScreenOrientation; import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy; import org.andengine.entity.primitive.Line; import org.andengine.entity.scene.Scene; import org.andengine.entity.scene.background.Background; import org.andengine.entity.util.FPSLogger; import org.andengine.opengl.vbo.VertexBufferObjectManager; import org.andengine.ui.activity.SimpleBaseGameActivity; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 11:54:51 - 03.04.2010 */ public class LineExample extends SimpleBaseGameActivity { // =========================================================== // Constants // =========================================================== /* Initializing the Random generator produces a comparable result over different versions. */ private static final long RANDOM_SEED = 1234567890; private static final int CAMERA_WIDTH = 720; private static final int CAMERA_HEIGHT = 480; private static final int LINE_COUNT = 100; // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override public EngineOptions onCreateEngineOptions() { final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT); return new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera); } @Override public void onCreateResources() { } @Override public Scene onCreateScene() { this.mEngine.registerUpdateHandler(new FPSLogger()); final Scene scene = new Scene(); scene.setBackground(new Background(0.09804f, 0.6274f, 0.8784f)); final Random random = new Random(RANDOM_SEED); final VertexBufferObjectManager vertexBufferObjectManager = this.getVertexBufferObjectManager(); for(int i = 0; i < LINE_COUNT; i++) { final float x1 = random.nextFloat() * CAMERA_WIDTH; final float x2 = random.nextFloat() * CAMERA_WIDTH; final float y1 = random.nextFloat() * CAMERA_HEIGHT; final float y2 = random.nextFloat() * CAMERA_HEIGHT; final float lineWidth = random.nextFloat() * 5; final Line line = new Line(x1, y1, x2, y2, lineWidth, vertexBufferObjectManager); line.setColor(random.nextFloat(), random.nextFloat(), random.nextFloat()); scene.attachChild(line); } return scene; } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
onCreateEngineOptions()将会创建一个EngineOptions 对象
EngineOptions 引擎的参数,创建它的时候,需要给定:屏幕方向,分辨率比率策略,和相机(这个相机是一个抽象的概念,并不是实际的硬件)
onCreateScene() 创建一个场景
这里,我们创建了一个场景,并且往里面加入了实体(Line is a Entity)
Line extends Shape
Shape extends Entity
VertexBufferObjectManager 是一个管理者,它管理这些实体对象的buffer。
--------------------------------------------------------------------------
扩展阅读:绘制是如何进行的?
EngineRenderer implements GLSurfaceView.Renderer
凡是对于OpenGL有一定了解的应该知道
GLSurfaceView.Renderer中有一个回调函数: public void onDrawFrame(final GL10 pGL)
继承类在此回调中调用了
(1) Engine.onDrawFrame
(2) Engine.onUpdateDrawHandlers(pGLState, this.mCamera)
(3) DrawHandlerList.onDraw(final GLState pGLState, final Camera pCamera)
(4) IDrawHandler.onDraw(final GLState pGLState, final Camera pCamera)
(5) interface IEntity extends IDrawHandler
(6) class Entity implements IEntity
(7) Entity.onDraw(final GLState pGLState, final Camera pCamera)
(8) Entity.onManagedDraw(final GLState pGLState, final Camera pCamera)
相关文章推荐
- AndEngine Example(5):SpriteBatchExample
- AndEngine Example(3):SpriteExample
- AndEngine Example(7):EntityModifierExample
- AndEngine Example(8):PathModifierExample
- AndEngine Example(2):RectangleExample
- AndEngine Example(6):MovingBallExample
- AndEngine Example(9):EaseFunctionExample
- AndEngine Example(4):SpriteRemoveExample
- EtherChannel Between a Cisco Catalyst Switch and Server Configuration Example
- codec engine代码阅读1~3:根目录package.xdc,release notes和example文件夹(转)
- Install qibuild. Compile and run an example.
- Pass4Sure Check Point Software Technologies Interactive Testing Engine and BrainDumps
- Pass4Sure SAS Institute Interactive Testing Engine and BrainDumps
- Spring 3 MVC And JSON Example
- How to use ConcurrentHashMap in Java - Example Tutorial and Working
- RHEL7.2/Centos-node.js 2. npm install and websocket example
- AngularJS CRUD Example with PHP, MySQL and Material Design
- struct and union example
- EXAMPLE of parsing GET and POST
- Example of EPOLL for C and C++