[英]How do I get back to my gl screen in android. I have tried to jump out and use an xml layout in my code
Ok I have looked everywhere on this site and have not found an answer to my question. 好的,我已经浏览过这个网站的所有地方,但没有找到我的问题的答案。 I am trying to make a game and am at the point were I need to get the users information from the screen.
我正在尝试制作一款游戏,而且我需要从屏幕上获取用户信息。 I have my whole game done just need this part to move forward.
我完成了整个游戏,只需要这部分就可以向前推进。 I am going from a screen class to an xml layout and can't seem to get back to my screen class to move to the next part of the game.
我将从屏幕类转到xml布局,似乎无法回到我的屏幕类移动到游戏的下一部分。 It seems easier to use the layout than to build the text boxes my self.
使用布局似乎比构建我自己的文本框更容易。 Here is my code.
这是我的代码。
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import com.wright.knightsattack.framework.Game;
import com.wright.knightsattack.framework.gl.Camera2D;
import com.wright.knightsattack.framework.gl.SpriteBatcher;
import com.wright.knightsattack.framework.impl.GLScreen;
import com.wright.knightsattack.framework.math.Vector2;
public class NewCharacterInfo extends GLScreen
{
EditText Name, Strength, Dexterity, Agility, Intelligence, Charisma;
RadioButton Sex;
int intStrength, intDexterity, intAgility, intIntelligence, intCharisma;
Button Done_BTN;
Camera2D guiCam;
SpriteBatcher batcher;
Vector2 animPoint;
Game gameIn;
Activity activity;
Intent gameIntent;
Boolean enterInfo = true;
public NewCharacterInfo(Game game)
{
super(game);
gameIn = game;
activity = (Activity) game;
}
@Override
public void resume()
{
}
@Override
public void update(float deltaTime)
{
if (enterInfo == true)
{
runInfo();
} else
{
newScreen();
return;
}
}
public void runInfo()
{
activity.runOnUiThread(new Runnable()
{
public void run()
{
activity.setContentView(R.layout.new_character_info);
Name = (EditText) activity.findViewById(R.id.editTextName);
Sex = (RadioButton) activity.findViewById(R.id.radioButton1);
Strength = (EditText) activity.findViewById (R.id.editTextStrength);
Dexterity = (EditText) activity.findViewById(R.id.editTextDexterity);
Agility = (EditText) activity.findViewById(R.id.editTextAgility);
Intelligence = (EditText) activity.findViewById(R.id.editTextIntelligence);
Charisma = (EditText) activity.findViewById(R.id.editTextCharisma);
Done_BTN = (Button) activity.findViewById(R.id.done);
Done_BTN.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
Log.e("Click check", "Inside");
if (v.getId() == R.id.done)
{
Log.e("Click check", "Try to change screen");
intStrength = Integer.parseInt(Strength.getText().toString());
intDexterity = Integer.parseInt(Dexterity.getText().toString());
intAgility = Integer.parseInt(Agility.getText().toString());
intIntelligence = Integer.parseInt(Intelligence.getText().toString());
intCharisma = Integer.parseInt(Charisma.getText().toString());
Settings.addCharacterStats(Name.getText().toString(), Sex.getText().toString(), 0, 0, 0, 0, 200, intStrength, intIntelligence, intDexterity, intAgility, intCharisma, 0, 0, 0, 0, 0, 0);
// gameIntent = activity.getIntent();
enterInfo = false;
update(0);
return;
}
}
});
}
});
}
public void newScreen()
{
Settings.save(gameIn.getFileIO());
gameIn.setScreen(new SplashHelmScreen(gameIn));
Log.e("", "check" + gameIn);
return;
}
@Override
public void present(float deltaTime)
{
}
@Override
public void pause()
{
}
@Override
public void dispose()
{
}
}
The xml screen will pop up, and I can enter information in all text boxs but when hit the done button it gives the error and here is the error I am getting from logcat. 将弹出xml屏幕,我可以在所有文本框中输入信息,但是当点击完成按钮时它会给出错误,这是我从logcat获得的错误。
01-09 11:04:38.038: E/libEGL(1743): call to OpenGL ES API with no current context (logged once per thread)
Thanks for any help I really appreciate it I have been strugling with this for a couple of days. 感谢任何帮助,我真的很感激,我已经花了几天时间。
Nevermind, I fixed it, I just created a new intent and then when the information is entered I call finish() on the activity and it jumps to my current screen. 没关系,我修好了,我刚刚创建了一个新的意图,然后当输入信息时,我在活动上调用finish()并跳转到我当前的屏幕。
If you want to get back in the main screen you have two possibilities: 如果你想回到主屏幕,你有两种可能:
@Override
public void onBackPressed() {
} }
or if you have a button: 或者如果你有一个按钮:
Button btn =(Button)findViewById(R.id.btn); 按钮btn =(按钮)findViewById(R.id.btn); btn.setonClickListener(this);
btn.setonClickListener(本);
@Override public void onClick(View v) { @Override public void onClick(View v){
switch (v.getId()) {
case R.id.btn: kill_activity(); case R.id.btn:kill_activity(); break;
打破;
}} }}
void kill_activity() { void kill_activity(){
finish(); 完();
} }
Cheers, 干杯,
Nevermind, I fixed it, I just created a new intent and then when the information is entered I call finish() on the activity and it jumps to my current screen. 没关系,我修好了,我刚刚创建了一个新的意图,然后当输入信息时,我在活动上调用finish()并跳转到我当前的屏幕。
public void newScreen()
{
game = MainMenuScreen.globalGame;
Settings.save(game.getFileIO());
game.setScreen(new SplashHelmScreen(game));
this.finish();
Log.e("", "check" + game);
return;
}
This jumps right back to my game. 这会直接回到我的游戏中。 Sorry I answered this a long time ago, didn't realize I had to come down here and answer it.
对不起我很久以前回答过这个问题,没想到我必须回到这里来回答。 Thought the update took care of that.
认为更新处理了这一点。 Thanks to all who tried to help!!
感谢所有试图帮助的人!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.