My first GitHub project! – A MKPolygon Category – Polygon Intersection!

I am happy to announce my very first open source project that is now on GitHub! You can check out (no pun intended) the repo here and run it in XCode!

I have been playing around the MKMapKit framework for a while and I have solved lots of different types of geo-spatial problems before (in different programming languages) but thought that the geo-spatial functionality, surrounding MKPolygons (which conform to the MKOverlay protocol) was a bit lacking.

If you check out the MKOverlay Protocol Reference you will see that you do have a a method called ‘intersectsMapRect:(MKMapRect) ‘ but then it only tells you whether or not your shape intersects with a rectangular area or not. That could be useful but what if I wanted to test whether two non-rectangular MKPolygons intersected? What if I wanted to do something REALLY crazy and create a brand spanking new MKPolygon that was the result of the union of two non-rectangular MKPolygons? Well, if you have ever wanted to do such a thing, then you are in luck because now there is a MKPolygon category that does just that!

I accomplished this task by using some good old fashioned slope-intercept math (and had to add special test cases) and writing my own custom algorithm to figure out a lot of the rest once I calculated all of the main intersection points.

Below are screenshots from a test, using view controller code. Basically just a MapView and the view controller to handle all of the GUI stuff. When i am done drawing 2 polygons on the map, I then call the category class method to return to me a new MKPolygon and I use that new polygon as a new overlay (colored orange) on the mapview. (see the view controller code for more details).

Screenshot 2013.06.25 13.46.46

Map View

Screenshot 2013.06.25 13.48.32

Drawing Polygon 1 on the map

Screenshot 2013.06.25 13.48.50

Finished Drawing Polygon 1 – Area Filled In

Screenshot 2013.06.25 13.49.28

Drawing Polygon 2

Screenshot 2013.06.25 13.49.43

Finished Drawing Polygon 2 and the intersection of both polygons is calculated and updated on the map!

Let me know what you think!

Rack Your Brain – Version 0.8

Screenshot 2013.05.27 21.43.32

Click To Enlarge

Here is the latest screenshot from my latest build – I have been keeping up with versions this whole time and I am currently at v0.8…close to something pretty complete. The following highlights of the game have been extensively tested and are deemed complete at this point. However, as I add the last features to the app, there will be other rounds of testing to ensure no bugs make their way back into the code.

Highlights Include:

  • Graphic Art mostly complete and is compatible with retina and non-retina displays
  • Animation Block code for flipping each game card as needed complete
  • Code for managing swipe gestures to navigate between screens is bug free (including the CATransition animation)
  • NSTimer for the level time done (last build)
  • Full randomization of game cards for every level(across all potential screens) passes all tests
  • Most sound effects have been integrated
  • Loading in all card data for every level of every game now has been streamlined

Still some things to get done.

  • Core Animation card tiles
  • Core Animation for start up/loading screen
  • Game theme and the remainder of sound effects need to be integrated
  • Creation of special button pop-up window for certain cards
  • Game screen background art/color scheme w/possible Core Animation stuff going on
  • Change look & feel of score/level/time font
  • Interaction with certain special tiles
  • Integration with the Game Center

That will at least take me to v0.9 maybe even v0.95 before the final touches to release this app as v1.0 complete! I will be working hard the next 3 or 4 weeks getting most of this done so we will see how that goes.

The Sound of Music

I have now added most of the sound effects and it sounds really good. The sound effects are used for some of the following:

  • When a new level is loaded and comes into view
  • When the player taps on the game tile
  • When the game tile finishes turning over after the player taps on it
  • When the game tiles turn back over
  • When the player gets a match
  • When the player uses a specialty tile(unique sound effect for each one)
  • Swiping between screens
  • When time is running low

Still have some more to add but mainly just tweaking the code as needed to make sure the timing of the sound effects are spot on.

Rack Your Brain – Latest Build/Update

Screenshot 2013.03.02 23.32.18So this is the latest! I now seem to have the code to handle all of the swiping working correctly. I had some issues that I had not planned for, concerning the animation of the swipe. For instance, as you know, you can have a game tile whose match is on another screen. Let’s say you know exactly where that match is. You tap on the first game tile then immediately swipe to the next screen. A couple of things that I am trying to keep up with here.

  • What screen am I swiping from?
  • What screen is going to animate in?
  • The identification of the 1st game tile that was selected (so that I can check for the match) when the 2nd game tile is selected.
  • Given the screen that I know is animating in, what is the traversal information for that screen? I need this so that i can update the arrows appropriately and I can set up checks ahead of time before the next swipe.

I don’t want to get too too technical but the crux of a few of my problems centered around not updating the model and/or view at the right times during all the animations involved here. You have to remember that in a MVC design, the view itself knows absolutely nothing about the contents of its game tiles – it gets that information from the model every time we swipe to the new screen and then its job is to display that content. The content in this case, is what’s under each game tile.

However, both model and view have to know what game tiles have been selected on that screen (the model knows which ones have been selected on multiple screens if applicable). First, the view will need perform custom animations, that I will be writing, on a game tile or tiles if there is a match. (which will including removing that game tile from the view). Second, the model needs to update itself if there is a match (or not) so that it can correctly send the view controller the appropriate contents when you swipe back to a screen that has had matches in the past (or anything other changes that have occurred during a level).

In code, I handle some of this functionality using the NSNotificationCenter, which is one of  most powerful classes in Objective-C that I absolutely love. In any event, what was happening, is that some of the notifications sent to the model (and/or view controller) didn’t sync up appropriately with the swipe animation (which also posts a notification) and I was getting some bugs related to some of the bullet points above.

To solve the issue, I had to slightly modify the model code receiving these notifications, along with using the CAAnimation delegate methods animationDidStart and animationDidStop:finished: so that I could fine tune when I wanted to update both the model and view controller during a swipe animation (i.e. when the notification of a swipe was posted for all relevant recipients).

Speaking of animations, looks like the next thing to do is to write those custom animations mentioned earlier, for things like selecting a matching set. This is going to be super fun. In addition, one of the low lying fruits that I need to pick off is to add sound effects for a variety of events in the game. More on that soon.

Finally, this might be the last of an in-game screenshot that I am going to post until I get REALLY close to submitting this to the app store. Lots of things about the app are finally coming together, including in-game images and I don’t want to give too many things away too soon. :)

MapKit Showcase

So I am now on this iOS project at work, that is centered around MapKit framework.  When the app starts you have a split view controller (this app is iPad only). On the left you have a table view and on the right is a map view. Each table view cell represents the location of one of many different types of custom annotations.  When you tap on a certain table view cell, (the mapview pans to the coordinate location of the annotation and a detailed view (a .xib file) is shown to show certain attributes about this annotation. While I cannot mention specifically the type of annotations are available, they are diverse.

What they want to do is have the capability to draw polygons around certain types of annotations and edit the polygons as needed. That’s where I come in. I have worked on iOS projects before using the MapKit framework but not specifically drawing shapes on the map, so this was a fun part of the framework to learn (I obviously don’t know every single method of the entire framework but I have a good feel for lots of it). Anyway, I started working on getting this functionality to work outside of the current project, just as a standalone test app to see how much I could get working/what I could get working before worrying about any integration into the current code base.

The way my code works, is that when you are in drawing mode, every single tap (recognizer) draws a MKCircle overlay at that coordinate and any subsequent tap draws a MKPolyLine overlay so that the user can clearly see what the polygon (MKPolygon) is going to look like. Obviously, with every tap, I update the MKPolyLine overlay accordingly. screenshot below:
Screenshot 2013.05.18 22.58.34Screenshot 2013.05.18 22.59.05Screenshot 2013.05.18 23.03.06When you are finished drawing the polygon you can tap “Done” and voila!… a new polygon has been created (MKPolygon overlay, yellow fill color, alpha of 0.4).

Screenshot 2013.05.18 23.08.33Below is a screenshot of two more polygons that I have added:

Screenshot 2013.05.18 23.16.02

If you expand the last image you will notice that some of the MKPolyLines appear to be jagged. I spent some time searching around to see what this was about and haven’t found an answer yet. If you know, please send me an e-mail or comment. Also, another thing that I have noticed, is that each time I add a new overlay to the map, the other overlays display some sort of “blinking” behavior. I wasn’t sure what was going on here but I did find a few questions about it in the apple dev forums and there seems to be an overlay bug with no solution as of yet. People seem to be claiming that it’s worse in iOS 6 than it was in iOS 5. Just a heads up.

To find out more of what I have accomplished so far, please head on over to the iOS page!


The project at work that I have been on at my real job has started to pick up beyond a normal work week. We’ve been at it for a couple of weeks now and looks like it will be this way until around the end of this month or the first week of April. This, of course, means that the progress on my app, will considerably slow down or be non-existent. When you work extra hours and have other ‘outside of work personal life stuff’ there isn’t much room to sit in front of a bunch of pixels much less be productive…..unless I want to become a zombie and burn myself out, which would not be the smart thing to do.

I will post back with, hopefully another update, after things get back to normal.

Rack Your Brain – Tornado!

This past week has been very interesting. In case you didn’t see the news, we got hit by a major tornado last week (Feb 10th). I just got internet back after a week and was without power for 3 days. The tornado came within 0.3 miles of my house and it was about 1/2 a mile wide! It doesn’t look like anyone was killed and only a few people were injured.

Anyway, I’ve been working heavily on the code that relates to swiping the screen. I’ve had a few glitches and bugs along the way but got most of those solved I think. Just trying to make sure that I get the sequence of events in the right order and that they are timed with the transition animations at the point the user swipes. Also I have been doing some major testing to make sure that when I swipe, I am getting the right content back for the screen that is animating into view. I’ll go ahead and share with you a picture I took of one of my whiteboard sessions. Enjoy!

2013-02-18 13.39.41

Rack Your Brain – Build Update

Screenshot 2013.02.17 01.07.45Here is another update for your viewing pleasure. This is the screen that you see as soon as the app starts. I have been taking some Christmas and New Years vacation but I have still gotten a lot done. Some of what I have accomplished includes:

  • IBOutlets connected
  • NSTimer added and counting down correctly
  • All game and level information loading in (level number, timer value for level)
  • Game tile content loaded in(right now just background colors) and displayed on the screen as a subview to the tile view (which is a subview to the main view).
  • All tile content randomized correctly (every time the app starts the set of colors are the same but they are always in different spots).
  • Specialty tiles added with names (I will not tell you what they do, you will have to play the game to find out!)

I will be working next on loading content for levels with multiple screens and introducing the swiping functionality. This is where the meat of the app is going to be. I am going to have to manage swiping to the next screen and figuring out which screen that is going to be(depending on where I am swiping from). Once i find that out, then the appropriate set of 24 game tiles will have to be loaded from the model and sent to the view controller so that the transition animation code can do its thing. Also I will need to know about the traversal information… i.e. what directions am I allowed to swipe for this new screen? I will need to know this to keep the player from swiping to a screen that doesn’t exist and updating my arrow images (still WIP) appropriately the let the user know which direction(s) they are allowed to swipe.

Everything seems to be going smoothly so far but i know there’s quite a lot of code left to write. Stay tuned!