私はゲームを作っており、キーボードが特定の領域に触れたときにキーボードがポップアップするようにしようとしています。Screenというクラスを既に拡張していますが、テキストの編集について知っているアクティビティを拡張できませんが、機能しません。これを回避する別の方法はありますか?または、ここでテキストの編集を機能させることができない場合は、Iveが試していて、運が悪かったためです。`package com.rmjr42.math4kidz;
import java.util.List;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Looper;
import android.widget.EditText;
import com.rmjr42.framework.Game;
import com.rmjr42.framework.Graphics;
import com.rmjr42.framework.Image;
import com.rmjr42.framework.Screen;
import com.rmjr42.framework.Graphics.ImageFormat;
import com.rmjr42.framework.Input.TouchEvent;
public class GameScreenCount extends Screen {
//Math4Kidz keyboard=new Math4Kidz();
// EditText text;
//Surface s=new Surface();
enum GameState {
Ready, Running, Paused, GameOver
}
GameState state = GameState.Ready;
// Variable Setup
Paint paint, paint2;
public GameScreenCount(Game game) {
super(game);
// Looper.prepare();
// Initialize game objects here
Graphics g = game.getGraphics();
NewImage pic=new NewImage();
Assets.background = g.newImage(pic.randombackground(), ImageFormat.RGB565);
//get one random
Assets.pic1=g.newImage(pic.singleImage(),ImageFormat.RGB565);
// Defining a paint object
paint = new Paint();
paint.setTextSize(70);
paint.setTextAlign(Paint.Align.CENTER);
paint.setAntiAlias(true);
paint.setColor(Color.WHITE);
paint2 = new Paint();
paint2.setTextSize(100);
paint2.setTextAlign(Paint.Align.CENTER);
paint2.setAntiAlias(true);
paint2.setColor(Color.WHITE);
}
@Override
public void update(float deltaTime) {
List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
if (state == GameState.Ready)
updateReady(touchEvents);
if (state == GameState.Running)
updateRunning(touchEvents, deltaTime);
if (state == GameState.Paused)
updatePaused(touchEvents);
if (state == GameState.GameOver)
updateGameOver(touchEvents);
}
private void updateReady(List<TouchEvent> touchEvents) {
state = GameState.Running;
}
private void updateRunning(List<TouchEvent> touchEvents, float deltaTime) {
// 1. All touch input is handled here:
int len = touchEvents.size();
Graphics g = game.getGraphics();
for (int i = 0; i < len; i++) {
TouchEvent event = touchEvents.get(i);
if (event.type == TouchEvent.TOUCH_UP) {
if (inBounds(event, 300, 100, 200, 200)) {
//Looper.prepare();//EDIT TEXT SHOULD GO HERE
//game.setScreen(new GameScreenCount(game));
}
}
}
}
private boolean inBounds(TouchEvent event, int x, int y, int width,
int height) {
if (event.x > x && event.x < x + width - 1 && event.y > y
&& event.y < y + height - 1)
return true;
else
return false;
}
private void updatePaused(List<TouchEvent> touchEvents) {
int len = touchEvents.size();
for (int i = 0; i < len; i++) {
TouchEvent event = touchEvents.get(i);
if (event.type == TouchEvent.TOUCH_UP) {
if (inBounds(event, 0, 0, 800, 240)){
if (!inBounds(event, 0, 0, 35, 35)){
resume();}
}
if (inBounds(event, 0, 240, 800, 240)){
nullify();
goToMenu();
}
}
}
}
private void updateGameOver(List<TouchEvent> touchEvents) {
int len = touchEvents.size();
for (int i = 0; i < len; i++) {
TouchEvent event = touchEvents.get(i);
if (event.type == TouchEvent.TOUCH_DOWN) {
if (inBounds(event, 0, 0, 800, 480)) {
nullify();
game.setScreen(new MainMenuScreen(game));
return;
}
}
}
}
@Override
public void paint(float deltaTime) {
Graphics g = game.getGraphics();
g.drawImage(Assets.background, 0, 0);
g.drawImage(Assets.pic1, 300, 100);
g.drawString("How many are there ? ", 400, 400, paint);
// Secondly, draw the UI above the game elements.
if (state == GameState.Paused)
drawPausedUI();
if (state == GameState.GameOver)
drawGameOverUI();
}
private void nullify() {
paint = null;
// Call garbage collector to clean up memory.
System.gc();
}
private void drawPausedUI() {
Graphics g = game.getGraphics();
// Darken the entire screen so you can display the Paused screen.
g.drawARGB(155, 0, 0, 0);
g.drawString("Resume", 400, 165, paint2);
g.drawString("Menu", 400, 360, paint2);
}
private void drawGameOverUI() {
Graphics g = game.getGraphics();
g.drawRect(0, 0, 1281, 801, Color.BLACK);
g.drawString("GAME OVER.", 400, 240, paint2);
g.drawString("Tap to return.", 400, 290, paint);
}
@Override
public void pause() {
if (state == GameState.Running)
state = GameState.Paused;
}
@Override
public void resume() {
if (state == GameState.Paused)
state = GameState.Running;
}
@Override
public void dispose() {
}
@Override
public void backButton() {
pause();
}
private void goToMenu() {
// TODO Auto-generated method stub
game.setScreen(new MainMenuScreen(game));
}
}