#3
by help » 6年前
大変失礼いたしました。
Task classで
code
public abstract class Task {
protected Context _context;
public Task(Context c){
_context = c;
}
public boolean onUpdate(){
return true;
}
public void onDraw(Canvas c){
}
}
/code
として
Playerクラスを
code
public class Player extends Task {
private final static float MAX_SPEED = 20;
private final static float SIZE = 20;
private Circle _cir = null;
private Paint _paint = new Paint();
private Vec _vec = new Vec();
private Vec _sensorVec = new Vec();
protected Context _context;
public Player(Context _context){
_context = context;
Resources res = context.getResources();
Bitmap bitmap = BitmapFactory.decodeResource(res, R.drawable.ziro);
_cir = new Circle( 380, 700, SIZE );
_paint.setColor(Color.BLUE);
_paint.setAntiAlias(true);
}
public final Circle getPt(){
return _cir;
}
// ベクトルをセットする
private void setVec(){
float x = -AcSensor.Inst().getX()*2;
float y = AcSensor.Inst().getY()*2;
_sensorVec._x = x < 0 ? -x*x : x*x;
_sensorVec._y = y < 0 ? -y*y : y*y;
_sensorVec.setLengthCap(MAX_SPEED);
_vec.blend( _sensorVec, 0.05f );
}
private void Move(){
_cir._x += _vec._x;
_cir._y += _vec._y;
}
@Override
public boolean onUpdate(){
setVec();
Move();
return true;
}
@Override
public void onDraw( Canvas c ){
c.drawBitmap(res,_cir._x, _cir._y, _paint);
}
}
/code
とするとcontextにcannot resolve symbolというエラーが出てしまいます。長文すみませんでした。
大変失礼いたしました。
Task classで
code
public abstract class Task {
protected Context _context;
public Task(Context c){
_context = c;
}
public boolean onUpdate(){
return true;
}
public void onDraw(Canvas c){
}
}
/code
として
Playerクラスを
code
public class Player extends Task {
private final static float MAX_SPEED = 20;
private final static float SIZE = 20;
private Circle _cir = null;
private Paint _paint = new Paint();
private Vec _vec = new Vec();
private Vec _sensorVec = new Vec();
protected Context _context;
public Player(Context _context){
_context = context;
Resources res = context.getResources();
Bitmap bitmap = BitmapFactory.decodeResource(res, R.drawable.ziro);
_cir = new Circle( 380, 700, SIZE );
_paint.setColor(Color.BLUE);
_paint.setAntiAlias(true);
}
public final Circle getPt(){
return _cir;
}
// ベクトルをセットする
private void setVec(){
float x = -AcSensor.Inst().getX()*2;
float y = AcSensor.Inst().getY()*2;
_sensorVec._x = x < 0 ? -x*x : x*x;
_sensorVec._y = y < 0 ? -y*y : y*y;
_sensorVec.setLengthCap(MAX_SPEED);
_vec.blend( _sensorVec, 0.05f );
}
private void Move(){
_cir._x += _vec._x;
_cir._y += _vec._y;
}
@Override
public boolean onUpdate(){
setVec();
Move();
return true;
}
@Override
public void onDraw( Canvas c ){
c.drawBitmap(res,_cir._x, _cir._y, _paint);
}
}
/code
とするとcontextにcannot resolve symbolというエラーが出てしまいます。長文すみませんでした。