$30 off During Our Annual Pro Sale. View Details »

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.

Secret Lab

August 07, 2012
Tweet

More Decks by Secret Lab

Other Decks in Programming

Transcript

  1. Secret Lab
    Jon Manning
    Cocos2D
    for Fun and Profit

    View Slide

  2. Hi!

    View Slide

  3. View Slide

  4. SECRET LAB

    View Slide

  5. REDACTED

    View Slide

  6. REDACTED

    View Slide

  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”

    View Slide

  8. View Slide

  9. What’s Cocos2D?

    View Slide

  10. View Slide

  11. View Slide

  12. View Slide

  13. View Slide

  14. View Slide

  15. View Slide

  16. View Slide

  17. View Slide

  18. What’s Cocos for?

    View Slide

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

    View Slide

  20. Why is OpenGL hard?

    View Slide

  21. OpenGL assumes nothing
    about your content

    View Slide

  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 ();

    View Slide

  23. Cocos2D makes
    a bunch of assumptions

    View Slide

  24. View Slide

  25. View Slide

  26. REDACTED

    View Slide

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

    View Slide

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

    View Slide

  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

    View Slide

  30. Cocos is great for:
    •2D games
    •Anything with lots of 2D
    animation
    •Simple OpenGL

    View Slide

  31. Cocos is not so great for:
    •Interfaces
    •Text-heavy apps
    •Apps that should follow the
    iOS HIG

    View Slide

  32. The Game

    View Slide

  33. View Slide

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

    View Slide

  35. A word on art!

    View Slide

  36. View Slide

  37. View Slide

  38. Slicy

    View Slide

  39. View Slide

  40. View Slide

  41. Getting Started

    View Slide

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

    View Slide

  43. The Director

    View Slide

  44. Director

    View Slide

  45. Director
    Main Menu

    View Slide

  46. Director
    Main Menu Game

    View Slide

  47. Director
    Main Menu Game

    View Slide

  48. Director
    Main Menu Game

    View Slide

  49. Nodes

    View Slide

  50. Director
    Scene

    View Slide

  51. Director
    Scene
    Node Node Node

    View Slide

  52. Director
    Scene
    Node Node Node

    View Slide

  53. Director
    Scene
    Node Node Node
    Node Node
    Node Node

    View Slide

  54. Actions

    View Slide

  55. Actions modify nodes

    View Slide

  56. View Slide

  57. Move

    View Slide

  58. Rotate

    View Slide

  59. Move+Rotate

    View Slide

  60. { code }

    View Slide

  61. View Slide

  62. Move Wait Run Code

    View Slide

  63. Scheduling

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  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:)

    View Slide

  68. -(void) update:(ccTime)deltaTime {
    // Run code every frame in this function
    }

    View Slide

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

    View Slide

  70. Collision Detection

    View Slide

  71. View Slide

  72. ?

    View Slide

  73. View Slide

  74. Rock

    View Slide

  75. Player
    Rock

    View Slide

  76. Player
    Rock

    View Slide

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

    View Slide

  78. Taking it further

    View Slide

  79. Further Reading

    View Slide

  80. View Slide

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

    View Slide

  82. Thanks!

    View Slide

  83. @thesecretlab

    View Slide

  84. View Slide