Coloring game

Posts: 1
Joined: 2010.12
Post: #1
I am looking at writing a coloring game which once if we click on the color and select an object in the graphic only the object gets colored, for ex: if I have a horse and i click on its tail only the tail gets colored.
However i am not able to get the exact co-ordinates or the object's area so that only that part gets colored.
Any help in this regard would be greatly appreciated.
Quote this message in a reply
Posts: 916
Joined: 2002.10
Post: #2
Sounds like you're looking to do a simple flood fill on the area. That of course only works if all the white pixels are connected. Do you need something more elaborate?
Quote this message in a reply
Posts: 5,143
Joined: 2002.04
Post: #3
I'd precalculate the areas (perhaps still using floodfill, or perhaps by having the artist draw masks in Illustrator). Floodfill at run-time will break when the kid colors everything black.
Quote this message in a reply
⌘-R in Chief
Posts: 1,277
Joined: 2002.05
Post: #4
I would create all the art as bezier paths. You can use the paths to determine what the user touched, and filling a path with a color is simply changing the fill color of the path.

The only complicated part is getting from a file format containing the paths, to a CGPath or NS/UIBezierPath. An SVG file is an xml file containing vector paths which are apparently described in a way where it's really easy to build a CGPath or NS/UIBezierPath from them, and any self-respecting vector art application will have an SVG export feature. You could look there.
Quote this message in a reply
Post Reply