Sujith S Manjavana
Sujith S Manjavana

Reputation: 1596

How to get maximum x and y values of screen in android 2.3?

I'm using andengine to build my first game. i can receive the x,y values of touch position with the following code. I want to compare the x value(from touchEvent) with the maximum x value of the screen. is it possible with andengine?

@Override
public boolean onSceneTouchEvent(final Scene pScene, final TouchEvent pSceneTouchEvent) {
    if(this.mPhysicsWorld != null) {
        if(pSceneTouchEvent.isActionDown()) {

            this.addFace(pSceneTouchEvent.getX(), pSceneTouchEvent.getPointerID());

            return true;
        }
    }
    return false;
}

Upvotes: 1

Views: 3058

Answers (2)

Plastic Sturgeon
Plastic Sturgeon

Reputation: 12527

Contained in the andengine TouchEvent is a reference to the Android MotionEvent that triggered the call using getMotionEvent();

That motion event will be in device screen coordinates.

Upvotes: 1

Siddharth
Siddharth

Reputation: 4312

There are two concern to get maximum x and y of device which one you need I don't know but here I post both.

  1. You can use CAMERA_WIDTH and CAMERA_HEIGHT to get maximum x and y of your game play.
  2. You can use following code to get maximum height and width of device

    Display display = getWindowManager().getDefaultDisplay();

    int width = display.getWidth();

    int height = display.getHeight();

Upvotes: 2

Related Questions