[TUTORIAL] Getting Started with AndEngine

  ... tutorials on how to use AndEngine.

[TUTORIAL] Getting Started with AndEngine

Postby RealMayo » Tue Sep 06, 2011 7:20 am

:flag_red: MULTIMEDIA


:flag_red: ALTERNATIVE INSTALLATION OPTIONS
    Start by deleting everything that currently exists in your Eclipse.
    Now download everything from my own personal github...
    https://github.com/RealMayo?tab=repositories
    Once you've downloaded everything from there into your Eclipse, then right click on each one in Eclipse, choose Properties, then set the Compiler to 1.6. Also while you are in Properties, go to Android, then scroll down and see the Library section. Take note of what extension is in that Library section, remove it, then add it back in again.
    Once you've done that for all extensions in Eclipse, you should be good to go and the examples should work.


:flag_red: TIPS AND TRICKS
    Tips for when you are ready to publish your game in the Google Play Store:
    http://www.andengine.org/forums/project-development-blogs/tips-for-new-games-t8741.html
    More tips on how to provide tech support for your game:
    http://www.andengine.org/forums/project-development-blogs/tech-support-for-your-game-t12881.html

    :information: Eclipse Emulator settings
    For those people who may be having trouble getting the emulator to work with AndEngine GLES2, its probably because your PC has an ancient graphics card that can't handle GLES2! Check and make sure that your PC graphics card supports GLES2 graphics.

    FYI the settings below work great with the emulator...

    Here's my AVD setup:
    Target = API 15
    CPU = Intel Atom
    Skin Builtin = WVGA800
    Abstracted LCD Density = 240
    Max VM Application Heap Size = 48
    Device RAM Size = 512
    GPU Emulation = yes

    Here's the important part of the AndroidMainfest.xml:
    <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" />
    <uses-feature android:glEsVersion="0x00020000" android:required="true"/>


:flag_red: BaseGameActivity VERSUS SimpleBaseGameActivity
    If you are upgrading from GLES1 to GLES2 then you might want to use SimpleBaseGameActivity instead of BaseGameActivity if you want a similar experience in your code.

    Once you're ready to explore more, you can try BaseGameActivity in GLES2. What is unique about this is that it has "callbacks" which are designed to give you more control of the flow of how your game loads. One method will not move to the next method until the callback is called. This means that you can more precisely preload resources and establish your scene, then only display your scene once its truly ready to go.

    If you don't call the Callbacks then you might just see a black screen when you launch your game.

    See here for an example of BaseGameActivity in GLES2 (note the required CALLBACKS)...


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.mycompany.mygame;
  2.  
  3. import org.andengine.engine.camera.Camera;
  4. import org.andengine.engine.options.EngineOptions;
  5. import org.andengine.engine.options.EngineOptions.ScreenOrientation;
  6. import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
  7. import org.andengine.entity.scene.Scene;
  8. import org.andengine.ui.IGameInterface.OnCreateResourcesCallback;
  9. import org.andengine.ui.IGameInterface.OnCreateSceneCallback;
  10. import org.andengine.ui.IGameInterface.OnPopulateSceneCallback;
  11. import org.andengine.ui.activity.BaseGameActivity;
  12.  
  13. public class myGame extends BaseGameActivity {
  14.        
  15.         final int mCameraWidth = 800;  
  16.         final int mCameraHeight = 480;
  17.         public Scene mScene;
  18.  
  19.                
  20.                 @Override
  21.                 public EngineOptions onCreateEngineOptions() {
  22.                         Camera mCamera = new Camera(0, 0, mCameraWidth, mCameraHeight);
  23.                         final EngineOptions engineOptions = new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(mCameraWidth, mCameraHeight), mCamera);
  24.                         return engineOptions;
  25.                 }
  26.                
  27.                 @Override
  28.                 public void onCreateResources(OnCreateResourcesCallback pOnCreateResourcesCallback)     throws Exception {
  29.  
  30.                         pOnCreateResourcesCallback.onCreateResourcesFinished();
  31.                 }
  32.                
  33.                 @Override
  34.                 public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback) throws Exception {
  35.                         mScene = new Scene();
  36.  
  37.                         pOnCreateSceneCallback.onCreateSceneFinished(mScene);
  38.                 }
  39.                
  40.                 @Override
  41.                 public void onPopulateScene(Scene pScene, OnPopulateSceneCallback pOnPopulateSceneCallback)     throws Exception {
  42.  
  43.                         pOnPopulateSceneCallback.onPopulateSceneFinished();
  44.                 }
  45.                
  46. }
  47.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
Last edited by RealMayo on Fri Sep 14, 2012 8:38 pm, edited 20 times in total.
User avatar
RealMayo
 
Posts: 1683
Joined: Sat Sep 03, 2011 9:25 pm
Location: Chicago, IL

Re: [TUTORIAL] UPDATED - Getting Started with AndEngine

Postby yordan » Sun Sep 11, 2011 12:19 am

perfect. It's what I was looking for. thank you very much!
yordan
 
Posts: 23
Joined: Fri Sep 09, 2011 4:49 pm

Re: [TUTORIAL] UPDATED - Getting Started with AndEngine

Postby Nicolas Gramlich » Sun Sep 11, 2011 6:08 pm

Very nice, the only thing I didn't understand was why you didn't keep the extensions as library projects but manually linked the source folders.
Nicolas Gramlich
Site Admin
 
Posts: 1734
Joined: Mon Jun 07, 2010 6:20 pm
Location: Schriesheim, Germany

Re: [TUTORIAL] UPDATED - Getting Started with AndEngine

Postby RealMayo » Mon Sep 12, 2011 4:26 pm

Thanks guys!
The reason I didn't keep the extensions as library projects was two fold:
1) I was experiencing errors when trying to run the AndEngine Examples. I probably overlooked some very simple fix, but in the end this method is what worked for me.
2) The method I used (I feel) is more straightforward when the user creates a brand new project for themselves.

Nevertheless, I'm always open to constructive feedback. Although I doubt I'll want to go through the pain of re-recording any of those videos ;)

Anyway, do you think we might want to "sticky" this thread?
Thanks
User avatar
RealMayo
 
Posts: 1683
Joined: Sat Sep 03, 2011 9:25 pm
Location: Chicago, IL

Re: [TUTORIAL] UPDATED - Getting Started with AndEngine

Postby Dan » Tue Sep 13, 2011 2:35 pm

Very nice vids.

Hum... Adding as link source actually did not work for me, It outputs a bunch of errors, it turns out that I had my project configured for 1.5, changing it to 1.6 fixed the issue, just thought of mentioning it in case anyone has the same issue.

Also it would be cool if you listed all the URLs for hte extensions in the vids or the forum.
Dan
 
Posts: 10
Joined: Thu Jun 02, 2011 9:08 pm

Re: [TUTORIAL] UPDATED - Getting Started with AndEngine

Postby Dan » Tue Sep 13, 2011 3:47 pm

@Nicolas: Why isn't the lib .so file added to the project? Or at least some instructions to compile it. It takes hours just to set this up :roll:

Also there is allot of broken shit, like the snake game that throws a buffer overflow, and a bunch of the other examples that crash.

For some fucking reason most demos wont run on the device, but it will run on the emulator. Anyway a lot of warnings and the resource management also is funky.

But there is a bunch of broken stuff:

09-13 16:56:54.253: INFO/ActivityManager(58): Starting activity: Intent { cmp=org.anddev.andengine.examples/.game.snake.SnakeGameActivity }
09-13 16:56:54.304: INFO/WindowManager(58): Setting rotation to 1, animFlags=1
09-13 16:56:54.304: INFO/ActivityManager(58): Config changed: { scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/2 nav=3/1 orien=2 layout=34 uiMode=17 seq=8}
09-13 16:56:54.393: INFO/ActivityManager(58): Displayed activity org.anddev.andengine.examples/.game.snake.SnakeGameActivity: 119 ms (total 119 ms)
09-13 16:56:54.433: INFO/dalvikvm(276): threadid=1: stack overflow on call to Lorg/anddev/andengine/ui/activity/BaseGameActivity;.getFontManager:L
09-13 16:56:54.433: INFO/dalvikvm(276): method requires 8+20+4=32 bytes, fp is 0x41869318 (24 left)
09-13 16:56:54.433: INFO/dalvikvm(276): expanding stack end (0x41869300 to 0x41869000)
09-13 16:56:54.433: INFO/dalvikvm(276): Shrank stack (to 0x41869300, curFrame is 0x4186beb8)
09-13 16:56:54.433: DEBUG/AndroidRuntime(276): Shutting down VM
09-13 16:56:54.433: WARN/dalvikvm(276): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
09-13 16:56:54.803: DEBUG/dalvikvm(276): GC_FOR_MALLOC freed 6416 objects / 684032 bytes in 81ms
09-13 16:56:54.813: ERROR/AndroidRuntime(276): FATAL EXCEPTION: main
09-13 16:56:54.813: ERROR/AndroidRuntime(276): java.lang.StackOverflowError
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(BaseGameActivity.java:137)
09-13 16:56:54.813: ERROR/AndroidRuntime(276): at org.anddev.andengine.ui.activity.BaseGameActivity.getFontManager(Bas
09-13 16:56:54.944: DEBUG/dalvikvm(276): GC_FOR_MALLOC freed 3946 objects / 861240 bytes in 80ms
09-13 16:56:54.973: WARN/ActivityManager(58): Force finishing activity org.anddev.andengine.examples/.game.snake.SnakeGameActivity
09-13 16:56:54.973: INFO/WindowManager(58): Setting rotation to 0, animFlags=1
09-13 16:56:55.073: DEBUG/dalvikvm(58): GC_FOR_MALLOC freed 7573 objects / 339136 bytes in 93ms
09-13 16:56:55.163: INFO/ActivityManager(58): Config changed: { scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/2 nav=3/1 orien=1 layout=34 uiMode=17 seq=9}
09-13 16:56:55.584: WARN/ActivityManager(58): Activity pause timeout for HistoryRecord{450fc4e8 org.anddev.andengine.examples/.game.snake.SnakeGameActivity}
09-13 16:56:57.702: DEBUG/dalvikvm(58): GC_EXPLICIT freed 1115 objects / 175216 bytes in 106ms
09-13 16:56:58.032: INFO/Process(276): Sending signal. PID: 276 SIG: 9
09-13 16:56:58.052: INFO/ActivityManager(58): Process org.anddev.andengine.examples (pid 276) has died.
09-13 16:56:58.052: INFO/WindowManager(58): WIN DEATH: Window{450c0d48 org.anddev.andengine.examples/org.anddev.andengine.examples.launcher.ExampleLauncher paused=false}
09-13 16:56:58.063: INFO/WindowManager(58): WIN DEATH: Window{4501cdd8 org.anddev.andengine.examples/org.anddev.andengine.examples.game.snake.SnakeGameActivity paused=false}
09-13 16:56:58.074: INFO/UsageStats(58): Unexpected resume of com.android.launcher while already resumed in org.anddev.andengine.examples
09-13 16:56:58.132: WARN/InputManagerService(58): Got RemoteException sending setActive(false) notification to pid 276 uid 10038
Last edited by Dan on Tue Sep 13, 2011 6:58 pm, edited 2 times in total.
Dan
 
Posts: 10
Joined: Thu Jun 02, 2011 9:08 pm

Re: [TUTORIAL] UPDATED - Getting Started with AndEngine

Postby marinat » Tue Sep 13, 2011 4:37 pm

Thnx a lot ! You are great man! :D
marinat
 
Posts: 34
Joined: Wed Aug 03, 2011 10:17 am

Re: [TUTORIAL] UPDATED - Getting Started with AndEngine

Postby eatjason » Wed Sep 14, 2011 1:44 am

I'm having a problem following this tutorial. I did everything up to 5:30, but I still have red errors on my project, I looked though and it appears some object definitions are not being found.

Camera, BitmapTextureAtlas, TextureRegion, etc, showing "Could not be resolved to a type"

I have android sdk installed properly, I already ran hello world examples from the android site running on my device.

I'm using revision 317.

Also apparently I already had a res folder, which was different from the tutorial. It already had stuff in it as well. I tried to see if maybe it was added recently to the repository, but doesn't look like that is the case. I tried to go a bit farther, the PhysicsBox2DExtention needed the res folder, just not the AndEngineExamples.
eatjason
 
Posts: 2
Joined: Wed Sep 14, 2011 12:30 am

Re: [TUTORIAL] UPDATED - Getting Started with AndEngine

Postby eatjason » Wed Sep 14, 2011 1:59 am

Oops, I was copying urls from the main andengine site, was mistaking andengineexamples for the engine itself. scratch that.
eatjason
 
Posts: 2
Joined: Wed Sep 14, 2011 12:30 am

Re: [TUTORIAL] UPDATED - Getting Started with AndEngine

Postby DeaCon » Thu Sep 15, 2011 10:35 pm

Thank you very much Mayo.

After concluding I detest working with raw OpenGL (At least ES 2.0) I decided to try and use AndEngine for my current live wallpaper project, and your videos made the initial setup a breeze. If only everything in life had such tutorials. :lol: If you decide to create more tutorials like this, I will definitely be looking forward to watching them.
DeaCon
 
Posts: 24
Joined: Thu Sep 15, 2011 10:29 pm

Next

Return to Tutorials

Who is online

Users browsing this forum: M26 and 27 guests