Answer the question
In order to leave comments, you need to log in
Image processing in iOS?
As a matter of fact, I'm making a small application for iOS for training. Idea - I have a map of the world, when a user clicks on a particular country, it, for example, is repainted in a different color.
Bad implementation, invented by me:
Take a map, and pave it with buttons on top (not UIButton, because I still want the button to have a country outline, not a rectangle, for this, OBShapedButton was found by googling). As soon as the user presses the button, make alpha = 0. At this time, under the buttons lay the map itself, already multi-colored. Voila - we changed the color.
But in reality, the implementation is very ... how to say, clumsy. If I want a country to be able to change color twice, or maybe 20 times, I need to overlay 20 buttons.
Questionis how to do it normally? In general, I would like to work with svg maps at the same time, but these are already trifles. In principle, the second idea is the outline of the map. When the user touches a particular country, we recolor this piece of the map. The problem is how to recognize which country the user has clicked on?
Or maybe you can suggest some more interesting solutions. Thanks a lot.
Answer the question
In order to leave comments, you need to log in
>The problem is how to recognize which country the user has clicked on?
Somewhere I saw such an implementation: there is a full-color image and there is its “map”, the dimensions corresponding to the image itself. The map is completely black and the pieces corresponding to the active areas on the original image are drawn on it in different colors. As a result, the task of determining the click area is reduced to determining the color of a pixel in the coordinates of the click. Correspondences area-color are registered in a separate structure.
If I understand your idea correctly, then you should look towards Cocos2d, as Enuriru advises .
You need a background (the map of countries itself)
Put sprites with cut out countries on it, the list of which you have in the countrySprites array.
A click on a country in this case will be determined easily in the ccTouchBegan:withEvent: method:
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
CGPoint touchLocation = [self convertTouchToNodeSpace:touch];
CCSprite * newCountry = nil;
for (CCSprite *sprite in self.countrySprites) {
if (CGRectContainsPoint(sprite.boundingBox, touchLocation)) {
newCountry = sprite;
break;
}
}
Why 20 buttons if you can just change their 'imageForState' using your algorithm/rule?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question