AndEngine学习笔记(三) RectangleExample
?
?
项目地址:http://code.google.com/p/andengine/
?
?
?
RectangleExample源码:
?
?
?
?
package org.anddev.andengine.examples;import org.anddev.andengine.engine.Engine;import org.anddev.andengine.engine.camera.Camera;import org.anddev.andengine.engine.options.EngineOptions;import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation;import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;import org.anddev.andengine.entity.primitive.Rectangle;import org.anddev.andengine.entity.scene.Scene;import org.anddev.andengine.entity.scene.background.ColorBackground;import org.anddev.andengine.entity.util.FPSLogger;/** * @author Nicolas Gramlich * @since 11:54:51 - 03.04.2010 */public class RectangleExample extends BaseExample {// ===========================================================// Constants// ===========================================================private static final int CAMERA_WIDTH = 720;private static final int CAMERA_HEIGHT = 480;// ===========================================================// Fields// ===========================================================private Camera mCamera;// ===========================================================// Constructors// ===========================================================// ===========================================================// Getter & Setter// ===========================================================// ===========================================================// Methods for/from SuperClass/Interfaces// ===========================================================@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() {}@Overridepublic Scene onLoadScene() {this.mEngine.registerUpdateHandler(new FPSLogger());final Scene scene = new Scene(1);scene.setBackground(new ColorBackground(0, 0, 0));final Rectangle rect1 = new Rectangle(180, 60, 180, 180);rect1.setColor(1, 0, 0);final Rectangle rect2 = new Rectangle(360, 60, 180, 180);rect2.setColor(0, 1, 0);final Rectangle rect3 = new Rectangle(180, 240, 180, 180);rect3.setColor(0, 0, 1);final Rectangle rect4 = new Rectangle(360, 240, 180, 180);rect4.setColor(1, 1, 0);scene.getTopLayer().addEntity(rect1);scene.getTopLayer().addEntity(rect2);scene.getTopLayer().addEntity(rect3);scene.getTopLayer().addEntity(rect4);return scene;}@Overridepublic void onLoadComplete() {}// ===========================================================// Methods// ===========================================================// ===========================================================// Inner and Anonymous Classes// ===========================================================}?
RectangleExample的内容和LineExample几乎相同,画Line和画Rectangle的方法和类似的图形画法在以后的文章里面总结一次,暂时不作过多记录。
?
-?NEAREST: Faster then?BILINEAR?as only the nearest pixel on the Texture is used (Sprites tend to look pixelated when, physical resolution is higher or lower than texture resolution. Up/Down-scaling)
-?BILINEAR: Slower than?NEAREST, but looks better, as not only one pixel from the texture is fetched but the 4 nearest.
The difference between those and the?REPEATING?TextureOptions is the way OpenGL treats TextureCoordinates that are out of the physical bounds of the Texture (usually ranging from 0.0 to 1.0).
Where?REPEATING?paints the Texture twice when the coordinates go from 0.0 to 2.0,?NON-REPEATING?will stretch the outermost pixel of the Texture what looks pretty ugly.
So the?REPEATING?TextureOptions are used only in very special cases.
?
?
?
?
?
?