Implementing SurfaceGestureDetector Example Andengine

 

call this method in on loadScene( )

private void setupGestureDetaction(){
 
  SurfaceGestureDetector surfaceGestureDetector = new SurfaceGestureDetector(1f) {
   
   @Override
   protected boolean onSwipeUp() {
    System.out.println("onSwipeUp");
    return true;
   }
   
   @Override
   protected boolean onSwipeRight() {
    System.out.println("onSwipeRight");
    return true;
   }
   
   @Override
   protected boolean onSwipeLeft() {
    System.out.println("onSwipeLeft");
    return true;
   }
   
   @Override
   protected boolean onSwipeDown() {
    System.out.println("onSwipeDown");
    return true;
   }
   
   @Override
   protected boolean onSingleTap() {
    System.out.println("onSingleTap");
    return true;
   }
   
   @Override
   protected boolean onDoubleTap() {
    System.out.println("onDoubleTap");
    return true;
   }
   
   @Override
   public boolean onManagedTouchEvent(TouchEvent pSceneTouchEvent) {    
    return super.onManagedTouchEvent(pSceneTouchEvent);
   }
   
   @Override
   public boolean onSceneTouchEvent(Scene pScene,
     TouchEvent pSceneTouchEvent) {    
    return super.onSceneTouchEvent(pScene, pSceneTouchEvent);
   }
  };
  surfaceGestureDetector.setEnabled(true);
 
 
  mScene.setOnSceneTouchListener(surfaceGestureDetector);
}

 


 

How are the Android Market ratings (stars) calculated?

I was wondering that how Android market calculate rating (stars) for apps. see it is really very simple to calculate

see the image for detail Smile

market_formula

SUMPRODUCT(A2:A6,B2:B6) / SUM(B2:B6)

Tags: rating, android market, comments

get angle between two points

Hi,

In this post I am going to tell you how to get angle between two points.

private float Xlocal = 0.0f;
private float Ylocal = 0.0f;
private float X = 0;
private float Y = 0;
 
private float velocity = 50f;
 
@Override
    public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) {
        
        if (pSceneTouchEvent.isActionDown()) {            
            
            Xlocal = pSceneTouchEvent.getX();
            Ylocal = pSceneTouchEvent.getY();
            
        } else if (pSceneTouchEvent.isActionUp()) {
            
            X = (pSceneTouchEvent.getX() - Xlocal);
            Y = (pSceneTouchEvent.getY() - Ylocal);
            
            float angleRad =(float)Math.atan2(Y, X);                    
                        
                float Vx = velocity * (float)Math.cos(angleRad);
                float Vy = velocity * (float)Math.sin(angleRad);
            //Now you can apply force or set velocity in direction Vx and Vy
                        
        }
        return true;        
    }

Helpful post:


http://stackoverflow.com/questions/9372909/linearimpulse-slows-down-on-pressing-power-button-andengine-box2d


 


Tags:


shoot at angle, angle between two points, how to get angle between two points andengine android

Animate in reverse order Andengine

private int mAnimationDirection;
 
private int calculateCurrentFrameIndex() {
        final long animationProgress = this.mAnimationProgress;
        final long[] frameEnds = this.mFrameEndsInNanoseconds;
        final int frameCount = this.mFrameCount;
        for(int i = 0; i < frameCount; i++) {
                if(frameEnds[i] > animationProgress) {
                        return i * mAnimationDirection;
                }
        }
 
        return (frameCount - 1) * mAnimationDirection;
}
 
public AnimatedSprite animate(final long[] pFrameDurations, final int pFirstTileIndex, final int pLastTileIndex, final int pLoopCount, final IAnimationListener pAnimationListener) {
        if(pLastTileIndex == pFirstTileIndex) {
                throw new IllegalArgumentException("An animation needs at least two tiles to animate between.");
        }
 
        final int frameCount = Math.abs(pLastTileIndex - pFirstTileIndex) + 1;
        if(pFrameDurations.length != frameCount) {
                throw new IllegalArgumentException("pFrameDurations must have the same length as pFirstTileIndex to pLastTileIndex.");
        }
        this.mFrameCount = frameCount;
        this.mAnimationDirection = (pLastTileIndex > pFirstTileIndex ? 1 : -1);
        this.mAnimationListener = pAnimationListener;
        ...
}

 


 


http://www.andengine.org/forums/development/animatedsprite-how-to-animate-in-reverse-t83.html


Tags:


Android, AndEngine, Animated Sprite, Reverse order animate

How to check is connected to network

public boolean isNetworkConnected(){
    if (isGranted(android.Manifest.permission.ACCESS_NETWORK_STATE, getContext())) {
            return false;
        }
        ConnectivityManager conMan = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetwork = conMan.getActiveNetworkInfo();
        return activeNetwork != null && activeNetwork.isConnected();
}
 
public boolean isGranted(String permission, Context ctx) {
        return PackageManager.PERMISSION_DENIED == ctx.getPackageManager().checkPermission(
                permission, ctx.getPackageName());
    }

Simple code snippet to check that is device connected to network. There are also other helpful methods of NetworkInfo like isConnectedOrConnecting, isAvailable, isFailover, isRoaming etc