Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Game Engines are Fun: Cocoa Design Patterns and a UIKit Game Engine

CocoaHeadsNYC
September 13, 2012

Game Engines are Fun: Cocoa Design Patterns and a UIKit Game Engine

Moshe Berman talks about MBTileParser, a game engine he's been working on for iOS. More info, including a link to the project's GitHub repository, at http://www.cocoaheadsnyc.org/2012/12/31/september-2012-demitri-and-moshe/.

CocoaHeadsNYC

September 13, 2012
Tweet

More Decks by CocoaHeadsNYC

Other Decks in Programming

Transcript

  1. Game Engines are Fun: Cocoa Design Patterns and a UIKit

    Game Engine Moshe Berman Sophomore, Brooklyn College CocoaHeads NYC Friday, October 5, 12
  2. • Why make a game engine? • Let’s Create a

    Game • Building a Better Engine with Design Patterns What We’ll Talk About Friday, October 5, 12
  3. Game Engines are Fun • Game engines make building games

    fun by hiding the complex parts. • Game engines are fun because games are fun. I grew up with Mario and Pikachu. I want those kinds of games on my iPhone. • Why? My iPhone has a better resolution than my GameBoy. Friday, October 5, 12
  4. How Many GameBoys? • Retina resolution is 960 pixels by

    640 pixels • GameBoy resolution is 160 pixels by 144 pixels • Fits 24 games at the same time, or, every Pokémon title ever with room for more! Retina iPhone GameBoy Friday, October 5, 12
  5. How Many GameBoys? • Retina resolution is 1136 pixels by

    640 pixels • GameBoy resolution is 160 pixels by 144 pixels • Fits 31 games at the same time. Retina iPhone GameBoy Friday, October 5, 12
  6. Why cocos2d? • It's really popular. • It's free. •

    Other engines were expensive, or lacked community and resources. Friday, October 5, 12
  7. Let’s Make a Game • Tiled, used to create tile

    apps from artwork. Friday, October 5, 12
  8. Let’s Make a Game • Tiled, used to create tile

    apps from artwork. • SneakyJoystick library for user input. Friday, October 5, 12
  9. Let’s Make a Game • Tiled, used to create tile

    apps from artwork. • SneakyJoystick library for user input. • TexturePacker, used to create sprite animation sequences. Friday, October 5, 12
  10. How cocos2d Works • One shared CCDirector • CCScenes contain

    CCLayers which contain CCNodes • All of these are visual classes. They’re the V in MVC. Friday, October 5, 12
  11. Why cocos2d? • It's really popular. • It’s free. •

    Other engines were expensive, or lacked community and resources. Friday, October 5, 12
  12. Why Not cocos2d? • Memory Management • Anti patterns •

    Memory Management • Memory Management: Autorelease ALL the things. • Anti patterns: No MVC, everything is a visual node, or an effect. • Memory Management: No ARC support until 1.1 and 2.0. Friday, October 5, 12
  13. MBMapView MBMapView - (void) initWithName:(NSString*)name; - (void) loadMap; - (void)

    buildCache; - (void) renderLayers; - (void) addSpriteForKey:(NSString*)key; - (void) removeSpriteForKey:(NSString*)key; - (void) moveSpriteForKey(NSString*) toCoords:(CGPoint)point; - (void) beginFollowingSpriteForKey:(NSString*)key; - (void) stopFollowingSpriteForKey:(NSString*)key; - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context; - (BOOL) tileIsOpenAtCoordinates; Object Group Object Group Object Group Sprite Tile Layer View Tile Layer View Tile Layer View Sprite Tile Layer Data Tile Layer Data Tile Layer Data Friday, October 5, 12
  14. MBMap MBMapView MBMap(View)(Controller) MBMapViewController - (void) initWithName:(NSString*)name; - (void) loadMap;

    - (CGSize)tileSizeInPoints; - (BOOL)tileIsOpenAtCoordinates: (CGPoint)coordinates forSprite: (MBSpriteView *)sprite - (void)interactWithTileAtCoordinates: (CGPoint)coordinates; Object Group Object Group Object Group Tile Layer Data Tile Layer Data Tile Layer Data Tile Layer View Tile Layer View Tile Layer View Sprite Sprite - (void) buildCache; - (void) layoutMap; - (void) moveSpriteForKey(NSString*) toCoords:(CGPoint)point; - (void) beginFollowingSpriteForKey: (NSString*)key; - (void) stopFollowingSpriteForKey: (NSString*)key; MBMap MBMapView Friday, October 5, 12
  15. •One-to-One relationships. •Don’t have to subclass to get special behavior.

    •Defined by protocols. Delegation Friday, October 5, 12
  16. #import <Foundation/Foundation.h> @class MBSpriteView; @protocol MBSpriteMovementDelegate <NSObject> - (CGSize)tileSizeInPoints; -

    (BOOL)tileIsOpenAtCoordinates:(CGPoint)coordinates forSprite:(MBSpriteView *)sprite; - (void)interactWithTileAtCoordinates:(CGPoint)coordinates; @end Delegation Friday, October 5, 12
  17. #import <Foundation/Foundation.h> @class MBSpriteView; @protocol MBSpriteMovementDelegate <NSObject> - (CGSize)tileSizeInPoints; -

    (BOOL)tileIsOpenAtCoordinates:(CGPoint)coordinates forSprite:(MBSpriteView *)sprite; - (void)interactWithTileAtCoordinates:(CGPoint)coordinates; @end Delegation Friday, October 5, 12
  18. #import <Foundation/Foundation.h> @class MBSpriteView; @protocol MBSpriteMovementDelegate <NSObject> - (CGSize)tileSizeInPoints; -

    (BOOL)tileIsOpenAtCoordinates:(CGPoint)coordinates forSprite:(MBSpriteView *)sprite; - (void)interactWithTileAtCoordinates:(CGPoint)coordinates; @end Delegation Friday, October 5, 12
  19. #import <Foundation/Foundation.h> @class MBSpriteView; @protocol MBSpriteMovementDelegate <NSObject> - (CGSize)tileSizeInPoints; -

    (BOOL)tileIsOpenAtCoordinates:(CGPoint)coordinates forSprite:(MBSpriteView *)sprite; - (void)interactWithTileAtCoordinates:(CGPoint)coordinates; @end Delegation Friday, October 5, 12
  20. Composition • The idea that you can make one class

    from many. • Allows you to avoid subclassing. • You do it all the time. Friday, October 5, 12
  21. It's UIKit • Yet incredibly fast. • Easy to use,

    no OpenGL. • Works with UIKit. Friday, October 5, 12