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/AppGameKit Studio Showcase / WIP: ShapeUp (Dev tool Polygon shape maker)

Author
Message
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 5th Mar 2012 22:56 Edited at: 12th Mar 2012 12:23
Hi all. I started this tool on a request thread by bjadams here:
http://forum.thegamecreators.com/?m=forum_view&t=192237&b=41

Now finished and open source!!
DOWNLOAD V1.0.1 updated 12th March 2012!
Version edits:
Added Zoom buttons and view joystick for small shapes



Usage:
1-Put your image into the "media/input" folder
2-Start the app
3-Randomise the background colour using the bottom right button if you can't see the image properly
4-Draw your shapes
5-Export using the "EXPORT" button. This creates a file called "yourImage.shp" for an image called "yourImage.png" in the "...\Documents\AGK\C_AGK_temp_Projects_ShapeUp_ShapeUpexe" folder.
6-Put the "loadPhysicsSprite()" function into your game after the loop
7-Put the image and "shp" file in your game's media folder
8-Call the load function to create a physics sprite using the shape you saved!

Use convex shapes only, built up in a clockwise direction and no more than 12 vertices per shape but you can add as many shapes as you like (I think)

Here is a load shape function that works with the output:


Here is a "loadPhysicsSprite" function:


Simples... ish...

Attachments

Login to view attachments
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 5th Mar 2012 22:59
Screenshot attached:

Attachments

Login to view attachments
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 6th Mar 2012 03:45
Well done "\" !
The Zoq2
15
Years of Service
User Offline
Joined: 4th Nov 2009
Location: Linköping, Sweden
Posted: 6th Mar 2012 11:28
This looks realy usefull!
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 6th Mar 2012 11:39
most useful AGK-specific tool to date
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 6th Mar 2012 12:11
Just updated the download in the first post.

I added a check for clockwise creation of shapes, it should no longer be possible to make a none clockwise shape.

The loading code is unchanged.

Next:
Make a cup of coffee
Convex shape check

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 6th Mar 2012 12:57
OK sorry for double posting but I added the convex shape check quicker than I thought. Must be bored today

I have also added some help text to tell you what is going wrong IE. "Shape not convex!" and a big red cross. If the current position of the cursor is valid the line goes green and the cross disappears. Sometimes when "snapping" to an existing point you may need to move the mouse around a little to get the red cross to go away but this all helps you create a working shape so I hope it makes sense!

Any bugs let me know.

I think the tool is done unless anyone has any further requests before I move back onto my main project (the one I made this tool for)?

bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 6th Mar 2012 13:59
requests?!!!!!

* ability to edit/move points after they are set
* option to load back shapes and continue editing or setting more shapes

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 6th Mar 2012 14:05
Thought you might have some

OK, I guess I could try that. I'll add a draw / edit button to toggle between modes. If a shape already exists for the currently loaded image it could load the shape too. Shouldn't be too hard!

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 6th Mar 2012 16:46
bjadams, just uploaded latest version which autoloads existing shape files and has an "Edit" button to drag existing points.

No validation in place for edit mode yet so if you make your shape none convex it's on your own head!

What about; When you export the shape it detects none convex shapes created in edit mode and asks if you want to recalculate the shape. If you say yes it decides where to make a change to the invalid shape automatically?

I also need to add a cancel button so a user can change their mind about a shape they have already started.

I also need a delete button to delete existing shapes.

...what have I let myself in for...?

bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 6th Mar 2012 22:46
Baxslash you're THE MAN!

delete existing shape & option to cancel current shape would be great!

btw, why can't the user create non-convex shapes? are these not allowed in the SetSpriteShapePolygon command?
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 7th Mar 2012 02:21 Edited at: 7th Mar 2012 02:22
Nice little app, Baxslash. I tend to use the simple setshape command normally as it does a pretty good job in the main. This would really speed up creating them yourself though. I'm sure lots of people will be putting it to good use!

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 7th Mar 2012 07:47
None convex shapes just go strange in Box2D.

The automatically created shapes are great but they only allow up to 12 polygons and convex shapes only. If you want concave shapes or holes you have to build them up using multiple shapes. This tool makes that process pretty painless.

I've got a new simple command for just defining the shape of a sprite based on a file name which I'll upload later. This utility works from centralised sprites so I might add some code to allow for offsets too before I post it.

3d point in space
15
Years of Service
User Offline
Joined: 30th Jun 2009
Location: Idaho
Posted: 7th Mar 2012 15:25 Edited at: 7th Mar 2012 15:27
I have already added this feature in my rapid xml features just have not updated the code in the forums. This is my polyline and my polygon code in rapid xml. if any one is interested.

rapid xml code.


If someone recodes rapid xml or another xml program for tier one then this would be good.


Developer of Space Chips, pianobasic, zipzapzoom, and vet pinball apps.
Developed the tiled map engine seen on the showcase.
Veterian for the military.

Attachments

Login to view attachments
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 7th Mar 2012 15:29 Edited at: 7th Mar 2012 15:32
@3d point in space, what does this xml code do? It's not immediately obvious what it has to do with my thread

EDIT: Here's the function I promised that just loads the shape to any sprite.


Duffer
21
Years of Service
User Offline
Joined: 9th Feb 2003
Location: chair
Posted: 7th Mar 2012 18:01
@ Baxslash - excellent - perhaps put this tool and the associated function with the UCF as well?

a long time dabbler with DBC and DBPro with no actual talent but lots of enthusiasm...
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 7th Mar 2012 18:09
I will once I release the source code this will be done once I'm happy with it...

New release to be uploaded very soon including option to delete shapes. There is one small bug I need to squash first. I just changed the whole data array setup for the shapes to make it work better and make it easier to understand for future development when the source is released.

Ideally I'd like to add the checking system for convex shapes in the export code first too... I want to highlight the offending point/s and let the user decide whether to ignore or fix.

3d point in space
15
Years of Service
User Offline
Joined: 30th Jun 2009
Location: Idaho
Posted: 7th Mar 2012 21:08 Edited at: 7th Mar 2012 21:27
It is how you can load a polygon from tiled. Instead of the editor that you just made. It has alot to do with your article because you have your own export command that exports the object as a shape I was just showing how to get the polygon from tiled which is a c++ way of doing this. I was just pointing out that if you had an xml parser for tier one you would not need your editor because you can make poly shapes with tiled. I use it know to define poly shapes similar as you did.

Developer of Space Chips, pianobasic, zipzapzoom, and vet pinball apps.
Developed the tiled map engine seen on the showcase.
Veterian for the military.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 7th Mar 2012 22:34 Edited at: 7th Mar 2012 23:11
I see so it's another method of loading polygons. What exactly is tiled? Can you draw poly shapes like my editor? If so then maybe I don't need to finish my editor (although I am nearly done)

EDIT: Now shows invalid points with a cross. This is constantly assessed so if you do any editing you will immediately see a red cross where there is an error. I'm just going to tidy up and add some error text then it's about finished for now. I'll upload a working version shortly and then full source code as soon as I'm happy with the code! Here's a screenshot:


Attachments

Login to view attachments
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 7th Mar 2012 23:50 Edited at: 7th Mar 2012 23:51
Version 0.0.6 now added to first post!



I've got the constant assessment of shapes working now and some better help text.

The background now only rotates shades of grey.

Deleting shapes is also now possible.

Be aware that edited shapes are saved on the fly overwriting existing shape files! I might change this to only create a temp file but not tonight

Attachments

Login to view attachments
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 8th Mar 2012 14:29
Just uploaded the fix I mentioned last night. I've tidied the code up a touch and added the source into the download in the first post of this thread.

You can use any / all of the attached source however you like, it's open source.

Enjoy!

...maybe someone wants to make it look pretty?

bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 8th Mar 2012 14:58
I am known to be a complainer, but let me take this opportunity to congratulate Baxslash on the awesome & wonderful job on this tool.

ShapeUp has now all the functionality one would need. I don't know if anyone managed to blindly draw AppGameKit shapes using co-ords. Most probably no one did up to now. NOW WE CAN do shapes with great ease!

THANKS!
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 8th Mar 2012 15:00 Edited at: 8th Mar 2012 15:01
Glad to make someone happy my pleasure!

EDIT: You can also see how I did it

DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 8th Mar 2012 19:31
Bjadams, yes at least one person has sat and manually done this, flipping from paint program to agk and back. I didn't realize that you could go over 12 points doing it manually though, so that is something I missed. I was just hoping to get the collision working on some track segments I was trying to use. I decided I would have to make my segments out of more parts in the end as I couldn't get it to work with a curved corner.
For instance, with the graphic here I have added blue to the bottom right so it will shape correctly. Remove the blue and that shape is not possible.
Would this tool help cure this or do I still need to make several sprites to get simple concave shapes to work?

Attachments

Login to view attachments
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 8th Mar 2012 20:22
This tool can be used to define any number of combined shapes for one sprite. The image does not need to have any resemblance to the physics/collision shape you want to make. It should work fine for your problem my lord vader sir!

The Slayer
Forum Vice President
15
Years of Service
User Offline
Joined: 9th Nov 2009
Playing: (Hide and) Seek and Destroy on my guitar!
Posted: 9th Mar 2012 16:05
Very very nice tool, bax! Will come in handy a lot.
Oh, and good luck with your next toddler.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 9th Mar 2012 16:06
Thanks Slayer!

basjak
14
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 9th Mar 2012 16:43
well done baxslash. amazing tool.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 9th Mar 2012 16:55
Thanks basjak! Glad you like it

MarcoBruti
13
Years of Service
User Offline
Joined: 20th Nov 2011
Location: Caput Mundi
Posted: 10th Mar 2012 00:38
thanks, it is very useful because I tried to define manually the shape by enumerating the single points, but with no success (because I lost my patience). No hopes for concave shapes without overlapping existing shapes? Has TGC some roadmap for some enhancement about this issue?
unlikely
12
Years of Service
User Offline
Joined: 5th Mar 2012
Location: Ohio, USA
Posted: 10th Mar 2012 05:49
I'd just like to chime in with my thanks too. Useful utility, saves a lot of time and tedium.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 10th Mar 2012 08:07
It's a limitation of box2d but you can make concave shapes by adding more polygons using my editor

DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 11th Mar 2012 04:17
Sounds just the job by the sounds! Of course, in the meantime I moved to a new game, inspired by your platform tutorial btw. I had done a fair bit of work to one before 'the crash', but it didn't make use of physics. So I decided as I had to start over anyway I may as well use the physics engine this time round. So nice job on the tut as it encouraged me to try a different approach.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 11th Mar 2012 10:04
Glad to help DVader

Hope you like the next one too. It's about using arrays and timer based movement.

MarcoBruti
13
Years of Service
User Offline
Joined: 20th Nov 2011
Location: Caput Mundi
Posted: 11th Mar 2012 22:20
@baxslash
I do it right now by overlapping triangular sprites. For my flipper app, I approximate a good smooth curve with 4 triangles.
Of course, using my approach requires 4 collision detections with 4 overlapping sprites and 1 poly shape for each sprite.
By using more shapes, AppGameKit must detect a single sprite collision with 4 shapes. I think that the last approach is more CPU-optimized.
Is it possible to see more than one shape overlapped on the same image?
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 11th Mar 2012 22:33
Why don't you upload one of your images and I'll show you how I would make the shape for it?

MarcoBruti
13
Years of Service
User Offline
Joined: 20th Nov 2011
Location: Caput Mundi
Posted: 12th Mar 2012 00:07
here you are. It is very simple.

Attachments

Login to view attachments
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 12th Mar 2012 08:52 Edited at: 12th Mar 2012 08:53
Here is an image of how I would build this shape:


I multiplied the image size by 4 as it was very small. I think what I need to do is add a zoom feature to make this easier as currently you would need to divide the results by 4:
Quote: "
Number of shapes
4
Shape 1
Number of points:
3
Point 1
-128.000000 <<<<<<each of these would need to be divided by 4
-96.000000 <<<<<<each of these would need to be divided by 4
Point 2
128.000000 <<<<<<each of these would need to be divided by 4
-96.000000 <<<<<<each of these would need to be divided by 4
Point 3
6.000000 <<<<<<each of these would need to be divided by 4
-73.000000 <<<<<<each of these would need to be divided by 4
"


I will add the zoom code and then this will be much easier for you!

Attachments

Login to view attachments
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 12th Mar 2012 12:25
Just uploaded V1.0.1 to the first post including a new view joystick (to navigate around the image) and zoom buttons in the top right corner.

This should make small / tricky shapes a bit easier

MarcoBruti
13
Years of Service
User Offline
Joined: 20th Nov 2011
Location: Caput Mundi
Posted: 12th Mar 2012 18:29
Thanks a lot! One of the most useful tool for AppGameKit! In next release you could add zooming and mirroring the shapes, the latter may be useful when flipping or rotaing the image...
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 12th Mar 2012 18:35
Glad to help Marco

Sprite size is taken into account when the shape is loaded (even for stretched sprites). I guess I could add a scale option to the load function but I think it is not completely necessary. Mirroring is something I hadn't considered. That will require the points being reversed, not terribly hard but I think it's going to be a function that you would need in your code rather than a feature of the tool.

What about:
flipShape(spriteID,hor,ver)?

unlikely
12
Years of Service
User Offline
Joined: 5th Mar 2012
Location: Ohio, USA
Posted: 14th Mar 2012 17:03
Why not a scale function? You could flip that way too.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 14th Mar 2012 18:18
Quote: "Why not a scale function? You could flip that way too."

Yes, that would be a good way to do it.

bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 14th Mar 2012 23:44
Great update!

Login to post a reply

Server time is: 2024-11-21 13:19:58
Your offset time is: 2024-11-21 13:19:58