为了账号安全,请及时绑定邮箱和手机立即绑定

如何根据点数组列表画圆?

如何根据点数组列表画圆?

翻阅古今 2022-11-10 15:12:46
我正在创建一个测试游戏,其中一个圆圈在被触摸时将移动到点数组列表中的选定位置。但是,单击时似乎无法移动到点的下一个位置。你能帮我找出问题出在哪里以及我可以使用什么解决方案吗?public class EyeTestActivity extends AppCompatActivity  {private GestureDetectorCompat mDetector;@Overrideprotected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,            WindowManager.LayoutParams.FLAG_FULLSCREEN);    this.requestWindowFeature(Window.FEATURE_NO_TITLE);    setContentView(new TestView(this));    // get the gesture detector    mDetector = new GestureDetectorCompat(EyeTestActivity.this, new SwipeGestureDetector());}public boolean onTouchEvent(MotionEvent motionEvent) {    this.mDetector.onTouchEvent(motionEvent);    return super.onTouchEvent(motionEvent);}@Overridepublic boolean dispatchTouchEvent(MotionEvent ev) {    super.dispatchTouchEvent(ev);    return mDetector.onTouchEvent(ev);}public class TestView extends View {    public ArrayList<Point> pointlist;    Paint paint;    public TestView(Context context) {        super(context);        init();        setFocusable(true);        setFocusableInTouchMode(true);        createPointList();    }    public void init() {        paint = new Paint();        paint.setColor(Color.WHITE);        paint.setStrokeWidth(5);        paint.setStyle(Paint.Style.STROKE);    }我希望在打印时绘制下一个圆圈。
查看完整描述

1 回答

?
汪汪一只猫

TA贡献1898条经验 获得超8个赞

首先,您应该参考您的TestView布局。


public class EyeTestActivity extends AppCompatActivity  {


    private GestureDetectorCompat mDetector;

    private TestView tv;


    @Override

    protected void onCreate(Bundle savedInstanceState) {

     super.onCreate(savedInstanceState);


     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,

        WindowManager.LayoutParams.FLAG_FULLSCREEN);

     this.requestWindowFeature(Window.FEATURE_NO_TITLE);

     tv = new TestView(this);

     setContentView(tv);

     // get the gesture detector

     mDetector = new GestureDetectorCompat(EyeTestActivity.this, new SwipeGestureDetector());


}

然后,在您的onScroll事件中,您应该测试e2而不是e1


@Override

public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {

    if (e2.getAction() == MotionEvent.ACTION_MOVE) {

        z++;

       if (z >= 120) {   // zero based arraylist, so, >= 120

           z = 0;

       }

       tv.invalidate; // this to redraw the point

    }

    return true;

}

我认为你createPointList没有做你想做的事。您正在创造 120 次相同的点!总计 120 * 5 * 24 = 14.400 点!


它应该是


for (int i = 1; i <= 5; i++) {

    float a = 100 * i;

    float b = 100 * i;

    for (int j = 1; j <= 24; j++) {

        float x = (float) (a * Math.sin(Math.toRadians(15 * j)));

        float y = (float) (b * Math.cos(Math.toRadians(15 * j)));

        pointlist.add(new Point((int)x, (int)y));

    }

}


查看完整回答
反对 回复 2022-11-10
  • 1 回答
  • 0 关注
  • 58 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信