我在將圖像繪製到android屏幕時出現問題。現在我正在嘗試爲Android做一個「殭屍射手」的端口,我不知道如何去畫屏幕上的烏龜和所有的殭屍。任何經驗豐富的安卓遊戲程序員都想幫助我?我覺得它比添加一個relativelayout並將一個ImageView添加到該相關佈局...僅僅是爲了顯示一個頭部要容易。我的代碼甚至沒有畫出頭像。我看到的只是在XML文件中定義的背景。繪製到Android屏幕自定義x,y
編輯:我有一個新的方法去看這個,使用Canvas'看LunarLander的源代碼後。我現在做錯了什麼?
主類:
package com.wickeyware.zombiearcher;
import android.app.Activity;
import android.graphics.Canvas;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
public class GameActivity extends Activity
{
private Turtle turtle;
private Canvas canvas = new Canvas();
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
final Window win = getWindow();
requestWindowFeature(Window.FEATURE_NO_TITLE);
win.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.game);
turtle = new Turtle(this);
}
@Override
public void onResume()
{
turtle.Draw(canvas);
}
}
烏龜類:
package com.wickeyware.zombiearcher;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
public class Turtle
{
// Surface Holder?
//private SurfaceHolder sh;
// Background image
//private Bitmap bmp;
// All the parts of the turtle
private Drawable head;
private Drawable body;
private Drawable rleg;
private Drawable lleg;
private Drawable rarm;
private Drawable larm;
private Drawable eye;
private Drawable mouth;
private Drawable bow;
private Drawable tstring;
private Drawable bstring;
// Fill the array
private Drawable[] turtle = {head, body, rleg, lleg, rarm, larm, eye, mouth, bow, tstring, bstring};
// X,Y coords of turtle
//private int tX = 0;
//private int tY = 0;
// Constructor
public Turtle(Context context)
{
//bmp = BitmapFactory.decodeResource(context.getResources(), R.drawable.default_board);
// Load up turtle parts with drawables
turtle[0] = context.getResources().getDrawable(R.drawable.head);
turtle[1] = context.getResources().getDrawable(R.drawable.body);
turtle[2] = context.getResources().getDrawable(R.drawable.leg);
turtle[3] = context.getResources().getDrawable(R.drawable.leg);
turtle[4] = context.getResources().getDrawable(R.drawable.arm);
turtle[5] = context.getResources().getDrawable(R.drawable.forearm);
turtle[6] = context.getResources().getDrawable(R.drawable.eye);
turtle[7] = context.getResources().getDrawable(R.drawable.mouth);
turtle[8] = context.getResources().getDrawable(R.drawable.bow);
turtle[9] = context.getResources().getDrawable(R.drawable.halfbowstring);
turtle[10] = context.getResources().getDrawable(R.drawable.halfbowstring);
}
public void Draw(Canvas canvas)
{
for(Drawable part : turtle)
{
part.setBounds(0,0,0,0);
part.draw(canvas);
}
}
}
發表您的佈局如果可能的話 – 2011-06-17 14:36:39