Cocos2d game programming 2

Click here to load reader

  • date post

  • Category


  • view

  • download


Embed Size (px)


Texas A&M University의 Android Programming Class의 Guest Talk 자료입니다.

Transcript of Cocos2d game programming 2

  • 1.Cocos2D

2. Cocos2d Open Source 2D Game Framework Built upon the OpenGL APIs 2D Game, Graphic, InteractiveApplication Programs Sep. 2008 - 0.3.0 version released Used in thousands of apps Active developer community 3. Cocos2d Multi-platform game engine iOS, Mac OS X, Android ported Cocos2d-x multi-platform port written inC++ 4. iOS game engines(non-commercial) Sparrow Cocos2d(open source)(open source)oolong engine Galaxy(MIT License) (New BSD License) 5. iOS game engines(commercial)UnrealGame saladDev KitUnity SIO2 And much more... 6. iOS game engines 7. Cocos2d gamesTap Pet Hotel: #1 Free Zombie Farm: #6 FreeTap Zoo: #2 FreeiStunt 2: #6 Free 8. Cocos2d gamesAir Penguin: #1 PaidZombieSmash: #1 PaidFishing Frenzy: #7 Paid Trainyard: #2 Paid 9. Cocos2d for Mac App 10. Cocos2d vs OpenGL You can make a high level game using openGL You will need an animation of sprits, menusfor the game, actions for game objects, soundeffects, and much more... Cocos2d supports a wrapper class ofOpenGL Also sound control class, menu class, sprites... 11. Cocos2d 12. Installation for iOS 13. Installation for iOS 14. Installation(super easy) 15. Cocos2d for Android 16. Sample ProgramMany featured sample codes are provided 17. Cocos2D PackageTutorial codes for beginners-easy tostart 18. Tutorial 19. DemoCocos2D for iPhone 20. and More 21. Features Scene Graph Structure Flow Control(Scene Management) Flow Control between Scenes Sprites and Sprite Sheets Easy and powerful way of Sprite Usage Action Supports many actions including move, rotate,scale, sequence, spawn,... 22. Features Effect Various 2D effect including wave, twirl,lens, liquid, ripple Tiled Maps, Transition, Menus, TextRendering Physics Engine : Chipmunk, Box2d, ParticleSystem 23. Features Basic Menu and Button Parallax scrolling Sound Controls, Particle System High Score server(Cocos live) Based on OpenGL ES 1.1 - for iOS Based on OpenGL 1.5 - for Mac 24. Scene Graph Hierarchy of every Cocos2d NODE thatscurrently active. Every node has exactly one parent node,except the scene itself, and can have anynumber of child nodes. General technique on high level graphicssystem or game programming 25. Scene Graph CCScene CCLayerCCLayer CCLayerCCSprite CCMenu CCSprite 26. Scene Graph Structure General data structure used in Vectorbased graphics editing application or games. Acrobat 3D, Java 3D, AutoCAD,VRML,Open Inventor,.. Collection of nodes in a graph or treestructure 27. Object class in Java The Object class is the super class for allclasses in Java Denes the basic states and behavior thatall objects must have equals, getClass, toString, ... 28. CCNode in Cocos2d The CCNode class is the super class of allCocos2d class Denes common attributes and methodsthat all Cocos2d object must have 29. CCNode Class Most important Cocos2D class, mostobject in Cocos2d inherits from CCNode CCScene, CCLayer, CCSprite, CCMenuclasses are children of CCNode class Can include another CCNode object. Can schedule periodic callbacks Can run all actions 30. CCNode Class Attributes rotation, scaleX_, scaleY_,position,visible_, anchorPointInPixels_,anchorPoint_, isRelativeAnchorPoint_,contentSize_, transform_, inverse_,vertexZ_, camera_, grid, zOrder_,children_ 31. CCNode: Attributes If you want to draw amonster in your game anchorPointscene You will need animage( CCSprite ) rotation And its position, size,rotation angle, anchorpoint, ... ion sit po 32. CCDirector Class Cocos2D Class has name space startingwith CCxxx. Director(CCDirector) Management object for game controlthru scene OpenGL ES environment setting Running the game loop 33. CCScene Class Scene A game is composed of multiple screens Each scene compose each screen ongame Scene is composed of multiplelayers(hierarchical structure) 34. Scene & DirectorCCDirector ..CCScene CCScene .. CCScene 35. CCScene ClassCCSceneCCLayerCCLayer (game layer) (touch handling layer) 36. CCLayer Class One Game scene can contain many layers and each layer contains more than onesprite or menu Capture user interaction or accelerometer Layer consists a scene 37. CCLayerCCLayerScore: 210 LIFE : 3..CCSprite CCLabel .. CCNode CCSprite CCSprite .. 38. CCLayerCCLayerScore: 210 LIFE : 3..CCSprite CCLabel .. CCNode CCSprite CCSprite .. 39. CCLayer CCLayer can handle events isTouchEnabled_ isAccelerometerEnabled_ Game controller Manage game entities 40. Sprite Object Image les are loaded into OpenGL ESTextures in a format that the GPU canunderstand Sprites can move within a scene or a layer Sprites may be animated, by cycling througha number of different images 41. CCSprite SpritesTexture-Sprite Sheet 42. Action Control the movement, transition, andeffects of Cocos2d objects. All CCNode objects are able to runactions. CCAnimate, CCJumpBy, CCRepeatForever,CCSequence, CCSpawn, CCMoveTo,CCFadeTo,... 43. CCNode: Actions Modify nodes attributes by time position/rotation/scale/opacity/grid/... Interval actions and Instant actions 44. Running an Action high level action description 45. Tools - TexturePacker Loading a sprite requires much systemresources In a game scene many sprites are required each sprite contains many animationimages packaging each image into a big spritesheet 46. Sprite ImagesMB_01.png MB_02.png MB_03.png MB_03.png... 47. Making a big Sprite Sheet 48. Meta data 49. in your code Sprite Sheet leSprite le 50. Tools-Font Generator Many game developers want in-housebitmap font Game scene needs an special font effectand customized fonts 51. Font Generator 52. in your codefont le (testFont.png)import meta-data(testFont.fnt) 53. Sound Editor Sound Effect is very important in a game 54. Map Editor 55. Particle Editor 56. More game tools 57. Game Tools Many 3rd party game tools for Cocos2dare available Enrich your game effect Minimize your programming efforts More efcient way of memorymanagement 58. Cocos2d for Android 59. Download Unzip downloaded le ZhouWeikuan-cocos2d-1d79d40 folder will be generated. 60. Android Code 61. iOS code 62. Android 63. Android code 64. iOS 65. iOS code 66. Demo 67. Q &A