Monday, June 20, 2011

Solution of problem touch input

First, make sure BaseGameAcitvity implement IOnSceneTouchListener. 
Then add setOnSceneTouchListener(this) to your scene. As you register touch listener on whole scene then no matter where you touch onSceneTouchEvent() will be called.
Then, as a part of the interface IOnSceneTouchListener, you will have to implement an operation



public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) {
  if(pSceneTouchEvent.isActionDown){
     .... do stuff 1
     return true; //don't forget this!
  }
  if(pSceneTouchEvent.isActionUp){
     .... do stuff 2
     return true; //don't forget this!
  }
  return false;
}

To make all works fine, don't forget add "return true", 
if you don't add, then ActionUp does not worked and stuff 2 never execute.

Sunday, June 19, 2011

Removing Activity Label

In manifest.xml file you need to change the theme so there is no title bar

android:theme="@android:style/Theme.NoTitleBar"

and that needs to be in the activity element 

<activity android:name=".MyMainClass" android:label="@string/app_name"  
android:theme="@android:style/Theme.NoTitleBar">

Safely detaching a entity from scene

To safely remove a entity from scene on finish path modifier i recommend use EntityDetachRunnablePoolUpdateHandler.

1) Define variable on main class
     private EntityDetachRunnablePoolUpdateHandler detachPoolHandler =  new EntityDetachRunnablePoolUpdateHandler();
2) Register handler
    getEngine().registerUpdateHandler(detachPoolHandler);

3) Add to onModifierFinished of LoopEntityModifier detaching of shape with use of EntityDetachRunnablePoolUpdateHandler

new LoopEntityModifier(new IEntityModifierListener() {
            @Override
            public void onModifierFinished(final IModifier<IEntity> pEntityModifier, final IEntity pEntity) {
                EntityDetachRunnablePoolItem edrpi = detachPoolHandler.obtainPoolItem();
                edrpi.set(entity, scene.getChild(0));
                MainActivity.instance.detachPoolHandler.postPoolItem(edrpi);
                visible = false;
            }
        }, 0, null, new SequenceEntityModifier(new ScaleModifier(0.2f, 1f, 0.1f)));

When the EntityDetachRunnablePoolUpdateHandler gets his next update, the entity is safely removed.

Bands on the background

In andengine standart example you can see bands on the background. The solution of the problem is override onInitDraw when creating Sprite:
 Sprite sprite = new Sprite(0,0,null) { 
        protected void onInitDraw(final GL10 pGL)     {
       super.onInitDraw(pGL);
       GLHelper.enableTextures(pGL);
       GLHelper.enableTexCoordArray(pGL);
       GLHelper.enableDither(pGL);
    }
 };
 
 

Saturday, June 18, 2011

Hello everyone, my blog about developing games for android

AndEngine is a free 2D OpenGL Game Engine for the Android platform and I think it's the best variant of engine with to start develop games for Android. Month ago I was start develop my first game. Hopefully soon you will be able to appreciate it.