1

美好的一天...我是android的新程序员...实际上这是我第一次这样做...但是我对Java有基本的了解...

所以来了..我的游戏将有一个可以通过操纵杆控制的图标...和另一个在屏幕上上下移动的图标(不可控制)我希望速度增加一点......我有启动了代码但不知道从哪里以及如何开始碰撞..另一个是可控的图标总是通过屏幕并弹出相反的方向......

    public class GameSurface1 extends SurfaceView implements SurfaceHolder.Callback {

private Context _context;
private GameThread1 _thread;
private GameControl _controls;
private GameJoystick1 _joystick;
private int y = 0; 

private int xSpeed = 1;


private Bitmap _pointer, bmp;


public GameSurface1(Context context) {
    super(context);
    // TODO Auto-generated constructor stub
    _context = context;
    init();
}


private void init(){
    //initialize our screen holder
    SurfaceHolder holder = getHolder();
    holder.addCallback( this);

    //initialize our game engine

    //initialize our Thread class. A call will be made to start it later
    _thread = new GameThread1(holder, _context, new Handler(),this);
    setFocusable(true);


    _joystick = new GameJoystick1(getContext().getResources());
    _pointer = (Bitmap)BitmapFactory.decodeResource(getResources(), R.drawable.icon1);
    bmp = (Bitmap)BitmapFactory.decodeResource(getResources(), R.drawable.bad1);
    //contols
    _controls = new GameControl();
    setOnTouchListener(_controls);
}


public void doDraw(Canvas canvas){
     if (y == getHeight() - bmp.getHeight()) {
         xSpeed = -1;
  }
  if (y == 0) {
         xSpeed = 1;
  }
  y = y + xSpeed;


    //update the pointer
    _controls.update(null);

    //draw the pointer
    canvas.drawBitmap(_pointer, _controls._pointerPosition.x, _controls._pointerPosition.y, null);

    //draw the joystick background
    canvas.drawBitmap(_joystick.get_joystickBg(), 15,215, null);

    //draw the dragable joystick
    canvas.drawBitmap(_joystick.get_joystick(),_controls._touchingPoint.x - 26, _controls._touchingPoint.y - 26, null);
    canvas.drawBitmap(bmp, 280, y, null);
}



//these methods are overridden from the SurfaceView super class. They are automatically called 
//when a SurfaceView is created, resumed or suspended.
@Override 
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {}
private boolean retry;
@Override 
public void surfaceDestroyed(SurfaceHolder arg0) {
    retry = true;
    //code to end gameloop
    _thread.state = GameThread1.STOPED;
    while (retry) {
        try {
            //code to kill Thread
            _thread.join();
            retry = false;
        } catch (InterruptedException e) {
        }
    }

}

@Override 
public void surfaceCreated(SurfaceHolder arg0) {
    if(_thread.state==GameThread1.PAUSED){
        //When game is opened again in the Android OS
        _thread = new GameThread1(getHolder(), _context, new Handler(),this);
        _thread.start();
    }else{
        //creating the game Thread for the first time
        _thread.start();
    }
}

非常感谢您提供的所有帮助...谢谢

4

0 回答 0