Triangle UIView - Swift

前端 未结 5 1573
长情又很酷
长情又很酷 2020-12-05 06:43

So I\'m making a game in which I am dropping objects which have to be destroyed by a spike(triangle) at the bottom of the screen by a user.

I cannot work out how to

5条回答
  •  借酒劲吻你
    2020-12-05 07:11

    I have tried a PNG triangle but it detects the collision as the border of the image not the start of the triangle.

    There is nothing you can do about that if you're going to use simple-minded collisions (e.g. the built-in UIKit Dynamics - it does only rectangular view collisions). If you want advanced shape collisions, either you must implement them yourself or you must use Sprites.

    and for the user to move it

    That is much easier to deal with: simply override hitTest for this view and return nil if the place the user touches is outside the borders of the triangle image.

提交回复
热议问题