나는이 기능을 사용하지 않고 있습니다. 이 네트워크는 단순한 코드 수정 게시물이 아니라는 것을 알았습니다. 하지만 좋은 튜토리얼이 없었기 때문에 이것이 다른 사람들의 관심사라고 생각합니다.Android 캔버스 업데이트 문제
그래서 나는 캔버스를 호출하고있어 나는 ondraw()
방법으로 그것을 그릴 수 있지만이 게임 루프에서 그릴 때 그것은 아무 것도 그립니다 없습니다. 나는 심지어 오류 메시지를받지 못한다.
앱 :
public class App extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
draw d = new draw(this);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(d);
}
public void end()
{
App.this.finish();
}
}
draw.java : 그래서
public class draw extends View {
Canvas ca;
View v;
Paint paint;
int width;
int height;
static final int MAX_GAME_SPEED=33;
static int fps;
boolean running=true;
int pw=0,ph=0;
public draw(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas c){
super.onDraw(c);
paint = new Paint(); //Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL);
//get screen size
WindowManager wm = (WindowManager) this.getContext().getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
width = display.getWidth(); // deprecated
height = display.getHeight(); // deprecated
// make the entire canvas white
paint.setColor(Color.WHITE);
c.drawPaint(paint);
ca = c;
paint.setColor(Color.BLACK);
c.drawRect(Math.round(width/3),Math.round(height/3),Math.round((width/3)*2),Math.round((height/3)*2), paint); //position width, position height,width,height
paint.setStyle(Paint.Style.FILL);
paint.setAntiAlias(true);
paint.setTextSize(30);
paint.setColor(Color.GREEN);
c.drawText(String.valueOf(width)+"x"+String.valueOf(height)+","+Math.round(width/3)+"x"+Math.round(height/3), 30, 200, paint);
paint.setColor(Color.GREEN);
c.drawText(String.valueOf(width)+"x"+String.valueOf(height)+","+Math.round(width/3)+"x"+Math.round(height/3), 30, 200, paint);
Thread myThread = new Thread(new UpdateThread());
myThread.start();
}
public void paint(Canvas c)
{
paint.setColor(Color.GREEN);
c.drawRect(20, 5, 50, 100, paint);
pw++;
ph++;
/*if (pw >= width || ph >= height)
{
pw=0;
ph=0;
}
*/
}
public Handler updateHandler = new Handler(){
/** Gets called on every message that is received */
// @Override
public void handleMessage(Message msg) {
paint(ca);
super.handleMessage(msg);
}
};
public class UpdateThread implements Runnable {
@Override
public void run() {
while(true){
draw.this.updateHandler.sendEmptyMessage(0);
}
}
}
}
대단히 감사합니다. 나를 위해 일한 – user1293780