Developing Android Games

download Developing Android Games

of 21

Transcript of Developing Android Games

  • 7/29/2019 Developing Android Games

    1/21

    AN INTRODUCTION TO

    DEVELOPING ANDROID

    GAMES USING COCOS2DENGINE.

    By Dibia Victor | Africa Android Challenge

  • 7/29/2019 Developing Android Games

    2/21

    Presentation Outline

    What are gaming engines ?

    Cocos2D Origins

    Cocos2D for Android

    Developing Games using Cocos2D Android

    Cocos2D Android Test Environment Setup (Windows)

    Setting up a Sample Game (Puzzlemania)

    Puzzlemania Components

    Conclusion

  • 7/29/2019 Developing Android Games

    3/21

    What are Gaming Engines ?

    Gaming engines are software frameworks whichprovide/simplify repeated used features in gamessuch as transitions, animations, sound, physics, flow

    control, text rendering, surface rendering etc. Whenwe set out to create games, we want to focus more onthe game logic, game experience and storyline rather than dwelling on how to animate the tile acrossthe screen.Examples of gaming engines include Adventure GameStudio (C++), Agate lib (.NET), Allegro (C), Cocos2D(Python) etc

  • 7/29/2019 Developing Android Games

    4/21

    Cocos 2D Origins

    Cocos2d is an open source framework for building 2D games,

    demos, and other graphical/interactive applications.

    Originally developed using python, some of its main features

    include :

    Flow control: Manage the flow control between different

    scenes in an easy way

    Sprites: Fast and easy sprites

    Actions: Just tell sprites what you want them to do.

    Composable actions like move, rotate, scale and much moreEffects: Effects like waves, twirl, lens and much more

    Other features include Tiled Maps, Transitions, Menus ,Text

    Rendering , OpenGL based and aBuilt-in Python Interpreter

  • 7/29/2019 Developing Android Games

    5/21

    Cocos 2D Origins (Contd)

    Due to its success and easy of use, several versions (ports) of

    Cocos2D on different platforms have emerged over the years.

    A very famous portCocos2d-iphone written in objective C

    (targeting the iOS and MAC platforms) has been used in

    authoring a wide range of top ranking games sold on the

    Apple Appstore. Other ports include Cocos2D Android written

    in Java for the Android platform , and Cocos2D Javascript that

    uses the HTML5 canvas API. Each of these ports maintain the

    original Cocos2D design concepts and structure.

  • 7/29/2019 Developing Android Games

    6/21

    Cocos 2D For Android

    Cocos 2D for android is a port of the Cocos2D-iphone

    essentially written in Java. Cocos2D for android project is

    still a budding open source community (November 2010)

    and aims to port latest cocos2d-iphone code, to theandroid platform. Main features include : Flow control,

    Sprites, Maps, Transitions, Menus, Text Rendering, BSD

    License, OpenGL Based: Hardware Acceleration

    The most current version of Cocos2D for android project ismanaged by ZhouWeikuan and found at [1]

  • 7/29/2019 Developing Android Games

    7/21

    Developing Games using Cocos2D

    Android

    In order to start creating cool games using the

    Cocos2D gaming engine, you need to download the

    .jar library (cocos2d-android.jar) and compile your

    android project using it as a referenced library. The next section provides steps on setting up a test

    environment and developing a simple game.

  • 7/29/2019 Developing Android Games

    8/21

    Cocos2D Android Test Environment

    Setup (Windows)

    1.) Download the cocos2d-android library.The cocos2D android project is managed here(http://code.google.com/p/cocos2d-android-1/) and the sourcecode as well as cocos2d-android.jar can be downloaded at thefollowing github account (https://github.com/ZhouWeikuan/cocos2d)

    via the downloads button. 2.) Download Eclipse IDE for Java Developers

    (http://www.eclipse.org/downloads/)Extract the downloaded zip file and run eclipse.exe to launch theIDE. No installations required.3.)Install Android SDK for Windows.

    Download and extract the android sdk here(http://dl.google.com/android/android-sdk_r12-windows.zip)For easy access, the preferred extraction location is C:/android-sdk-windows.

    http://code.google.com/p/cocos2d-android-1/https://github.com/ZhouWeikuan/cocos2dhttp://www.eclipse.org/downloads/http://www.eclipse.org/downloads/https://github.com/ZhouWeikuan/cocos2dhttp://code.google.com/p/cocos2d-android-1/http://code.google.com/p/cocos2d-android-1/http://code.google.com/p/cocos2d-android-1/http://code.google.com/p/cocos2d-android-1/http://code.google.com/p/cocos2d-android-1/
  • 7/29/2019 Developing Android Games

    9/21

    Cocos2D Android Test Environment

    Setup (Windows)

    4.) Install the Android Development Tools (ADT) Pluginfor Eclipse.Android offers a custom plugin for the Eclipse IDE,called Android Development Tools (ADT), that is

    designed to provide a powerful, integratedenvironment in which to build Android applications.

    ADT plugin for Eclipse can be installed using the followingsteps.Start Eclipse, then select Help > Install New

    Software....Click Add, in the top-right corner. In theAdd Repository dialog that appears, enter "ADT Plugin"for the Name and the following URL for the Location:

    https://dl-ssl.google.com/android/eclipse/ClickOK and proceed to finish and restart Eclipse.

  • 7/29/2019 Developing Android Games

    10/21

    Cocos2D Android Test Environment

    Setup (Windows)

    5.) Configure the ADT Plugin [2]The next step is to modify your ADT preferences inEclipse to point to the Android SDK directory:Select Window > Preferences... to open the Preferences

    panel .Select Android from the left panel. You may seea dialog asking whether you want to send usagestatistics to Google. If so, make your choice and clickProceed.

    For the SDK Location in the main panel, click Browse... and

    locate your downloaded SDK directory (C:/android-sdk-windows if you used the recommended path in step 2above). Click Apply, then OK. Done!. Now, you shouldbe able to create and manage android projects in theeclipse IDE.

  • 7/29/2019 Developing Android Games

    11/21

    Cocos2D Android Test Environment

    Setup (Windows)

    6.) Setting up an Android Virtual Device (AVD) for testing.An AVD is an emulated version of a mobile device runningthe android operating system and is used to test androidapplications.

    In Eclipse, choose Window > Android SDK and AVDManager.Select Virtual Devices in the left panel.ClickNew.The Create New AVD dialog appears.Type the nameof the AVD, such as "my_avd".Choose a target. The target isthe platform (that is, the version of the Android SDK, such as

    2.1) you want to run on the emulator. It is recommended touse Android 2.1 and above for cocos2d development.Detailed information on testing android applications usingan actual android device such as an android tablet pc ormobile phone can be found here [3]

  • 7/29/2019 Developing Android Games

    12/21

    Cocos2D Android Test Environment

    Setup (Windows)

    7a.) Setting Up a Sample Cocos2D Project

    From Eclipse, select File > New > Project.

    If the ADT Plugin for Eclipse has been successfully

    installed, the resulting dialog should have a folderlabeled "Android" which should contain "Android

    Project". If you dont see the Android folder, follow

    step 6 above again to install the ADT Pluging (After

    you create one or more Android projects, an entryfor "Android XML File" will also be available.)

  • 7/29/2019 Developing Android Games

    13/21

    Cocos2D Android Test Environment

    Setup (Windows)

    7b.) Select "Android Project" and click Next. Fill in the

    project details and Click Finish.

    The Next Steps are to add the cocos2D android

    library (cocos2d-android.jar) to your project inorder to access its functionalities. The cocos2d-

    android.jar file can be found in the libs folder of

    the cocos2d source file downloaded in step 1

    above.

  • 7/29/2019 Developing Android Games

    14/21

    Cocos2D Android Test Environment

    Setup (Windows)

    7c.) Right Click the HelloCocos2D Project > New >

    Folder

    In the New Folder Dialog name the folder libs.

    Copy the cocos2d-android.jar file and paste it inthe libs folder

    Right Click on the HelloCocos2D Project >

    Properties > Java Build PathClick Add

    JARsNavigate to the HelloCocos2D project > LibsSelect cocos2d-android.jar.Complete! You can now

    use cocos2D functions in your android code.

  • 7/29/2019 Developing Android Games

    15/21

    Cocos2D Android Test Environment

    Setup (Windows)

    8.) Importing a Cocos2D Android Project in Eclipse

    From the main menu bar, select File > Import....

    The Import wizard opens. Select General > Existing

    Project into Workspace and click Next.Choose either Select root directory or Select archive

    file and click the associated Browse to locate the

    directory or file containing the projects.Under Projects select the project or projects which you

    would like to import.

    Click Finish to start the import.

  • 7/29/2019 Developing Android Games

    16/21

    Cocos2D Android Test Environment

    Setup (Windows)

    9.) Running a Cocos2D Android Project in Eclipse

    Now that you have either set up a cocos2D project

    or imported an existing project the next simple step

    is to run your project.Right Click on project in package Explorer

    Run As > Android Application

  • 7/29/2019 Developing Android Games

    17/21

    Setting up a Sample Game

    (Puzzlemania)

    Puzzlemania is an implementation of a simple number slidingblock puzzle. A canvas of tiles labeled with numbers from 19 is presented to the user in random order. The users taskis to arrange the numbers in there ascending order from leftto right by sliding each tile. The users score is judged based

    on the amount of time used to solve the puzzle and thenumber of moves used to solve the puzzle.

    Project files for this sample can be downloaded from

    http://www.vidicorp.org/labs/puzzle.zip and imported as an

    android project using step 8 above. The project files arecommented and explanatory.

    http://www.vidicorp.org/labs/puzzle.ziphttp://www.vidicorp.org/labs/puzzle.zip
  • 7/29/2019 Developing Android Games

    18/21

    Puzzlemania Screenshot

  • 7/29/2019 Developing Android Games

    19/21

    Puzzlemania Components

    Puzzle.javaMain logic that controls game play,timing, tile animation and difficulty selection

    Utility.javaGenerates puzzle number sequence suchthat the puzzle is ALWAYS solvable

    CCNodeExt.javaA special node object used to modeleach tile.

    A possible extension of puzzlemania would be to

    develop an image slider puzzle in contrast to thecurrent number slider puzzle.

  • 7/29/2019 Developing Android Games

    20/21

    Conclusion

    Cocos2D is a powerful game engine as evidenced by

    notable games on the iphone platform [4] . A great

    way to proceed in getting familiarized with the

    Cocos2D engine and game development is to attemptto develop mobile versions of simple games we

    played as children (Ludo, snakes and ladders and

    other local games).

  • 7/29/2019 Developing Android Games

    21/21

    References

    1. Cocos2d for Android Github Projecthttps://github.com/ZhouWeikuan/cocos2d RetrievedMarch 1, 2012

    2. Installing the Android Developer Tools (ADT) Plugin

    http://developer.android.com/sdk/eclipse-adt.html#installing. Retrieved March 2, 2012

    3. Using Hardware Deviceshttp://developer.android.com/guide/developing/device.html. Retrieved March 3, 2012

    4. Games Using the Cocos2D for iPhonehttp://code.google.com/p/cocos2d-iphone/wiki/GamesUsingCocos2d . Retrieved March1, 2012

    https://github.com/ZhouWeikuan/cocos2dhttp://developer.android.com/sdk/eclipse-adt.htmlhttp://developer.android.com/sdk/eclipse-adt.htmlhttp://developer.android.com/guide/developing/device.htmlhttp://developer.android.com/guide/developing/device.htmlhttp://code.google.com/p/cocos2d-iphone/wiki/GamesUsingCocos2dhttp://code.google.com/p/cocos2d-iphone/wiki/GamesUsingCocos2dhttp://code.google.com/p/cocos2d-iphone/wiki/GamesUsingCocos2dhttp://code.google.com/p/cocos2d-iphone/wiki/GamesUsingCocos2dhttp://code.google.com/p/cocos2d-iphone/wiki/GamesUsingCocos2dhttp://code.google.com/p/cocos2d-iphone/wiki/GamesUsingCocos2dhttp://developer.android.com/guide/developing/device.htmlhttp://developer.android.com/guide/developing/device.htmlhttp://developer.android.com/sdk/eclipse-adt.htmlhttp://developer.android.com/sdk/eclipse-adt.htmlhttp://developer.android.com/sdk/eclipse-adt.htmlhttp://developer.android.com/sdk/eclipse-adt.htmlhttps://github.com/ZhouWeikuan/cocos2dhttps://github.com/ZhouWeikuan/cocos2d