我在 Android 上使用 openGL 2D 开发游戏。
由于我的视图很复杂并且同时包含 300-400 个对象(游戏循环),因此获得性能水平非常无能为力。
static
我对java中的和non-static
领域非常了解:
private final static int NUMBER = 10;
和
private final int NUMBER = 10;
我的问题不是封装(作为 OO),而是性能。
什么更好用于性能static
或non-static
领域。
这个想法是,对于我的大多数逻辑,我使用像float/int
.
我为我的所有“视图”创建了通用超类,并且这个类必须在性能范围内更有效:
这是示例:
/** Sprite sheet definition */
private final int SPRITE_WIDTH = 4;
private final int SPRITE_HEIGHT = 4;
private float mScreenWidth, mScreenHeight, wRatio, hRatio;
private int mFrame = 0;
private int mSwitcher = 0;
private final int TEXTURE_COUNT = 1; // for sprite sheet we use 1 image all the time.
private int[] textures = new int[TEXTURE_COUNT]; // frame animation
protected FloatBuffer vertexBuffer;
private final ESpriteDirection mDirection = ESpriteDirection.TOP_TO_DOWN_LEFT_TO_RIGHT;
public float x, y, initPos, finalPos, initSpeed, currentPos;
private ByteBuffer bb1;
private final int TOTAL_IMAGE_COUNT_IN_SPRITE = SPRITE_WIDTH * SPRITE_HEIGHT;
private FloatBuffer[] floatBufferArray = new FloatBuffer[TOTAL_IMAGE_COUNT_IN_SPRITE];
private float xOffset = 1.0f/SPRITE_WIDTH;
private float yOffset = 1.0f/SPRITE_HEIGHT;
private float vertices[] = {
0.0f,3.0f,0.0f,
0.0f,0.0f,0.0f,
3.0f,3.0f,0.0f,
3.0f,0.0f,0.0f
};
private float storage[][] = new float[TOTAL_IMAGE_COUNT_IN_SPRITE][];
private int[] sprite_X_Indexes = new int[SPRITE_WIDTH];//{1,2,3,4};
private int[] sprite_Y_Indexes = new int[SPRITE_WIDTH];//{1,2,3,4};
我可以猜测对于同一个类static
字段的多次启动更好,嗯
谢谢,