4. Performance Tips
● Avoid object creations
● Use pools and pre create them
● Avoid getters and setters
● Public attributes instead
● Avoid collections
● Avoid interfaces
● Use a single Activity
16. Creating the Engine (1/2)
public Engine onLoadEngine() {
DisplayMetrics om = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(om);
camWidth = 480;
camHeight = (int) (om.heightPixels*480f / om.widthPixels);
RatioResolutionPolicy rrp = new
RatioResolutionPolicy(camWidth, camHeight);
Camera camera = new Camera(0, 0, camWidth, camHeight);
17. Creating the Engine (2/2)
EngineOptions options = new EngineOptions(true,
ScreenOrientation.LANDSCAPE, rrp, camera);
options.getRenderOptions()
.disableExtensionVertexBufferObjects();
return new Engine(options);
}
19. Texture Atlas
● Quite a pain for AndEngine
● Built by hand
● Size must be a power of 2
● One big or many small ones?
20. Creating the Scene (1/3)
public Scene onLoadScene() {
Scene scene = new Scene();
PhysicsWorld physicsWorld = new PhysicsWorld(new
Vector2(0, SensorManager.GRAVITY_EARTH), false);
Shape ground = new Rectangle(0, camHeight - 2,
camWidth, 2);
FixtureDef wallFixtureDef =
PhysicsFactory.createFixtureDef(0, 0.5f, 0.5f);
PhysicsFactory.createBoxBody(physicsWorld, ground,
BodyType.StaticBody, wallFixtureDef);
scene.attachChild(ground);
21. Creating the Scene (2/3)
Sprite box = new Sprite(0, 0, mBoxTextureRegion);
FixtureDef boxFixture =
PhysicsFactory.createFixtureDef(1, 0.5f, 0.5f);
Body boxBody =
PhysicsFactory.createBoxBody(physicsWorld, box,
BodyType.DynamicBody, boxFixture);
physicsWorld.registerPhysicsConnector(new
PhysicsConnector(box, boxBody, true, true));
scene.attachChild(box);
22. Creating the Scene (3/3)
scene.registerUpdateHandler(physicsWorld);
scene.registerUpdateHandler(mUpdateHandler);
return scene;
}
23. Types of bodies
● Dynamic
● It is affected by physics like gravity
● Kinematic
● It moves in a specified way
● Static
● It does not move
24. More Interesting things
● TiledTextures / Animated Sprites
● Animations
● Sound Engine
● Particle Systems
● Collision Detect
● Polygonal Bodies
● Menus
48. Why use a Library?
● Not reinventing the wheel
● It is proven that works
● Familiarity for users
● Other games use them
● You do not own the servers
● You don’t, and that is good
50. What do you get?
● Achievements
● Not very impressive
● Leaderboards
● That is interesting
● News Feed
● Friends management
● Improved engagement
51. Easy to integrate
● Android Library Project
● Initialize with the Application
● Open a specific screen
● 2 lines of code
● Submit a score or achievement
● 2 lines of code