105 comments on “Simple AndEngine Game V2.0 [more awesomeness]

  1. 1: —– autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(+25.0f, new Sprite(0,mCamera.getHeight() – this.mParallaxLayer.getHeight(),this.mParallaxLayer)));

    * Please tell how to fir the screens hight and width Mainly the height (It must do it auto, thanks

    2: —— mAutoParallaxBackgroundTexture = new BitmapTextureAtlas(1024, 1024,TextureOptions.DEFAULT);

    * What does the 1024 , 1024 do? because it will crash if values changed thanks :)!
    and very good job on these tutorials!

    • To auto fit the resolution, you have to set the camera height and width manually to certain sizes [just like how the AndEngine tutorials are doing]
      You can have 2 final variables at the top

      from the andEngine tutorials , they use these
      private static final int CAMERA_WIDTH = 720;
      private static final int CAMERA_HEIGHT = 480;

      you’d have to set the width to 800 if you wanna use the background I provided
      and inside onLoadEngine() you’d have to replace the camera line with this one

      this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);

      This should do it regarding the scaling for the game on all resolutions [I didn’t try that but that’s what the “internet” said :P]
      [note: I’m using -25.0f and yours says +25.0f, if you wanna get the correct effect change that to -]

      for the second question , those numbers are the size that the texture atlas takes from the ram, they should be a power of 2 [2,4,8,16,…512,1024…etc] and your image should fit in , in my case the background’s resolution is 1100*480 so taking 1024 won’t fit , you’d have to go to the next number which is 2048

      • 😛 Thank YOU! I think I saw the fixed camera before just didn’t think back! anyway thanks 😀 now My game is all good :)!!, Il post a link when its complete, but first 4 assignments for college :P.

  2. This should fix the stars being off.

    private void shootProjectile(final float pX, final float pY) {

    if (!CoolDown.sharedCooldown().checkValidity()) {

    int offX = (int) (pX – (hero.getX() + hero.getWidth()));
    int offY = (int) (pY – (hero.getY() + hero.getHeight()/3));
    if (offX <= 0)

    final Sprite projectile;
    projectile = pPool.obtainPoolItem();

    int realX = (int) (mCamera.getWidth() – (hero.getX() + hero.getWidth()) + projectile.getWidth());
    float ratio = (float) realX / (float) offX;
    int realY = (int) ((offY * ratio));

    float length = (float) Math.sqrt((realX * realX)
    + (realY * realY));
    I simplified it a bit by getting rid of offReal and made the stars appear closer to where the star is in the animation. Not sure if it works on other resolutions.

  3. Hi
    you forget to close else
    // enabling MultiTouch if available
    try {
    if (MultiTouch.isSupported(this)) {
    mEngine.setTouchController(new MultiTouchController());
    } else {
    Toast.makeText(this,”Sorry your device does NOT support MultiTouch!\n\n(Falling back to SingleTouch.)”,Toast.LENGTH_LONG).show();
    } catch (final MultiTouchException e) {
    Toast.makeText(this,”Sorry your Android Version does NOT support MultiTouch!\n\n(Falling back to SingleTouch.)”,Toast.LENGTH_LONG).show();

  4. Thanks for the quick response. My SDK works good, but i have problems importing that code. First of all, this: [2012-01-04 12:47:00 – AndEngine Tutorial V2.0] Unable to resolve target ‘android-4’

    And there are any red lines in code, like overrides and imports.

    • That error is probably because I’m using an sdk that you don’t have, right click on your project then go to properties then chose android and chose which target you want to build against [android -4 is sdk 1.6 which am using here] or you can download the 1.6 sdk.

      you can remove the override annotations (@override) if you want, also from the link in the first tutorial just make sure that AndEngine is working properly

  5. This has been a great tutorial, and very fun to work with. One question I have, is how would you go about making an animated explosion to go with the collision of the target? Creating a new sprite doesn’t make a lot of sense. I suppose that somehow you would load up other images from the same or different sprite sheet and change the tile index?

    Does anyone have any thoughts or examples of this?

    Thanks a bunch!

    • I’m glad you liked it, you can use an explosion pool and add a new sprite to get the explosion effect
      if anyone got any other idea then please state it here 😀

  6. Im trying to add an effect when the targets hits the player that the player will loose health.I got an image for the heart but im struggling just to get the image on the screen. I have followed this tutorial but just dont get it working! i have an idea for the code.

    • I’m planning on adding a similar effect on the next tutorial , but I can’t say when I’ll even start working on that [pretty busy lately >_<]
      but I think that you just need to add your heart sprite over the player's sprite, just make sure that the sprite doesn't get covered by any other sprite [look up at the z depth for sprites]

  7. Thanks for the tutorial, I was lost in AndEngine and with this tutorial, I learned so much things.

    Tomorrow I want to refactor the code, to let it a bit more OO. I can post the project here if someone wants :).

    If you want help with the next tutorial, let me know, I will try to help with I can.

    Again, thanks for the tutorial, was well detailed and step by step.

    • I didn’t make it OO because I thought that having everything in one file would be better for starting a tutorial [I used to hate multiple files beginners tutorials]
      But I was planning on making it OO in future updates , if you did that then share the project and I will add it to the tutorial and may use it as a reference for the next one

  8. Jimmar i don’t have words to tank you. Please, for the good of the planet, you need to keep up the good work.

  9. Jimmar, another question for you: i want bleed the ninja ( yes, i’m bad ), and create life for him that would be measured by hearts or something like that.
    How do I bleed the ninja ? It’s possible to use the same sprite, but in another line the “bleed animation” ? If is, how i do this ?
    Thank you again.

  10. Jimmar, my master. I want to move the ninja with the Accelerometer ( only up and down ). You have any tutorial or examples ? Thank you !!!

  11. Hey Jim, i am having problem on the import.org.anddev.andengine.opengl.texture.atlas where it shows red underline. It says org.anddev.andengine.opengl.texture.atlas cannot be resolved. Any solution?

    • umm , did you manage to go through the first tutorial ?
      are you sure that andEngine is working correctly ? if not then check the links I provide at the top of the first tutorial they contain how to do that
      if you did all that , then try cleaning your project and restarting eclipse see if that helps or not

  12. Master, the example works great. But i have one question ( no ! what a surprise ).
    I don’t know what version of “AndEngine.jar” i use. In your example, functions like: mMainScene.attachChild(target); works great. But in this example of accelerometer, he use:
    scene.getTopLayer().addEntity(sprite); And attachChild not work.
    I’m a little lost here, and i need your help, Master !!!

    • apparently they deprecated getTopLayer() , attachChild should work fine
      but there are some changes you need to do for the texture too
      this is a full working modified code [also changed resolution width to 800 😛
      it should work [just make sure you put the proper image in it]

      • Thanks again, Master.
        You are great ! So i think i just have to continue using the andengine.jar where methods like attachChild works. 😀

  13. Hi Jimmar,

    Please forgive my poor english and let me congratulate you for your outstanding work doing this tutorials, are really usefull and very good explained.

    Just one question about the background music you are using for your tutorials, is it copyrighted or something? I’m interested on using it for a project that I’ve been working on.

    Thanks again for your collaboration.

    • All the sprites/music in the first tutorial are made by Ray and taken from his tutorial [http://www.raywenderlich.com/352/how-to-make-a-simple-iphone-game-with-cocos2d-tutorial], he gave me permission to use them in my tutorial and I think he won’t mind you using them in yours, but you may want to ask him about them
      The sprites in the second tutorial are made by my friend [except for the background which I created using paint :P] , and you can use them in whatever you want
      Thank you for going through the tutorial , glad you liked it 😀

  14. Jimmar,

    I am trying to follow your tutorials and develop the game you have described…it was all fine till the pools tutorial…the pool thing worked fine..now i am interested in using sprite sheets for the target instead of a static target..once done with that i will try to animate the player too..i followed your method but its troubling me a bit..there is no error as such but the application ForceCloses when i try to run it..it will be very kind of you if you can provide me your mail id so that i can send you the project to take a look..I am sure it wont take you more than a few minutes to figure out what is wrong with it…
    thanks in advance…pls rply soon..

    • you can use pastebin.com to put your code and paste a link here if you want
      also my email is available in the about page [link at top of the blog]

  15. Jimmar,

    i have mailed you the SlingShot.rar file (the project i mentioned)..please take a look and help me out…
    thank you….please reply soon(as you always do..:)).

  16. Master, i want stop the enemies in touch event, i already have created the event, but i don’t know how stop them. Thanks again !

    • umm… try removing the modifier(s) from the sprites in the event, not quite sure if that works but it should
      you may also need to stop the animation too

      • So… I used “this.clearEntityModifiers();” for stop the sprite.

        But “this.stopAnimation();” not stopped the animation. Any idea ? Thanks again²

      • Another question. I put this.animate… In ontouch of sprite method. But i have a animation in all enemies sprites. Why? thanks again

      • you mean that when you touch a sprite all sprites animate ? and did you solve the stopping animation problem yet ?
        also could you paste your code on pastebin.com and give me a link so I understand what’s going on

  17. Exactly, dude. When i touch one sprite all sprites animate.

    inimigo1 = new AnimatedSprite(x, y, this.mInimigo1TextureRegion)
    public boolean onAreaTouched(TouchEvent pSceneTouchEvent,float pTouchAreaLocalX, float pTouchAreaLocalY)
    this.animate(new long[]{200, 200, 200}, 3, 5, true);
    return true;

    Here is my code. Any problem ?

    • JiMMaR, this.animate(new long[]{200, 200, 200}, 3, 5, true) don’t work only inimigo1.animate(new long[]{200, 200, 200}, 3, 5, true) but all sprites animate. And, inimigo1.stopAnimation(); and this.stopAnimation(); don’t work. =/

      • your problem is probably here , I mentioned this in the tutorial
        inimigo1 = new AnimatedSprite(x, y, this.mInimigo1TextureRegion);
        should be
        inimigo1 = new AnimatedSprite(x, y, this.mInimigo1TextureRegion.deepCopy());
        this should potentially solve the problem that all sprites animate together

        as for the issue with stopping animation, I still didn’t mess around with that so I can’t really help you .. tell me if you found a solution though

  18. Thanks, Jimmar. this.mInimigo1TextureRegion.deepCopy() really solved my problem. After, i just use this.stopAnimation(); and the animation stopped too. You are my hero !


  19. Master, what you’re thinking in develop for the next tutorial ?
    And… Everybody wanna know: The next has date of release ?

  20. Master, i using a basic collision detection, but i’m not using this to removesprite, i’m using to do an animation of death ( MUAHUAHUA. 😀 ). But i have a problem ( WHAT A SURPRISE ! ) i want to do the animation only in the first time when the “bullet” hit the target. Otherwise the sprite always animate, and it look’s strange a death “sprite” animate again. 😀 You know any way to know if the target has hit before ?

    if (hit)
    if(if is not hit before)
    _inimigo.animate(new long[]{50, 50, 50, 50}, 4, 7, false);
    hit = false;

    Thanks²³³³, and sorry for my English.

    • Just add a boolean that initially is false, and when the enemy is hit simply check if the boolean is false and if it is, set it to true and then do the animation. if the enemy is hit again the boolean will be true and the animation won’t restart…

      • Thanks, Björn. But i have a LinkedList with a lot of enemies. And i solved the problem by other way. I just used de pool to recycle and removed the sprite from LinkedList.

    • The idea is just how Björn explained it
      but in practice you may need to create a new monster class which contains a sprite and a boolean flag [or an int counter if you wanna do more than one hit] and your linked list would be a list of enemies instead of list of sprites

      I’m kinda busy with couple of projects [and finding a job :P] so no ETA for next tutorial .. sorry

  21. Yes. Anyway i already have created my enemy class with attributes like life, speed, hitCount and others…

    Now i wanna to know how in the game “Fruit Ninja” ( you should know) is made the cut effect when we touch the screen. There are some method with initial and final touch ?
    ( one video of the game: http://www.youtube.com/watch?v=tXEo-asZyBY&feature=fvst )
    Thanks for the help and good luck in the “Job quest” 😀

    • if you want the trail effect behind the finger drag , that’s kinda too advanced for me 😛
      but I think you should be able to find stuff for that if you looked [or asked at the andEngine forums]

      if you just want a cut effect on a sprite , then that should be kinda doable .. but I still can’t help you in that so far

      • I really look for trail effect. I’ll look for the effect in And Engine Forums. And if i find, i post here.

        Thanks, Jimmar.

  22. great tutorial!!! it was exactly what I was looking for!!
    It covers all the main aspects related to the game development in andengine!!
    keep on good working!!!

  23. Hi Jimmar,

    Thank you so much for the tutorial.
    I must say this is the best tutorial on anything related to android. You have obviously explained the things very nicely, but also because you make it look so effortless and not intimidating at all. Also you make it really funny, many of the ninja stuff made me smile and I really enjoyed reading it.

    I had one suggestion for you, why not consider writing a book on Andengine. I have gone through quite a few android game development books at least 4-5(I have an online subscription) and believe me they don’t even properly do what you have done in these three blog entries. I am sure you will be able to write a great one. A publisher is looking for someone to write a book http://www.andengine.org/forums/post31645.html#p31645

    Thanks again for the tutorial.

    • I’m pretty flattered by this, but I don’t think that I’m currently qualified to write a book.
      I started these tutorials as a way for me to learn and because I couldn’t find suitable tutorials for people like me, I’m planning on releasing more tutorials after I get rid of my laziness 😛

      Maybe someday I’ll release a book, but not yet.. who knows

  24. Hi Jimmar, it would be great if you could make a tutorial about moving a character on a scroll level with a chasing camera (I’m stuck on that last point…) 🙂

  25. Hi JiMMaR, this is great tutorial. I’ve a problem: i downloaded the source code in the final but it havent AndEngineMultiTouch.jar.
    How can i have it?

  26. my projectile is shooting a lot lower then where i touch, how do i fix it. i have all the same code i believe.

  27. “In the above code, we created a new AutoParallaxBackground that changes on a rate of 5 parallex and we attached the background image and set it to go on a speed of -25 [move from right to left], mess around with it and see what you get ”

    Hi, can you help me to move background image from up to down or down to up instead right to left as in your tutorial

  28. hey man, thanks for your excellent work!

    I follow you. and i wanna make a little game also.
    I already create a scene where spawn sprite are comes and pass the screen. I wanna to set touch effects on every spirits which on the screen.

    Where i add the touch effects for every spirits ??

  29. I want to shoot the bullet from Canon with projectile motion just like Angry Birds has. Can you help in writing the code the for that I am not able to get hold of the formula and the code.

  30. ItFirst of all I really thank you for this tutorials ..I’d like to give a favor please could you upload the jar file of gles1again…. i have searching on the net but i find only one but thisis diferent that you use ib this tutorial…sorry for my english but you’re tutorial are great and i need to use my bad engliah to try to comunicate! 😉

    • even though I really do suggest following the jimvaders tutorial and switching to GLES2.0
      I updated the links in the posts, if you go to the first tutorial you should be able to download the jar file from there
      or you could download the whole project from this tutorial and extract the jar file from it

  31. Heey “JiMMaR” your tutorial really help . i am working on a app with my friend . and i want to make it a side scoller . do you know where i can get started ? i been looking for a tutorial on a basic tmx game but i cant find anything . also how did you make your sprite sheet ? i would like to make one for my game . thanks (;

  32. Hello,
    First of all thank you for this awesome tutorial.
    I’ve just one question : How do I do if I want the ninja to run when he’s not throwing shurikens? I suppose I need 2 animatedsprites for this, but How manage them?
    Thanks in advance,

    • if you have them all in one sheet , you can chose which frames to animate
      let’s say you have one sheet , where the first 4 frames are running , and the other 4 frames are throwing
      you prepare it like this
      final long[] fDurationRun = { 300, 300, 300, 300,};
      final int[] framesRun = { 0, 1, 2, 3};

      final long[] fDurationThrow = { 300, 300, 300, 300,};
      final int[] framesThrow = { 4, 5, 6, 7};

      and then when you animate the running you do


      when you want to throw, you’ll have to
      ninja.stopAnimation(); //not sure if this is needed , play around
      ninja.animate(fDurationThrow,framesThrow,false); //false is for the loop

      you might also wanna attach an animation listener so that when throwing is finished, you go back to running again

      you may have a problem with the proper running animation, another solution is to have 2 sprites , one for the upper part and one for the lower part , where the lower part is always animating for the running animation and the upper part only throws, attack them together to an entity

      that’s what I could think of right now, hope it helped

  33. Hello my friend congrats for the great tutorial 🙂
    I wanna know if is possible that you could teach us how to make the ninja got damage on collision. pls pls pls.

    • the ninja getting damage should be the same way as the zombies getting damage, if you understood the tutorial you should be able to do that yourself 😀

      • Tks Jimmar I already figure out how to do that 🙂 now i’m trying to do a health bar, i’m researching how to do that, but if you have some tips i’ll apreciatte, and when u have a bit of time to u spend with us 😛 please can u give some classes about box2d and how to use it, or a general view 🙂 tks in advance and really i loved your work 😛 cya

    • Please don’t paste long codes as comments , use pastebin next time
      and you didn’t mention what was wrong , but you have an error here
      this.asLakon.animate(new long[] { 100, 100 }, 0, 3, true);
      this is wrong , it should be
      this.asLakon.animate(new long[] { 100, 100 }, new long[] {0,3}, true);
      this will loop over the frames 0 and 3 [it will skip frames 1 and 2] and each will get 100ms

  34. can u correct this code,,i dont want the player to rotate.
    public void createPlayer(TiledTextureRegion mCircleFaceTextureRegion, int x, int y){

    mPlayer = new Player(x, y, 30,30,mCircleFaceTextureRegion, this);
    FixtureDef FIXTURE = PhysicsFactory.createFixtureDef(1, 0.5f, 0.5f);
    Body body;
    //body = PhysicsFactory.createCircleBody(mPhysicsWorld, mPlayer, BodyType.DynamicBody, FIXTURE);
    body= PhysicsFactory.createBoxBody(mPhysicsWorld, mPlayer, BodyType.DynamicBody, FIXTURE);
    mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(mPlayer, body, true, true, false, false));


    • I didn’t talk about physics yet and this is out of the scope of the post .. also I’m not sure what you are trying to do
      I can’t help you in this .. sorry

  35. Hello,JiMMar! I have a problem when i import your source code .Project can’t start. It notify a red exclamation mark,In java build path notify andengine mutil touch missing and com.androd.ide.ECLIPSE.adt.libarry red erro although I changed java compiler is 1.6.Can you help me?

  36. Hi Jimmar. You tutorials are life savers from newbies like me. Thank you very much for this.

    I do have a doubt. Keeping you code as base, I am trying to make a game where my player can move right using accelerometer. In my case, the enemies are coming from bottom. I use smooth camera and make it to chase player. I use parallax background. Till this point everything works fine. But firing bullets for my player is not working fine once I cross screen width and continue to move right. I tried changing shootProjectile method to give correct formX and toX value to MoveModifier but it doesn’t seem to work once player crosses screen width and continue to move.

    Please advise me, what should I do.

    Thanks again for the tutorial

  37. Thanks a lot for this awesome tutorial !
    but there’s a problem when i try to build the project (after i add the required jar files of MultiTouch and AndEngine ) …

    Unbale to execute DEX.

  38. Thanks a lot for this awesome tutorial..but i have faced one problem when i use AutoParallaxBackground it flicker(lag) i mean it is not very smooth ..i am creating running with shooting game using your code but not able to achieve very smooth effect in background moving Please help me i searched a lot not found any solution……

  39. Hello, JiMMaR.
    Literally the way you do these tutorials are just the best. I have so much hope and you’ve made it possible for me.

    May I also have a real quick request? I’ve been trying to get a FAIL if one of the targets collides with my Ninja.

    //check if player hit
    if (_fish.collidesWith (player))
    hit = true;

    However, I don’t think andengine is detecting collision with my player. Can you do a real quicky. Maybe just add an extra bit. How to detect collision between a target and player?
    Thank you !

    • ops! to be consistent with your tutorial. its supposed to be _target not _fish. Just a small experimentation for me. lol

  40. when i run app, it is error : can anyone help me

    this is LogCat

    03-06 16:23:33.810: E/AndroidRuntime(18852): FATAL EXCEPTION: main
    03-06 16:23:33.810: E/AndroidRuntime(18852): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.wordpress.jimmaru.tutorial.SimpleGame/com.wordpress.jimmaru.tutorial.SimpleGame.AndEngineSimpleGame}: java.lang.ClassNotFoundException: Didn’t find class “com.wordpress.jimmaru.tutorial.SimpleGame.AndEngineSimpleGame” on path: /data/app/com.wordpress.jimmaru.tutorial.SimpleGame-1.apk
    03-06 16:23:33.810: E/AndroidRuntime(18852): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
    03-06 16:23:33.810: E/AndroidRuntime(18852): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
    03-06 16:23:33.810: E/AndroidRuntime(18852): at android.app.ActivityThread.access$600(ActivityThread.java:141)
    03-06 16:23:33.810: E/AndroidRuntime(18852): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
    03-06 16:23:33.810: E/AndroidRuntime(18852): at android.os.Handler.dispatchMessage(Handler.java:99)
    03-06 16:23:33.810: E/AndroidRuntime(18852): at android.os.Looper.loop(Looper.java:137)
    03-06 16:23:33.810: E/AndroidRuntime(18852): at android.app.ActivityThread.main(ActivityThread.java:5041)
    03-06 16:23:33.810: E/AndroidRuntime(18852): at java.lang.reflect.Method.invokeNative(Native Method)
    03-06 16:23:33.810: E/AndroidRuntime(18852): at java.lang.reflect.Method.invoke(Method.java:511)
    03-06 16:23:33.810: E/AndroidRuntime(18852): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    03-06 16:23:33.810: E/AndroidRuntime(18852): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
    03-06 16:23:33.810: E/AndroidRuntime(18852): at dalvik.system.NativeStart.main(Native Method)
    03-06 16:23:33.810: E/AndroidRuntime(18852): Caused by: java.lang.ClassNotFoundException: Didn’t find class “com.wordpress.jimmaru.tutorial.SimpleGame.AndEngineSimpleGame” on path: /data/app/com.wordpress.jimmaru.tutorial.SimpleGame-1.apk
    03-06 16:23:33.810: E/AndroidRuntime(18852): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
    03-06 16:23:33.810: E/AndroidRuntime(18852): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
    03-06 16:23:33.810: E/AndroidRuntime(18852): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
    03-06 16:23:33.810: E/AndroidRuntime(18852): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
    03-06 16:23:33.810: E/AndroidRuntime(18852): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
    03-06 16:23:33.810: E/AndroidRuntime(18852): … 11 more

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s