プロが教えるわが家の防犯対策術!

いるのですが、ゲーム画面は出来ているのですが、ゲームスタート画面、ゲームオーバー画面を作りたいのですがどうすればよろしいのでしょうか、スタート画面はタッチされたらゲーム画面に切り替わるようにしたいです。 ソースは メインアクティビティーは
package android.game;

import android.os.Bundle;

import android.app.Activity;
import android.widget.LinearLayout;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout l = new LinearLayout(this);
setContentView(l);
l.addView(new textview(this, null, 0));
l.addView(new PView(this, null, 0));

}

}

で、ゲーム画面のクラスは
package android.game;

import android.annotation.SuppressLint;
import android.content.Context;
import android.game.R.id;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import java.util.Random;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Paint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import java.util.Random;



public class PView extends View{
Paint paint = new Paint();
int player = 0;
int playerV = 20;
int tamaV = 20;
int x = 100;
int y = 50;
int tamaY = player;
int tamaX = player;
int line = 550;
int tama2X = 0;
int tama2Y = 0;
int linex = 400;
int cnt = 0;
int score = 0;
int timerT = 30;
int flg = 0;
int stx = 200;
int sty = 200;
Random rand = new Random();

Resources res = this.getContext().getResources();
Bitmap bg = BitmapFactory.decodeResource(res, R.drawable.haikei);
Bitmap pl = BitmapFactory.decodeResource(res, R.drawable.player);
Bitmap tama = BitmapFactory.decodeResource(res, R.drawable.tama);
Bitmap tama2 = BitmapFactory.decodeResource(res, R.drawable.tama2);
Bitmap lineview = BitmapFactory.decodeResource(res, R.drawable.line);
Bitmap lineview2 = BitmapFactory.decodeResource(res, R.drawable.line2);






public PView(Context context,AttributeSet attrs,int defStyle) {
super(context,attrs);
// TODO 自動生成されたコンストラクター・スタブ
}
@SuppressLint("DrawAllocation")
@Override
protected void onDraw(Canvas c){

timerT--;

if(timerT < 0)
{
timerT = 0;
}

player += playerV;
if(player<0 || 400<player) playerV *= -1;

//弾の処理
tamaY+= 0;


tama2Y += 20;

if(tamaY > getHeight())
{
tamaY = rand.nextInt(500)+1;

}

tamaX = rand.nextInt(30);



tama2Y += 20;

if(tama2Y > getHeight())
{
tama2Y = rand.nextInt(500)+1;

}

tama2X = rand.nextInt(100);




c.drawBitmap(bg,0,0,paint);
c.drawBitmap(pl,player,y, paint);
c.drawBitmap(tama,player,tamaY,paint);
c.drawBitmap(tama2,tama2X,tama2Y, paint);
c.drawBitmap(lineview,0,line,paint);
c.drawBitmap(lineview2,0,linex, paint);
invalidate();
}


public boolean onTouchEvent(MotionEvent me) {
//タッチされた時
if(me.getAction() == MotionEvent.ACTION_DOWN)
stx = 0;
{



if(me.getAction() == MotionEvent.ACTION_DOWN) {

if(tamaY >= line && tamaY < line + 40)
{
tamaY = 0;
score+= 10;
}

}
if(me.getAction() == MotionEvent.ACTION_DOWN){
if(tama2Y >= linex && tama2Y < linex + 50)
{
tama2Y = 0;
score+= 20;
}
}

return true;
}

}
}
このようになっています。 よろしくお願いします

A 回答 (1件)

Activity を1つ作成して、そこからViewを切り替えるイメージと考えます。


1つViewを作ることはできていると思うので、ゲームスタート画面、ゲームオーバー画面を作成して頂いて、

以下のURLを参考に切り替えていただくことができると思います。
http://blogs.yahoo.co.jp/magoapp/1841049.html

Activityの切り替えはコストがかかる(すなわち重たい)ようです。
http://y-anz-m.blogspot.jp/2011/02/1-activity.html
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!