使用ArrayList的内容绘制一个框架
所以我有一个使用 csv 文件填充的数组列表。一旦填充完毕,它就用于将对象绘制到框架中。这是我的 onDrawFrame 方法(我知道它很乱,我稍后会清理)
@Override
public void onDrawFrame(GL10 gl) {
gl.glClear(GL10.GL_COLOR_BUFFER_BIT |
GL10.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glScalef(screenWidth/10, screenHeight/7, 0);
while (currentLoadSpace < totalMapSize){
loadObject = levelDat.get(currentLoadSpace);
Log.d(TAG,"currentLoadSpace " + String.valueOf(currentLoadSpace));
Log.d(TAG,"totalMapSize " + String.valueOf(totalMapSize));
Log.d(TAG,"loadObject " + String.valueOf(loadObject));
Log.d(TAG,"x " + String.valueOf(x));
Log.d(TAG,"y " + String.valueOf(y));
gl.glPushMatrix();
gl.glTranslatef(x, y, 0);
if (String.valueOf(loadObject) == "000"){
Log.d(TAG, "Empty Space");
}
if (String.valueOf(loadObject) == "001"){
square.draw(gl);
Log.d(TAG, "draw a square");
}
gl.glPopMatrix();
currentLoadSpace++;
updateXY();
}
currentLoadSpace = 0;
}
基本上,这段代码的作用是检查我们尝试读取的值的索引是否小于 ArrayList 的总大小。然后它读取该值并根据 if 语句进行检查(如果值为 000,则它不会绘制任何内容,但如果值为 001,则它将在位置 x, y 处绘制一个正方形),它对中的每个值重复此操作数组列表。
我的问题是 if 语句没有触发。它们上面的那些日志标签返回它们应该返回的所有值,并且加载对象总是返回 000 或 001,但我从未从返回的 if 语句中获取日志标签,并且我的屏幕保持空白。
这是此代码的一个循环的日志。
10-22 11:54:37.821: DEBUG/input(14680): currentLoadSpace 0
10-22 11:54:37.821: DEBUG/input(14680): totalMapSize 55
10-22 11:54:37.821: DEBUG/input(14680): loadObject 001
10-22 11:54:37.821: DEBUG/input(14680): x 0.0
10-22 11:54:37.821: DEBUG/input(14680): y 1.0
请注意,没有返回方形绘制的日志,那么为什么我的 if 语句无法识别 loadObject 值?
So I have this array list that is populated using a csv file. Once it is populated it is used to draw objects to frame. Here is my onDrawFrame method (i know its messy i'll clean up later)
@Override
public void onDrawFrame(GL10 gl) {
gl.glClear(GL10.GL_COLOR_BUFFER_BIT |
GL10.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glScalef(screenWidth/10, screenHeight/7, 0);
while (currentLoadSpace < totalMapSize){
loadObject = levelDat.get(currentLoadSpace);
Log.d(TAG,"currentLoadSpace " + String.valueOf(currentLoadSpace));
Log.d(TAG,"totalMapSize " + String.valueOf(totalMapSize));
Log.d(TAG,"loadObject " + String.valueOf(loadObject));
Log.d(TAG,"x " + String.valueOf(x));
Log.d(TAG,"y " + String.valueOf(y));
gl.glPushMatrix();
gl.glTranslatef(x, y, 0);
if (String.valueOf(loadObject) == "000"){
Log.d(TAG, "Empty Space");
}
if (String.valueOf(loadObject) == "001"){
square.draw(gl);
Log.d(TAG, "draw a square");
}
gl.glPopMatrix();
currentLoadSpace++;
updateXY();
}
currentLoadSpace = 0;
}
Basically what this code does is check to see whether the index of the value we are trying to read is less than the total size of the ArrayList. It then reads that value and checks it against the if statements (if the value is 000 then it won't draw anything but if the value is 001 then it will draw a square at location x, y) it repeats this for every value in the array list .
My problem is that the if statements aren't triggering. those log tags above them return all the values they should and load object always returns either a 000 or a 001 but I never get the log tags from within the if statements returned and my screen remains blank.
Here is the log from one loop of this code.
10-22 11:54:37.821: DEBUG/input(14680): currentLoadSpace 0
10-22 11:54:37.821: DEBUG/input(14680): totalMapSize 55
10-22 11:54:37.821: DEBUG/input(14680): loadObject 001
10-22 11:54:37.821: DEBUG/input(14680): x 0.0
10-22 11:54:37.821: DEBUG/input(14680): y 1.0
notice no square drawn log is returned so how come my if statements aren't recognizing the loadObject value?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Jack,字符串永远不应该使用 == 运算符进行比较。
这是你应该如何使用它:
Jack, Strings should NEVER be compared using the == operator.
This is how you should use it: