Posted: 4th Dec 2011 20:39
is there way to describe an irregular polygon as a series of vertices, then convert the interior of this polygon into a hit or drop zone?

Feel free to skip the lengthy explanation below!

We have a very powerful engine (developed with EU money) for creating language-teaching exercises of a cute and games-like nature. We'd like to produce a similar authoring and delivery system cross-platform, hence the interest in AGK.

One kind of exercise involves dragging and dropping a word or phrase onto the appropriate part of a picture. For example, drop the word "hand" onto one of the hands of a background picture of a very pretty girl.

Rather than having a vast array of sub-images created in a paint package, in authoring mode creators/teachers can simply click th polygonal vertex in order. You can get quite tight around the hands, for example.

Thisn is save in the exercise definition file a list of vertices. At run-time this list is used to create a bitmap and filled. This is part of a "smart" object with a positive Z-order.

When a student drags and drops the "hand" word onto the list of active objects is scanned to see if it is associated with dropped object. So then it will either right or wrong.

There's probably a way to do this with AppGameKit which I haven't spotted! If not, it would be very useful. You might want a hero to hit a dragon on the nose. Have one dragon, and many regions!
Posted: 4th Dec 2011 20:41
You could have a mask image, and use that image as the collision zone for the sprite?
Posted: 4th Dec 2011 21:42
You can use the built-in physics to achieve this. The bodies you make can be static or kinematic, and it will allow you "normal" control but with all the functionality of collision detection.

You may need to make yourself a little editor to design the shapes. The maximum number of vertices for a fixture is 8, and each fixture must be convex. However you can stick as many fixtures together as you need with fixed joints to make complex shapes.
Posted: 5th Dec 2011 0:13
Thanks, BatVink. I have a very powerful editor - it's case of translation into appropriate AGC code. Tiny example would gratefully received!
Posted: 5th Dec 2011 9:56
You can also use "setSpritePhysicsIsSensor" to stop other physics sprites reacting to it.
Posted: 5th Dec 2011 11:41
I can't get this to work in the way I would like. It really seems to want a sprite image. SetSpriteShapePolygon() is quoted as the way to do it with no actual image in the documentation, but the documentation is not at all clear on this function.

What it needs is to give a list of up to 12 points which represent the bounds of the region and effectively flood-fill inside this. This should not be too much of a problem in Tier 2, but unless it could work automatically in Tier 1 it would be hard.
Posted: 5th Dec 2011 21:37
SetSpriteShapePolygon() is a way to automatically create a "best fit" convex fixture and shape.

AddSpriteShapePolygon() is how you would create a new polygon of your specification. In DBPro it's limited to 8 points, but in AppGameKit I see it is 12. It has to be attached to a Sprite, but you could use a dummy Sprite (CreateDummySprite) which does not display but facilitates a physics shape.

I don't know if you have to add joints with AddSpriteShapePolygon(). It looks to me like all shapes attached to one sprite are by default joined with a Weld Joint.
Posted: 5th Dec 2011 23:15
Thanks, BatVink. I'll have a look at that.