Cocos2D for Fun and Profit

Cocos2D for Fun and Profit

Cocos2D is a fun little 2D graphics library that makes it easier to make OpenGL games. In this talk, you'll learn about the core concepts of Cocos2D.

This was presented by Jon Manning of Secret Lab at Swipe Conference 2012 in Sydney.

Read the blog post at http://blog.secretlab.com.au/2012/09/09/swipe-conference-2012/

Source code is available at https://github.com/thesecretlab/swipeconf2012.

6ed02dec32058508c6feb43b2fbc94f7?s=128

Secret Lab

August 07, 2012
Tweet

Transcript

  1. Secret Lab Jon Manning Cocos2D for Fun and Profit

  2. Hi!

  3. None
  4. SECRET LAB

  5. REDACTED

  6. REDACTED

  7. Neal Goldstein Jon Manning Paris Buttfield-Addison Learn to: • Build

    an actual game from start to finish • Recognize what makes a good game for Apple’s mobile devices • Use Objective-C®, Cocoa®, OpenGL ES 2.0, and other iOS programming tools • Connect your app to Facebook, get it into the App Store, and market it iPhone® & iPad™ Game Development Making Everything Easier!™ ompanion Web site at www.dummies.com/go/ egameprogramming to find plenty of sample other materials to help you create the examples ok Open the book and find: • The latest and greatest on the iPad, iPhone 4, and iOS 4.0 • Elements of great game design and architecture • Why you need to be a registered Apple developer • Why scoring is critical • How to debug your games • What provisioning is and why you need to know • Important social aspects of game design • Key differences between games on the iPad and the iPhone ldstein has a rock-star reputation among iPhone developers. e iPhone Application Development For Dummies and frequently at conferences. Jon Manning and Paris Buttfield-Addison are the rs of Secret Lab, a game design company that builds fun things for e and iPad when the principals aren’t playing games for research. $29.99 US / $35.99 CN / £21.99 UK ISBN 978-0-470-59910-5 Programming/Apple/Mobile Device Go to Dummies.com® for videos, step-by-step examples, how-to articles, or to shop! bby or a — create cool games st devices around! Pad or iPhone game but don’t know ad this book and you will! You’ll see that play wonderfully on the small ed in becoming a registered developer, e SDK, key features of game architecture, games, and more. Get your game on! od game? — learn the fundamentals of good loper’s hat — become a registered Apple how iOS games work, and understand s are made of — build a native user interface, architecture fundamentals, learn to animate and grasp the basics of OpenGL nd get social — set up a scoring system and learn to e into social networks like Facebook o market — get your game into the App Store and etability with such bonus features as gestures, ternal displays, and ad-supported revenue iPhone® & iPad™ Game Development Goldstein Manning Buttfield-Addison spine=1.01”
  8. None
  9. What’s Cocos2D?

  10. None
  11. None
  12. None
  13. None
  14. None
  15. None
  16. None
  17. None
  18. What’s Cocos for?

  19. UIKit Object-oriented Designed for UIs Easy to use, tricky to

    extend OpenGL Immediate mode Designed for 3D Maximum flexibility, steep learning curve
  20. Why is OpenGL hard?

  21. OpenGL assumes nothing about your content

  22. glBindTexture(GL_TEXTURE_2D, 13); glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, imageWidth, imageHeight, 0, GL_RGB,

    GL_UNSIGNED_BYTE, imageData); glBegin (GL_QUADS); ! glTexCoord2f (0.0, 0.0); ! glVertex3f (0.0, 0.0, 0.0); ! glTexCoord2f (1.0, 0.0); ! glVertex3f (10.0, 0.0, 0.0); ! glTexCoord2f (1.0, 1.0); ! glVertex3f (10.0, 10.0, 0.0); ! glTexCoord2f (0.0, 1.0); ! glVertex3f (0.0, 10.0, 0.0); glEnd ();
  23. Cocos2D makes a bunch of assumptions

  24. None
  25. None
  26. REDACTED

  27. UIKit Object-oriented Designed for UIs Easy to use, tricky to

    extend OpenGL Immediate mode Designed for 3D Maximum flexibility, steep learning curve
  28. UIKit Object-oriented Designed for UIs Easy to use, tricky to

    extend OpenGL Immediate mode Designed for 3D Maximum flexibility, steep learning curve
  29. UIKit Object-oriented Designed for UIs Easy to use, tricky to

    extend OpenGL Immediate mode Designed for 3D Maximum flexibility, steep learning curve Cocos2D Object-oriented, OpenGL available Designed for 2D Easy to build dynamic 2D scenes
  30. Cocos is great for: •2D games •Anything with lots of

    2D animation •Simple OpenGL
  31. Cocos is not so great for: •Interfaces •Text-heavy apps •Apps

    that should follow the iOS HIG
  32. The Game

  33. None
  34. G!"# $% &'# Y#!(

  35. A word on art!

  36. None
  37. None
  38. Slicy

  39. None
  40. None
  41. Getting Started

  42. Get it from GitHub http://github.com/cocos2d/cocos2d-iphone

  43. The Director

  44. Director

  45. Director Main Menu

  46. Director Main Menu Game

  47. Director Main Menu Game

  48. Director Main Menu Game

  49. Nodes

  50. Director Scene

  51. Director Scene Node Node Node

  52. Director Scene Node Node Node

  53. Director Scene Node Node Node Node Node Node Node

  54. Actions

  55. Actions modify nodes

  56. None
  57. Move

  58. Rotate

  59. Move+Rotate

  60. { code }

  61. None
  62. Move Wait Run Code

  63. Scheduling

  64. [self schedule: interval: 1.0] Schedule a method to run in

    1 second: @selector(doSomething:) @selector(doSomething:)
  65. [self schedule: interval: 1.0] Schedule a method to run in

    1 second: @selector(addEnemy:) @selector(addEnemy:)
  66. [self schedule: interval: 1.0] Schedule a method to run in

    1 second: @selector(earnPoints:) @selector(earnPoints:)
  67. [self schedule: interval: 1.0] Schedule a method to run in

    1 second: Schedule the update: method to run every frame: [self scheduleUpdate] @selector(earnPoints:) @selector(earnPoints:)
  68. -(void) update:(ccTime)deltaTime { // Run code every frame in this

    function }
  69. -(void) addEnemies:(ccTime)deltaTime { // Add an enemy }

  70. Collision Detection

  71. None
  72. ?

  73. None
  74. Rock

  75. Player Rock

  76. Player Rock

  77. Circle-Circle Collision distance(center1, center2) < radius1 + radius2

  78. Taking it further

  79. Further Reading

  80. None
  81. http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:index Cocos2D Programming Guide (or just search for it)

  82. Thanks!

  83. @thesecretlab

  84. None