Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / How to create a sprite with no bounding area within a bounding area?

Author
Message
NeedHalp
3
Years of Service
User Offline
Joined: 20th May 2016
Location:
Posted: 26th May 2016 21:30
For example, I'm trying to create a sprite with a square shaped bounding area. However, inside that square, I want to "remove" a smaller square region of bounding area so that if a different and separate sprite is inside that small region of square, hit detection will return 0 but outside that small region, hit detection will return 1. Any ideas? Alternatively, if there is a way to code if all parts of the sprite (like 100% of the pixels of the sprite, not just a corner or parts of the sprite) has been hit, that would also be equally great. Thank you!
BatVink
Moderator
16
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 27th May 2016 09:06
You can't do it with one bounding box. Collison shapes must be convex. Essentially you are making a concave area by removing a section.
You can use multiple collision shapes on one sprite, using AddSpriteShapeBox (and other similar commands). in this way you can put 4 boxes around the hole in the centre.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
NeedHalp
3
Years of Service
User Offline
Joined: 20th May 2016
Location:
Posted: 27th May 2016 18:45
I know the definition of convex and concave but I'm not sure what you mean by convex and concave in terms of sprite and bounding area.
Also, I have thought of putting multiple bounding areas but I need to make multiple shapes (like circles, triangles, etc) and creating holes like that are too tedious.
Is there anyway where I can just have the edges of a shape be my bounding area? So that I can only make my outlines of a shape are able to detect hit.
BatVink
Moderator
16
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 27th May 2016 22:31 Edited at: 27th May 2016 22:31
I knocked up an image below, that shows the lines in a shape that break the rules in red. The first shape is OK, the other 2 are not. The interior angles are greater than 180 degrees, which is not allowed.
SetSpriteShape( mySprite, 3) will work out the best polygon fit for the sprite based on transparency.

Somewhere on this board there are a couple of free utilities for making complicated physics shapes. One of them is by Baxslash.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt

Attachments

Login to view attachments
NeedHalp
3
Years of Service
User Offline
Joined: 20th May 2016
Location:
Posted: 28th May 2016 05:15
Ahhh that's unforutunate. Thanks for your help though! Much appreciate it!
BatVink
Moderator
16
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 28th May 2016 10:47 Edited at: 28th May 2016 10:49
I should have added that both are possible with multiple shapes. This is a suggested layout for the shapes needed.
This is actually a constraint of all physics systems, not just AGK. You can calculate any collision point in a convex shape with simple maths. As soon as you add a convex element, the calculations become much more complicated by a large magnitude.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt

Attachments

Login to view attachments

Login to post a reply

Server time is: 2019-11-17 15:23:29
Your offset time is: 2019-11-17 15:23:29