- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用此处描述的无尽道路算法后,我还实现了墙壁的滚动。我有位于屏幕中央的人的行走动画。
我做了什么:根据无尽路算法实现后台滚动
有什么问题吗?男人的影像也如无尽的道路一样滚动。
我想要的:人的动画不应该滚动,但背景应该滚动。
我尝试使用以下方法在 openglES 中处理矩阵...“gl.glMatrixMode(GL10.GL_TEXTURE)”,但结果是背景滚动停止,但动画成功。
我知道我在某个地方错了,但我找不到我的错误。
这是我的代码:
public class GLSquare {
FloatBuffer fVertexBuffer, mTextureBuffer;
ByteBuffer mColorBuff;
ByteBuffer mIndexBuff;
int[] textures = new int[1];
public boolean useMipMapping = true;
float _numTextures = 2;
float incrementTex;
private float _acceleration;
long startTime;
float vertices [] = {
-2.0f,2.0f,0.0f, //byte index 0
2.0f, 2.0f,0.0f, //byte index 1
-2.0f, -2.0f,0.0f, //byte index 2
2.0f,-2.0f,0.0f, //byte index 3
};
float textureCoord[] = {
0.0f,incrementTex,
1.0f,incrementTex,
0.0f,_numTextures+incrementTex,
1.0f,_numTextures+incrementTex
};
byte indices[] = {0, 1, 2,
1, 2, 3 };
public GLSquare() {
// TODO Auto-generated constructor stub
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(vertices.length * 4); // 4 vertices, 3 co-ordinates(x,y and z) 4 for converting in float
byteBuffer.order(ByteOrder.nativeOrder());
fVertexBuffer = byteBuffer.asFloatBuffer();
fVertexBuffer.put(vertices);
fVertexBuffer.position(0);
ByteBuffer byteBuffer2 = ByteBuffer.allocateDirect(textureCoord.length * 4);
byteBuffer2.order(ByteOrder.nativeOrder());
mTextureBuffer = byteBuffer2.asFloatBuffer();
Log.i("texture", "tex corrrrd " + String.valueOf(textureCoord));
mTextureBuffer.put(textureCoord);
mTextureBuffer.position(0);
startTime = System.currentTimeMillis();
}
public void draw(GL10 gl){
gl.glFrontFace(GL11.GL_CW);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glVertexPointer(3,GL10.GL_FLOAT, 0, fVertexBuffer);
gl.glEnable(GL10.GL_TEXTURE_2D);
/** for the repetition of road.*/
_acceleration += -0.005f * (float)System.currentTimeMillis()-startTime;
_acceleration = Math.max(_acceleration, 0.002f);
gl.glMatrixMode(GL10.GL_TEXTURE);
gl.glTranslatef(0, _acceleration, 0);
gl.glMatrixMode(GL10.GL_MODELVIEW);
incrementTex -= _acceleration;
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]); //4
gl.glTexCoordPointer(2, GL10.GL_FLOAT,0, mTextureBuffer); //5
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4); //7
gl.glFrontFace(GL11.GL_CCW);
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
}
public void createSquareTexture(GL10 gl, Context context, int resource)
{
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resource);
gl.glGenTextures(1, textures, 0);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_REPEAT, GL10.GL_CLAMP_TO_EDGE);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
bitmap.recycle();
}
}
这里是渲染类中使用的方法...
TextureRegion keyFrame;
public void present(float deltaTime) {
GL10 gl = glGraphics.getGL();
gl.glClearColor(0f, 0.2f, 0.2f, 1.0f);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
loadTheWalls(gl);
guiCamera.setViewportAndMatrices();
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glEnable(GL10.GL_BLEND);
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
batcher.beginBatch(texture);
keyFrame = straightWalk.getKeyFrame(stickMan.straightWalkTime, Animation.ANIMATION_LOOPING);
drawTheManMethod();
batcher.endBatch();
}
public void loadTheWalls(GL10 gl){
/**
*
* Code for the back scrolling of roads and walls
* Three squares are taken and the textures are repeated on the respective square.
* Only two textures are taken here, One for the wall and other for the road.
* Wall textures are rotated accordingly ap per usage.
*
* */
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
GLU.gluPerspective(gl, 67, glGraphics.getWidth()
/ (float) glGraphics.getHeight(), 1f, 100f);
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glEnable(GL10.GL_DEPTH_TEST);
/**Square used as a road*/
gl.glPushMatrix();
gl.glLoadIdentity();
gl.glTranslatef(0.0f, -1.0f, -4.0f); // Translate to wallpos and into the screen ( NEW )
gl.glRotatef(-80, 1, 0, 0);
mSquare2.draw(gl); // Draw Square ( NEW )
gl.glPopMatrix();
/**Square used as a left wall*/
gl.glPushMatrix();
gl.glLoadIdentity();
gl.glTranslatef(-2.0f, 0.0f, -4.0f); // Translate to wallpos and into the screen ( NEW )
gl.glRotatef(-90, 0, 1, 0);
gl.glRotatef(90, 0, 0, 1);
mSquare3.draw(gl); // Draw Square ( NEW )
gl.glPopMatrix();
/**Square used as a right wall*/
gl.glPushMatrix();
gl.glLoadIdentity();
gl.glTranslatef(1.8f, 0.0f, -4.0f); // Translate to wallpos and into the screen ( NEW )
gl.glRotatef(-85, 0, 1, 0);
gl.glRotatef(90, 0, 0, 1);
mSquare1.draw(gl); // Draw Square ( NEW )
gl.glPopMatrix();
}
public void pause() {
}
public void resume() {
GL10 gl = glGraphics.getGL();
texture = new Texture(((GLGame)game), "twocharacter.png");
straightWalk = new Animation(0.2f,
new TextureRegion(texture, 0, 96, 96, 96),
new TextureRegion(texture, 96, 96, 96, 96),
new TextureRegion(texture, 96*2, 96, 96, 96),
new TextureRegion(texture, 96*3, 96, 96, 96),
new TextureRegion(texture, 96*4, 96, 96, 96),
new TextureRegion(texture, 96*5, 96, 96, 96),
new TextureRegion(texture, 96*6, 96, 96, 96),
new TextureRegion(texture, 96*7, 96, 96, 96)
);
int resId2 = R.drawable.buildngs;
mSquare1.createSquareTexture(gl, getBaseContext(), resId2);
int resId3 = R.drawable.buildngs;
mSquare3.createSquareTexture(gl, getBaseContext(), resId3);
int resId4 = R.drawable.path;
mSquare2.createSquareTexture(gl, getApplication(), resId4);
}
以下是为了更好地理解的图像。
最佳答案
在 GLSquare 中创建一个名为“texturePos”的字段。
private float texturePos = 0.0f;
将加速部分替换为:
/** for the repetition of road.*/
_acceleration += -0.005f * (float)System.currentTimeMillis()-startTime;
_acceleration = Math.max(_acceleration, 0.002f);
texturePos += acceleration;
gl.glMatrixMode(GL10.GL_TEXTURE);
gl.glPushMatrix();
gl.glTranslatef(0, texturePos, 0);
gl.glMatrixMode(GL10.GL_MODELVIEW);
incrementTex -= _acceleration;
请注意,在通过texturePos而不是_acceleration进行转换之前,我们将当前矩阵压入堆栈,并且texturePos也按_acceleration递增。
然后在绘制方法的末尾添加以下内容:
gl.glMatrixMode(GL10.GL_TEXTURE);
gl.glPopMatrix();
gl.glMatrixMode(GL10.GL_MODELVIEW);
因此,我们将旧的纹理矩阵从堆栈中弹出,使其恢复正常。
<小时/>或者您也可以直接调用
gl.glMatrixMode(GL10.GL_TEXTURE);
gl.glLoadIdentity();
在画你的人之前,但第一种方法更好,因为它适用于更多情况。
关于java - 防止 Spite 动画随着 openGL ES 中的背景滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14229357/
使用此处描述的无尽道路算法后,我还实现了墙壁的滚动。我有位于屏幕中央的人的行走动画。 我做了什么:根据无尽路算法实现后台滚动 有什么问题吗?男人的影像也如无尽的道路一样滚动。 我想要的:人的动画不应该
这是我用来防止这一糟糕事故发生在我心爱的角色身上的机制:。我的大部分游戏甚至变量的灵感都来自于火焰的Ember角色,唯一的区别是Ember游戏不使用CameraComponent.Follow(玩家)
这是我用来防止这一糟糕事故发生在我心爱的角色身上的机制:。我的大部分游戏甚至变量的灵感都来自于火焰的Ember角色,唯一的区别是Ember游戏不使用CameraComponent.Follow(玩家)
我从 PHP artisan 命令创建了迁移,它在我的 Postgres 数据库中创建了一个表,id 设置为 auto_increment。 我在 laravel 中制作了一些播种器,并通过 php
我建立和维护的网站有可见的 div,具体取决于它们是否为 :target。由于 w3schools 告诉我 ( http://www.w3schools.com/cssref/sel_target.a
我的 html Submit *You have already submitted review fo
我想测试以下类(class): public class TestClass { private OuterClass client; public TestClass(int v1,
以下 java 8 流没有任何终端操作。下面这个块是不是应该是懒惰的,因为我只有中间操作,还没有被终端操作操作过。当我运行这个块时,我得到“流已经被操作或关闭”。见 https://ideone.co
我是一名优秀的程序员,十分优秀!