So 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.