我想用3个班级把球画到我的屏幕上.我已经阅读了一些关于此的内容,我找到了一个代码片段,可以在一个页面上使用3个类,在Android中使用图形
我修改了代码,以便我有一个正在移动的球,并在撞击墙壁时移动方向,如下图所示(这是使用链接中的代码).

现在我喜欢将这些类分成3个不同的页面,因为它们不会让所有东西变得如此拥挤,所有内容都以相同的方式设置.
这是我有的3个班级.
package com.brick.breaker;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
public class BallActivity extends Activity {
private Ball ball;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
ball = new Ball(this);
setContentView(ball);
}
@Override
protected void onPause() {
super.onPause();
setContentView(null);
ball = null;
finish();
}
}
Run Code Online (Sandbox Code Playgroud)
package com.brick.breaker;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class Ball extends SurfaceView implements SurfaceHolder.Callback {
private …Run Code Online (Sandbox Code Playgroud) 我对6点的轮换感到不满.这些点围绕中间的中心点旋转.但是会发生的是形状区域缩小,变得越来越小.
形状的绘图在带有PaintComponent的i JPanel上进行.这意味着画布只支持整数定位,尽管我可以在双打中存储位置.
我使用Point2D.Double存储点位置I在每个函数调用时将所有点旋转1个deegre
我认为我对旋转的理解是缺乏的,我可以在一次调用中旋转360 deegre,或180,这样可以正常工作.但45 deegres或90将完全把我的点变成一条线(下图).
这个问题一直困扰着我一段时间,但一如既往,我确信有一个简单的解决方案.
这是旋转功能
@Override
public synchronized void rotatePoints(int move_x, int move_y) {
// TODO Auto-generated method stub
super.rotatePoints(move_x, move_y);
BottomPanel.appendText("Area of Polygon is: " + UtilClass.calculateAreaOfPolygon(points)+ "\n");
double degrees=1.0;
double radians = degrees * (double)(Math.PI / 180.0);
//GET THE CENTER POINT C
Point2D.Double center = UtilClass.getCenterOfPolygon(points);
//ITERATE THROUGH THE POINTS
Iterator<PointClass> itr = points.iterator();
while(itr.hasNext()) {
//GET THE POINT
PointClass point_class = itr.next();
//point_class = points.get(3);
//FIRST TRANSLATE THE DIFFERENCE
double x1 = point_class.point.x …Run Code Online (Sandbox Code Playgroud)