好的,这里是代码。我想要它做什么它翻译屏幕跟随对象l2rArrow。确实如此,但 l2rArrow 仍然在屏幕上飞行。即使我将平移设置为 l2rArrow 的 x,y,当 l2rArrow 应该保持死点时,它最终仍然会跑出屏幕。
当我将 camX 乘以 25 时,它似乎稍微好一点,但只是稍微好一点。箭头仍然飞出屏幕。
public void Render(GL10 gl, float deltaTime) {
//Log.d("Game", "Render");
gl.glViewport(0, 0, Screen.SCREEN_WIDTH, Screen.SCREEN_HEIGHT);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrthof(0, Screen.WIDTH_SCALE, 0, Screen.HEIGHT_SCALE, 1, -1);
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glEnable(GL10.GL_BLEND);
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
gl.glEnable(GL10.GL_TEXTURE_2D);
MeshRect mRect; // this holds all of our rectangles
// draw the sky/backdrop************************************************************
texture.bind(gl, Texture.TEXTURE_SKY1);
mRect = new MeshRect(Sky.getMyRect());
mRect.Draw(GL10.GL_TRIANGLES, gl);
//draw clouds***********************************************************************
clouds.Update();
Vector<Cloud> vClouds = clouds.getClouds();
for (int i = 0; i < vClouds.size(); i++){
vClouds.get(i).Update(deltaTime);
texture.bind(gl, Texture.TEXTURE_CLOUDS1);
mRect = new MeshRect(vClouds.get(i).getMyRect());
mRect.Draw(GL10.GL_TRIANGLES, gl);
if (vClouds.get(i).hasRunCourse()){
clouds.RemoveCloud(vClouds.get(i).getID());
}
}
// draw arrows and applied power ups***********************************************************************
boolean hasTranslated = false;
if (!l2rArrow.isFired) {
gl.glPushMatrix(); //save our state
gl.glTranslatef(l2rArrow.GetToOriginX, l2rArrow.GetToOriginY, 0f); // translate to origin 0,0,0
gl.glRotatef(LBow.getAngle(), 0f, 0f, 1f); //rotate
gl.glTranslatef(-l2rArrow.GetToOriginX, -l2rArrow.GetToOriginY, 0f); // translate to where we want to draw it
texture.bind(gl, Texture.TEXTURE_L2RARROW);
mRect = new MeshRect(l2rArrow.getMyRect());
mRect.Draw(GL10.GL_TRIANGLES, gl);
gl.glPopMatrix(); //return to saved state
} else {
l2rArrow.Update(deltaTime);
texture.bind(gl, Texture.TEXTURE_L2RARROW);
mRect = new MeshRect(l2rArrow.getMyRect());
mRect.Draw(GL10.GL_TRIANGLES, gl);
hasTranslated = true;
gl.glPushMatrix();
float camX = (float) ((l2rArrow.startX - l2rArrow.PosX));
camX = camX * 25;
float camY = (float) ((l2rArrow.startY - l2rArrow.PosY));
if (camY > 0) { camY = 0;}
gl.glTranslatef(camX, camY,0f);
if (l2rArrow.hasCollided) {
//run collision code for detecting a hit and ending turn
}
}
/**=======================================================================================================
* Everything between here should be effected by translate | | gl.gltranslatef(x,y,z) x = Xoffset
*=======================================================================================================*/
/**=======================================================================================================
* gl.glPopMatrix(); back to origin
*=======================================================================================================*/
if (hasTranslated){
gl.glPopMatrix();
}
//finish drawing other non translated
}