Y
Y
Yaroslav Vorontsov2016-05-25 13:33:58
Java
Yaroslav Vorontsov, 2016-05-25 13:33:58

How to properly track collisions?

In principle, I can write my own function that will take the coordinates of objects and check if they match, but I'm afraid that I will do it wrong.
Are there any super-compact and ingenious solutions, or just ready-made ones?
You need to track collisions of objects, which are just models that are drawn using Bitmap and canvas.
It would also be cool if you described where it would be more correct to store this function. My mini-game is meteorites falling from the sky and a man running away from them. I think that this function should be stored in each meteorite, and the coordinates of the little man should be passed to each meteorite. Maybe I'm dumb.
I wrote my mini-function like this, but it only fires when x man touches a meteorite.

public void check(Sprite sprite, Bitmap man){
        int sx = sprite.getX();
        int sy = sprite.getY();
        if(x < sx && x + width > sx && y < sy && y + height > sy){
            sprite.isDead = true;
        }

    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Василий, 2016-05-27
@Applez

Поищите на хабре статьи по определению вхождения точки в заданную область.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question