I am currently working on an iPhone project, but most of my work has been in Flash. Flash has a feature where you can place a bitmap into a MovieClip, set its registration point with the mouse and it's automatically adopted. It's one of the lovelier Flash features.

Now I'm doing iPhone stuff, using TexturePacker for importing the graphics, and I'm having to write code like this:

3 Answers
3

If you're referring about not having to hardcode all of of those anchor points, you could move them to an external file, and after loading all of the images, just read and iterate through your anchor file and set the values. The file could look like:

And for easier access, after loading the images you cold store them in some hashtable or dictionary using the name of the graphic as a key. Then to assign the anchor points it would be something like (in pseudocode because I'm not familiar with Objective-C):

To help you generate the file, you could also create a simple offline tool where you'd load all of your images, click once on each of them, and then it would generate the data file for you with all the anchor points recorded. Should be fairly trivial to implement.

A generic, shared anchor point would not work for this situation. The art is too varied and the anchor point needs to match the visuals. My level editor is written specifically for this game and definitely handles this ok.
–
Chris Burt-BrownJan 3 '12 at 11:16

@ChrisBurt-Brown But why does it have to match the visuals? Do you plan to rotate the sprites? In any case: If you have your own level-editor, why not make the anchor-point editable there and output it with your other level data?
–
bummzackJan 3 '12 at 11:27

It has to match the visuals -- um, imagine a Box2D polygon breaking up into bits, with sprites attached to the polygon, they have to follow the right "chunks". So they need to know the point they are attached at. As for the level editor, I don't want to put the burden on the level designer to place the anchor point correctly. I want that to all be sorted out before level design begins.
–
Chris Burt-BrownJan 3 '12 at 11:36

@ChrisBurt-Brown If you're using Box2D, then you might consider PhysicsEditor. It also allows you to set the anchor point and provides helper classes that will allow you to parse and apply the anchor point from the meta-data.
–
bummzackJan 3 '12 at 12:03

Usually artists manage their assets folder where they create their graphics in .psd format or something else with layers. By convention a specific layer named anchor is created which contains a single opaque pixel (other pixels are ignored), and the artists define that pixel as the rotation point for the sprite. Then, in your conversion process from .psd to your own formats you split the layers and convert the coordinate to a text file which you can later load like David Gouveia mentioned.

If you are dealing with a layer-less art pipeline, you can then use the convention of storing several files for the same graphic, like sprite1.png and sprite1_anchor.png, where the anchor point has already been split by the artist into a separate graphic. This puts pressure on the artists to remember to update the anchor files, though anchors don't tend to change that much.