Android OntouchListener,绘制位图时检查图像交集

发布于 2024-10-30 19:10:18 字数 1746 浏览 0 评论 0原文

好吧,大家好......,似乎我在上一个问题中错了......

我正在开发一个单词搜索游戏,并且我已经使用将我的应用程序实现的“视角”从 GridView 更改为位图绘制安卓中的画布。

情况是这样的: 画布内有一个可绘制对象,还有另一个可绘制对象,当用户调用 OntouchListener 事件时,该对象将被绘制...

我想进行逻辑操作,以便第二个绘制对象与第一个可绘制对象具有相同的轴或坐标对象,它会做一些事情...

这是代码:

public class DrawView extends View implements OnTouchListener{
private static final String TAG = "DrawView";

List<Point> points = new ArrayList<Point>();
Paint paint = new Paint();
Bitmap kangoo = BitmapFactory.decodeResource(getResources(),R.drawable.icon);

public DrawView(Context context, AttributeSet attrs) {
    super(context,attrs);
    setFocusable(true);
    setFocusableInTouchMode(true);

    this.setOnTouchListener(this);
    paint.setColor(Color.WHITE);
    paint.setAntiAlias(true);
}

@Override
public void onDraw(Canvas canvas) {
    Bitmap krazy = BitmapFactory.decodeResource(getResources(),R.drawable.schema);
    canvas.drawBitmap(krazy, 130, 130, null);
    for (Point point : points) {
        canvas.drawBitmap(kangoo, point.x, point.y, null);
        //canvas.drawCircle(point.x, point.y, 5, paint);
        // Log.d(TAG, "Painting: "+point);
    }
}

@Override
public boolean onTouch(View view, MotionEvent event) {
     // if(event.getAction() != MotionEvent.ACTION_DOWN)
    // return super.onTouchEvent(event);
    Point point = new Point();
    point.x = event.getX();
    point.y = event.getY();
    points.add(point);
    invalidate();
    Log.d(TAG, "point: " + point);
    return true;
}
    }

    class Point {
    float x, y;

    @Override
     public String toString() {
       return x + ", " + y;
     }
    }

看...,静态绘制对象是 KRAZY,动态绘制对象是 KANGOO,触摸屏幕时将绘制该对象

我想知道这两个对象是否通过 x 接触或者你....

谢谢你

OK guys fine..., seems like I was wrong from the last question...

I'm working on a wordsearch game, and I've changed the "Point of View" of my app implementation from GridView to Bitmap-drawing using canvas in android.

this is the case:
there's a drawable object inside a canvas and also another drawable object that will be draw as the user invoke the OntouchListener event...

I want to make a logic operation so that if the second draw object have the same axis or ordinat as the first drawable object, it will do something...

here's the code:

public class DrawView extends View implements OnTouchListener{
private static final String TAG = "DrawView";

List<Point> points = new ArrayList<Point>();
Paint paint = new Paint();
Bitmap kangoo = BitmapFactory.decodeResource(getResources(),R.drawable.icon);

public DrawView(Context context, AttributeSet attrs) {
    super(context,attrs);
    setFocusable(true);
    setFocusableInTouchMode(true);

    this.setOnTouchListener(this);
    paint.setColor(Color.WHITE);
    paint.setAntiAlias(true);
}

@Override
public void onDraw(Canvas canvas) {
    Bitmap krazy = BitmapFactory.decodeResource(getResources(),R.drawable.schema);
    canvas.drawBitmap(krazy, 130, 130, null);
    for (Point point : points) {
        canvas.drawBitmap(kangoo, point.x, point.y, null);
        //canvas.drawCircle(point.x, point.y, 5, paint);
        // Log.d(TAG, "Painting: "+point);
    }
}

@Override
public boolean onTouch(View view, MotionEvent event) {
     // if(event.getAction() != MotionEvent.ACTION_DOWN)
    // return super.onTouchEvent(event);
    Point point = new Point();
    point.x = event.getX();
    point.y = event.getY();
    points.add(point);
    invalidate();
    Log.d(TAG, "point: " + point);
    return true;
}
    }

    class Point {
    float x, y;

    @Override
     public String toString() {
       return x + ", " + y;
     }
    }

see..., the static draw object is KRAZY and dynamic which will be draw while touch the screen is KANGOO

I want to know if those two object are in contact either by x or y....

Thank U

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风吹雨成花 2024-11-06 19:10:18

实际上这个解决方案是用来协助我的单词搜索游戏项目...

我只需要做的主要事情就是测量由可绘制字符串块表示的占用单词...
然后将其与正方形选择框生成的正方形区域进行比较,只要用户触摸屏幕,正方形选择框就会在字符块内绘制自己......

然后在正方形区域或正方形占用的区域时调用选择被整个字符块占据......
我的意思是方形选择框位于字符块内部,

在这种情况下,如果一个单词从 point.x=0.0 , y=0.0 开始形成 4 个字符块,并且每个块占据 32pix H 和 W ,那么方形选择框占据的位置必须小于 4*32(W) 和 1*32(H)...

Actually this solution is used to assist my word-search game project...

The main thing that I just need to do is to measure the occupied words which represented by drawables blocks of string...
and then to compare it with the square area that will be make by the square selection box which will draw itself inside the characters blocks as long as the user touch the screen...

and then invoke when the square area or the occupied area of square selection is OCCUPIED by the entire characters block....
i mean the square selection box is inside the characters blocks

in this case if a word make 4 blocks of characters start from point.x=0.0 , y=0.0 , and each block occupied 32pix H and W then the square selection box occupied position must be less than 4*32(W) and 1*32(H)....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文