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.

AppGameKit Classic Chat / Irregular polygonal regions

Author
Message
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
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!

-- Jim
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 4th Dec 2011 20:41
You could have a mask image, and use that image as the collision zone for the sprite?

My signature is NOT a moderator plaything! Stop changing it!
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
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.

JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 5th Dec 2011 00:13
Thanks, BatVink. I have a very powerful editor - it's case of translation into appropriate AGC code. Tiny example would gratefully received!

-- Jim
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 5th Dec 2011 09:56
You can also use "setSpritePhysicsIsSensor" to stop other physics sprites reacting to it.

JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
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.

-- Jim
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
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.

JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 5th Dec 2011 23:15
Thanks, BatVink. I'll have a look at that.

-- Jim

Login to post a reply

Server time is: 2024-11-22 19:19:27
Your offset time is: 2024-11-22 19:19:27