AndEngine TUTORIALS - [ 71 Articles! ]

  ... tutorials on how to use AndEngine.

Re: AndEngine TUTORIALS - [ 71 Articles! ]

Postby Mathew » Sat Apr 13, 2013 5:10 pm

New physics related series has been started - joints articles.
User avatar
Mathew
 
Posts: 1073
Joined: Sun Jul 31, 2011 2:49 pm
Location: Tarnów, Poland

Re: AndEngine TUTORIALS - [ 71 Articles! ]

Postby Mathew » Sun Apr 21, 2013 5:00 pm

3 new articles published.
User avatar
Mathew
 
Posts: 1073
Joined: Sun Jul 31, 2011 2:49 pm
Location: Tarnów, Poland

Re: AndEngine TUTORIALS - [ 71 Articles! ]

Postby Mathew » Thu May 23, 2013 9:38 pm

up
User avatar
Mathew
 
Posts: 1073
Joined: Sun Jul 31, 2011 2:49 pm
Location: Tarnów, Poland

Re: AndEngine TUTORIALS - [ 71 Articles! ]

Postby Mathew » Sun Jun 30, 2013 6:58 pm

up
User avatar
Mathew
 
Posts: 1073
Joined: Sun Jul 31, 2011 2:49 pm
Location: Tarnów, Poland

Re: AndEngine TUTORIALS - [ 71 Articles! ]

Postby RealMayo » Sun Jun 30, 2013 8:25 pm

By the way dude, I have this thread permanently linked to in the first post of my sticky thread.
User avatar
RealMayo
 
Posts: 1694
Joined: Sat Sep 03, 2011 9:25 pm
Location: Chicago, IL

Re: AndEngine TUTORIALS - [ 71 Articles! ]

Postby bukibit999 » Mon Jul 01, 2013 1:01 pm

could you write a tutorial on how to make a side scrolling game?
bukibit999
 
Posts: 4
Joined: Mon Jul 01, 2013 11:08 am

Re: AndEngine TUTORIALS - [ 71 Articles! ]

Postby RealMayo » Mon Jul 01, 2013 4:06 pm

bukibit999 wrote:could you write a tutorial on how to make a side scrolling game?

Just search the forum for "chase"
User avatar
RealMayo
 
Posts: 1694
Joined: Sat Sep 03, 2011 9:25 pm
Location: Chicago, IL

Re: AndEngine TUTORIALS - [ 71 Articles! ]

Postby Mathew » Mon Jul 01, 2013 5:57 pm

RealMayo wrote:By the way dude, I have this thread permanently linked to in the first post of my sticky thread.


Oh right, I just always see big difference in blog views, when thread is on the top : )
User avatar
Mathew
 
Posts: 1073
Joined: Sun Jul 31, 2011 2:49 pm
Location: Tarnów, Poland

Re: AndEngine TUTORIALS - [ 71 Articles! ]

Postby RealMayo » Mon Jul 01, 2013 6:10 pm

LOL ok then keep bumping it up, I don't care :lol:
User avatar
RealMayo
 
Posts: 1694
Joined: Sat Sep 03, 2011 9:25 pm
Location: Chicago, IL

Re: AndEngine TUTORIALS - [ 71 Articles! ]

Postby markos2xx » Tue Jul 23, 2013 11:41 am

I'm working with these tutorials. I have a problem with switching beetwen scenes from menu. I created 5 menu items, only first one works. When i click second one i get an error: "application has been stopped".

SceneManagaer.java
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.example.matchcolors;
  2.  
  3. import org.andengine.engine.Engine;
  4. import org.andengine.engine.handler.timer.ITimerCallback;
  5. import org.andengine.engine.handler.timer.TimerHandler;
  6. import org.andengine.ui.IGameInterface.OnCreateSceneCallback;
  7. import com.example.matchcolors.MainMenuScene;
  8. import com.example.matchcolors.BestScoresScene;
  9.  
  10. public class SceneManager
  11. {
  12.    
  13.     private BaseScene splashScene;
  14.     private BaseScene menuScene;
  15.     private BaseScene worldScene;
  16.     private BaseScene levelScene;
  17.     private BaseScene bestScoresScene;
  18.     private BaseScene seetingsScene;
  19.     private BaseScene aboutScene;
  20.     private BaseScene exitScene;
  21.     private BaseScene gameScene;
  22.     private BaseScene loadingScene;
  23.    
  24.    
  25.     private static final SceneManager INSTANCE = new SceneManager();
  26.    
  27.     private SceneType currentSceneType = SceneType.SCENE_SPLASH;
  28.    
  29.     private BaseScene currentScene;
  30.    
  31.     private Engine engine = ResourcesManager.getInstance().engine;
  32.    
  33.     public enum SceneType
  34.     {
  35.         SCENE_SPLASH,
  36.         SCENE_MENU,
  37.         SCENE_WORLD,
  38.         SCENE_LEVEL,
  39.         SCENE_GAME,
  40.         SCENE_LOADING,
  41.         SCENE_BESTSCORES,
  42.         SCENE_SEETINGS,
  43.         SCENE_ABOUT,
  44.         SCENE_EXIT
  45.     }
  46.    
  47.    
  48.     public void setScene(BaseScene scene)
  49.     {
  50.         engine.setScene(scene);
  51.         currentScene = scene;
  52.         //currentSceneType = scene.getSceneType();
  53.     }
  54.    
  55.    
  56.     // ustawia scene
  57.     public void setScene(SceneType sceneType)
  58.     {
  59.         switch (sceneType)
  60.         {
  61.             case SCENE_MENU:
  62.                 setScene(menuScene);
  63.                 break;
  64.             case SCENE_GAME:
  65.                 setScene(gameScene);
  66.                 break;
  67.             case SCENE_WORLD:
  68.                 setScene(worldScene);
  69.                 break;
  70.             case SCENE_LEVEL:
  71.                 setScene(levelScene);
  72.                 break;    
  73.             case SCENE_SPLASH:
  74.                 setScene(splashScene);
  75.                 break;
  76.             case SCENE_LOADING:
  77.                 setScene(loadingScene);
  78.                 break;
  79.             case SCENE_BESTSCORES:
  80.                 setScene(bestScoresScene);
  81.                 break;
  82.             case SCENE_SEETINGS:
  83.                 setScene(seetingsScene);
  84.                 break;
  85.             case SCENE_ABOUT:
  86.                 setScene(aboutScene);
  87.                 break;
  88.             case SCENE_EXIT:
  89.                 setScene(exitScene);
  90.                 break;    
  91.             default:
  92.                 break;
  93.         }
  94.     }
  95.    
  96.    
  97.     public static SceneManager getInstance()
  98.     {
  99.         return INSTANCE;
  100.     }
  101.    
  102.     public SceneType getCurrentSceneType()
  103.     {
  104.         return currentSceneType;
  105.     }
  106.    
  107.     public BaseScene getCurrentScene()
  108.     {
  109.         return currentScene;
  110.     }
  111.    
  112.     public void createSplashScene(OnCreateSceneCallback pOnCreateSceneCallback)
  113.     {
  114.         ResourcesManager.getInstance().loadSplashScreen();
  115.         splashScene = new SplashScene();
  116.         currentScene = splashScene;
  117.         pOnCreateSceneCallback.onCreateSceneFinished(splashScene);
  118.     }
  119.    
  120.     private void disposeSplashScene()
  121.     {
  122.         ResourcesManager.getInstance().unloadSplashScreen();
  123.         splashScene.disposeScene();
  124.         splashScene = null;
  125.     }
  126.    
  127.     public void createMenuScene()
  128.     {
  129.         ResourcesManager.getInstance().loadMenuResources();
  130.         menuScene = new MainMenuScene();
  131.         //loadingScene = new LoadingScene();
  132.         SceneManager.getInstance().setScene(menuScene);
  133.         disposeSplashScene();
  134.     }
  135.    
  136.     public void createBestScoresScene()
  137.     {
  138.         bestScoresScene = new BestScoresScene();
  139.         currentScene = bestScoresScene;
  140.         //pOnCreateSceneCallback.onCreateSceneFinished(bestScoresScene);
  141.     }
  142.    
  143.     public void loadGameScene(final Engine mEngine)
  144.     {
  145.       //setScene(gameScene);
  146.         //loadingScene = new LoadingScene();
  147.         setScene(loadingScene);
  148.         ResourcesManager.getInstance().unloadMenuTextures();
  149.         mEngine.registerUpdateHandler(new TimerHandler(0.1f, new ITimerCallback()
  150.         {
  151.             public void onTimePassed(final TimerHandler pTimerHandler)
  152.             {
  153.                 mEngine.unregisterUpdateHandler(pTimerHandler);
  154.                 ResourcesManager.getInstance().loadGameResources();
  155.                 gameScene = new GameScene();
  156.                 setScene(gameScene);
  157.             }
  158.         }));
  159.     }
  160.    
  161.     public void loadMenuScene(final Engine mEngine)
  162.     {
  163.         setScene(loadingScene);
  164.         gameScene.disposeScene();
  165.         ResourcesManager.getInstance().unloadGameTextures();
  166.         mEngine.registerUpdateHandler(new TimerHandler(0.1f, new ITimerCallback()
  167.         {
  168.             public void onTimePassed(final TimerHandler pTimerHandler)
  169.             {
  170.                 mEngine.unregisterUpdateHandler(pTimerHandler);
  171.                 ResourcesManager.getInstance().loadMenuTextures();
  172.                 setScene(menuScene);
  173.             }
  174.         }));
  175.     }
  176.    
  177. }
  178.  
  179.  
  180.  
Parsed in 0.018 seconds, using GeSHi 1.0.8.4


MainMenuScene.java
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.example.matchcolors;
  2.  
  3. import org.andengine.engine.camera.Camera;
  4. import org.andengine.entity.scene.menu.MenuScene;
  5. import org.andengine.entity.scene.menu.MenuScene.IOnMenuItemClickListener;
  6. import org.andengine.entity.scene.menu.item.IMenuItem;
  7. import org.andengine.entity.scene.menu.item.SpriteMenuItem;
  8. import org.andengine.entity.scene.menu.item.decorator.ScaleMenuItemDecorator;
  9. import org.andengine.entity.sprite.Sprite;
  10. import org.andengine.opengl.util.GLState;
  11. //import org.andengine.engine.handler.timer.ITimerCallback;
  12. import com.example.matchcolors.BaseScene;
  13. import com.example.matchcolors.SceneManager.SceneType;
  14.  
  15. public class MainMenuScene extends BaseScene implements IOnMenuItemClickListener
  16. {
  17.        
  18.        
  19.         private MenuScene menuChildScene;
  20.     private final int MENU_PLAY = 0;
  21.     private final int MENU_BESTSCORES = 1;
  22.     private final int MENU_SEETINGS = 2;
  23.     private final int MENU_ABOUT = 3;
  24.     private final int MENU_EXIT = 4;
  25.    
  26.         @Override
  27.     public void createScene()
  28.     {
  29.                 createBackground();    
  30.                 createMenuChildScene();
  31.     }
  32.  
  33.     @Override
  34.     public void onBackKeyPressed()
  35.     {
  36.         System.exit(0);
  37.     }
  38.  
  39.     @Override
  40.     public SceneType getSceneType()
  41.     {
  42.         return SceneType.SCENE_MENU;   
  43.     }
  44.  
  45.     @Override
  46.     public void disposeScene()
  47.     {
  48.        
  49.     }
  50.    
  51.     private void createBackground()
  52.     {
  53.         //attachChild(new Sprite(400, 240, resourcesManager.menu_background_region, vbom)
  54.         attachChild(new Sprite(0, 0, resourcesManager.menu_background_region, vbom)
  55.         {
  56.             @Override
  57.             protected void preDraw(GLState pGLState, Camera pCamera)
  58.             {
  59.                 super.preDraw(pGLState, pCamera);
  60.                 pGLState.enableDither();
  61.             }
  62.         });
  63.     }
  64.    
  65.    
  66.  
  67.     private void createMenuChildScene()
  68.     {
  69.         menuChildScene = new MenuScene(camera);
  70.         //menuChildScene.setPosition(400, 240);
  71.         menuChildScene.setPosition(0, 0);
  72.        
  73.         final IMenuItem playMenuItem = new ScaleMenuItemDecorator(new SpriteMenuItem(MENU_PLAY, resourcesManager.play_region, vbom), 1.2f, 1);
  74.         final IMenuItem bestscoresMenuItem = new ScaleMenuItemDecorator(new SpriteMenuItem(MENU_BESTSCORES, resourcesManager.bestscores_region, vbom), 1.2f, 1);
  75.         final IMenuItem seetingsMenuItem = new ScaleMenuItemDecorator(new SpriteMenuItem(MENU_SEETINGS, resourcesManager.seetings_region, vbom), 1.2f, 1);
  76.         final IMenuItem aboutMenuItem = new ScaleMenuItemDecorator(new SpriteMenuItem(MENU_ABOUT, resourcesManager.about_region, vbom), 1.2f, 1);
  77.         final IMenuItem exitMenuItem = new ScaleMenuItemDecorator(new SpriteMenuItem(MENU_EXIT, resourcesManager.exit_region, vbom), 1.2f, 1);
  78.        
  79.        
  80.         menuChildScene.addMenuItem(playMenuItem);
  81.         menuChildScene.addMenuItem(bestscoresMenuItem);
  82.         menuChildScene.addMenuItem(seetingsMenuItem);
  83.         menuChildScene.addMenuItem(aboutMenuItem);
  84.         menuChildScene.addMenuItem(exitMenuItem);
  85.        
  86.         menuChildScene.buildAnimations();
  87.         menuChildScene.setBackgroundEnabled(false);
  88.        
  89.         /*playMenuItem.setPosition(playMenuItem.getX(), playMenuItem.getY() + 10);
  90.         bestscoresMenuItem.setPosition(bestscoresMenuItem.getX(), bestscoresMenuItem.getY() - 110);*/
  91.        
  92.        // playMenuItem.setPosition(playMenuItem.getX(), playMenuItem.getY() - 40);
  93.        // bestscoresMenuItem.setPosition(bestscoresMenuItem.getX(), bestscoresMenuItem.getY() - 70);
  94.         /*
  95.          
  96.          *
  97.          *
  98.          *    t u t a j   d o k o ń c z y ć
  99.          *
  100.          *
  101.          */
  102.        
  103.        
  104.        
  105.        
  106.         menuChildScene.setOnMenuItemClickListener(this);
  107.        
  108.         setChildScene(menuChildScene);
  109.     }
  110.  
  111. public boolean onMenuItemClicked(MenuScene pMenuScene, IMenuItem pMenuItem, float pMenuItemLocalX, float pMenuItemLocalY)
  112. {
  113.         switch(pMenuItem.getID())
  114.         {
  115.         case MENU_PLAY:
  116.                 SceneManager.getInstance().loadGameScene(engine);
  117.             return true;
  118.         /*case MENU_SEETINGS:
  119.             return true;*/
  120.         case MENU_BESTSCORES:
  121.                 SceneManager.getInstance().createBestScoresScene();
  122.             return true;
  123.         /*case MENU_ABOUT:
  124.             return true;
  125.         case MENU_EXIT:
  126.             return true;*/
  127.         default:
  128.             return false;
  129.     }
  130. }
  131.  
  132. }
  133.  
Parsed in 0.016 seconds, using GeSHi 1.0.8.4


GameActivity
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.example.matchcolors;
  2.  
  3. import java.io.IOException;
  4.  
  5. import org.andengine.engine.Engine;
  6. import org.andengine.engine.LimitedFPSEngine;
  7. import org.andengine.engine.camera.Camera;
  8. import org.andengine.engine.handler.timer.ITimerCallback;
  9. import org.andengine.engine.handler.timer.TimerHandler;
  10. import org.andengine.engine.options.EngineOptions;
  11. import org.andengine.engine.options.ScreenOrientation;
  12. import org.andengine.engine.options.WakeLockOptions;
  13. import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
  14. import org.andengine.entity.scene.Scene;
  15. import org.andengine.ui.activity.BaseGameActivity;
  16.  
  17. import android.view.KeyEvent;
  18.  
  19. public class GameActivity extends BaseGameActivity
  20. {
  21.         private Camera camera;
  22.         private ResourcesManager resourcesManager;
  23.         public EngineOptions onCreateEngineOptions()
  24.     {
  25.         camera = new Camera(0, 0, 800, 480);
  26.         EngineOptions engineOptions = new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(800, 480), this.camera);
  27.         engineOptions.getAudioOptions().setNeedsMusic(true).setNeedsSound(true);
  28.         engineOptions.setWakeLockOptions(WakeLockOptions.SCREEN_ON);
  29.         return engineOptions;
  30.     }
  31.  
  32.         public void onCreateResources(OnCreateResourcesCallback pOnCreateResourcesCallback) throws IOException
  33.         {
  34.             ResourcesManager.prepareManager(mEngine, this, camera, getVertexBufferObjectManager());
  35.             resourcesManager = ResourcesManager.getInstance();
  36.             pOnCreateResourcesCallback.onCreateResourcesFinished();
  37.         }
  38.  
  39.     public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback) throws IOException
  40.     {
  41.         SceneManager.getInstance().createSplashScene(pOnCreateSceneCallback);  
  42.     }
  43.  
  44.     public void onPopulateScene(Scene pScene, OnPopulateSceneCallback pOnPopulateSceneCallback) throws IOException
  45.     {
  46.         mEngine.registerUpdateHandler(new TimerHandler(2f, new ITimerCallback()
  47.         {
  48.             public void onTimePassed(final TimerHandler pTimerHandler)
  49.             {
  50.                 mEngine.unregisterUpdateHandler(pTimerHandler);
  51.                 SceneManager.getInstance().createMenuScene();
  52.             }
  53.         }));
  54.         pOnPopulateSceneCallback.onPopulateSceneFinished();
  55.     }
  56.    
  57.    
  58.    // żeby gra działała z podobną szybkością na różnych urządzneniach
  59.     @Override
  60.     public Engine onCreateEngine(EngineOptions pEngineOptions)
  61.     {
  62.         return new LimitedFPSEngine(pEngineOptions, 60);
  63.     }
  64.    
  65.     @Override
  66.     protected void onDestroy()
  67.     {
  68.         super.onDestroy();
  69.             System.exit(0);    
  70.     }
  71.    
  72.     @Override
  73.     public boolean onKeyDown(int keyCode, KeyEvent event)
  74.     {  
  75.         if (keyCode == KeyEvent.KEYCODE_BACK)
  76.         {
  77.             SceneManager.getInstance().getCurrentScene().onBackKeyPressed();
  78.         }
  79.         return false;
  80.     }
  81.    
  82.    
  83. }
  84.  
Parsed in 0.014 seconds, using GeSHi 1.0.8.4


BestScoresScene
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.example.matchcolors;
  2.  
  3. //import org.andengine.entity.scene.background.Background;
  4.  
  5. //import android.graphics.Color;
  6.  
  7. import org.andengine.entity.scene.background.Background;
  8. import org.andengine.entity.text.Text;
  9. import org.andengine.util.adt.color.Color;
  10.  
  11. import com.example.matchcolors.BaseScene;
  12. import com.example.matchcolors.SceneManager.SceneType;
  13.  
  14. public class BestScoresScene extends BaseScene
  15. {
  16.     @Override
  17.     public void createScene()
  18.     {
  19.         setBackground(new Background(Color.WHITE));
  20.         attachChild(new Text(400, 240, resourcesManager.font, "Najlepsze wyniki", vbom));
  21.     }
  22.  
  23.     @Override
  24.     public void onBackKeyPressed()
  25.     {
  26.         System.exit(0);  
  27.     }
  28.  
  29.     @Override
  30.     public SceneType getSceneType()
  31.     {
  32.         return SceneType.SCENE_BESTSCORES;
  33.     }
  34.  
  35.     @Override
  36.     public void disposeScene()
  37.     {
  38.        
  39.     }
  40.    
  41.     /*private void createBackground()
  42.     {
  43.         setBackground(new Background(Color.BLUE));
  44.     }*/
  45. }
  46.  
Parsed in 0.012 seconds, using GeSHi 1.0.8.4
markos2xx
 
Posts: 7
Joined: Thu Jul 18, 2013 3:54 pm

PreviousNext

Return to Tutorials

Who is online

Users browsing this forum: No registered users and 11 guests