Skip to main content
deleted 2 characters in body
Source Link
David Gouveia
  • 24.9k
  • 5
  • 87
  • 125

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 them. E.g the values. The file could look like:

spikes1 1 0
spikes2 0.5 0
spikes3 0.5 0
spikes4 0.5 0
bush-a 0.5 0.25
bush-b 0.5 0.25

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):

foreach(entry in anchorFile)
{
    string[] data = entry.split(' ');
    string name = data[0];
    doublefloat x = parseDoubleparseFloat(data[1]);
    doublefloat y = parseDoubleparseFloat(data[2]);
    imageRegistry[name]imageDictionary[name].setAnchorPoint(cpp(x, y));
}

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.

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 them. E.g the file could look like:

spikes1 1 0
spikes2 0.5 0
spikes3 0.5 0
spikes4 0.5 0
bush-a 0.5 0.25
bush-b 0.5 0.25

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):

foreach(entry in anchorFile)
{
    string[] data = entry.split(' ');
    string name = data[0];
    double x = parseDouble(data[1]);
    double y = parseDouble(data[2]);
    imageRegistry[name].setAnchorPoint(cpp(x, y));
}

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.

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:

spikes1 1 0
spikes2 0.5 0
spikes3 0.5 0
spikes4 0.5 0
bush-a 0.5 0.25
bush-b 0.5 0.25

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):

foreach(entry in anchorFile)
{
    string[] data = entry.split(' ');
    string name = data[0];
    float x = parseFloat(data[1]);
    float y = parseFloat(data[2]);
    imageDictionary[name].setAnchorPoint(cpp(x, y));
}

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.

Source Link
David Gouveia
  • 24.9k
  • 5
  • 87
  • 125

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 them. E.g the file could look like:

spikes1 1 0
spikes2 0.5 0
spikes3 0.5 0
spikes4 0.5 0
bush-a 0.5 0.25
bush-b 0.5 0.25

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):

foreach(entry in anchorFile)
{
    string[] data = entry.split(' ');
    string name = data[0];
    double x = parseDouble(data[1]);
    double y = parseDouble(data[2]);
    imageRegistry[name].setAnchorPoint(cpp(x, y));
}

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.