Model Implementation (MVC) for Cocos2D

Forums Programming Programming – Everything else Model Implementation (MVC) for Cocos2D

This topic contains 9 replies, has 7 voices, and was last updated by  iUridium 2 years, 3 months ago.

Viewing 10 posts - 1 through 10 (of 10 total)
Author Posts
Author Posts
September 1, 2011 at 1:52 pm #234893

tonyngo
@tonyngo

I’m a fan of the Model-View-Controller design pattern. In game programming, often it unnecessarily increases complexity, but sometimes it’s useful.

I could not find any example of an implementation of a model, so I decided to roll my own, inspired by Flixel, an ActionScript game engine:

I’ve been doing web development for over five years, but I’m new to game programming. I still have much to learn :) Please let me know what you think.

http://tonyngo.net/2011/09/model-implementation-for-cocos2d/

September 1, 2011 at 2:29 pm #345796

phil_me_up
@phil_me_up

Looks interesting – for me though, MVC is a very good way of writing easy to understand / maintain code (once you know the MVC pattern) but it probably isn’t the most efficient / flexible of systems and when it comes to games, you don’t want to be wasting any processing power at all.

I would be interested to see a more complete example.

September 1, 2011 at 8:13 pm #345797

tonyngo
@tonyngo

@phil_me_up thank you for responding. How can I make the example more complete?

September 1, 2011 at 9:21 pm #345798

psykano
@psykano

@tonyngo I’m guessing that, for starters, you don’t mention the Controller side of things. :P

September 1, 2011 at 11:33 pm #345799

tonyngo
@tonyngo

@psykano I see :) It wasn’t my intention to provide a complete example MVC itself. I wanted to show how to group variables into an object and bind to value changes, all without the complexity of defining custom delegates or using notification observers. I’m not sure if my approach is the right way; that’s why I’m asking for opinions. Hopefully experienced developers could shed some light :)

November 26, 2011 at 10:19 am #345800

festival
Participant
@festival

@tonyngo Thanks for sharing. Polling for Model changes is not a good idea. The flaw is a) you have a update loop b) you might miss a model change

November 26, 2011 at 10:24 am #345801

Stepan Generalov
Moderator
@ipsi

I agree. You should use Observer pattern to handle changes in Model.

In Objective-C KVO is the best way to do it.

January 7, 2012 at 1:32 pm #345802

festival
Participant
@festival

@StepanGeneralov What do you mean by KVO?

January 7, 2012 at 3:18 pm #345803

Martin
Participant
@martinh

What’s your view on using callbacks from the model to the view/controller for state changes? Is this basically KVO (which I don’t know)?

January 7, 2012 at 3:19 pm #345804

iUridium
Participant
@iuridium

KVO is Key-Value Observing method (little googling should help ;-)). In iPhone programming there are 2 options when bringing observing topic on the table; using KVO or NSNotification. For Model changes seems to me that notifications would be better option.. On the other hand, KVO is much lighter.. Not really sure, what do you think?

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.