Jack
Jack

Reputation: 2625

Finding the edge of the screen android

This may sound really obvious but how can I find the points along the edge of the screen in order to know if a moving object has hit the edge of the screen.

Thankyou

Upvotes: 2

Views: 1435

Answers (2)

Wroclai
Wroclai

Reputation: 26925

Given you have orthographic projection, you can easily know where your edges are by knowing the values you've passed into the glOrtho() function.

For example, consider this line:

glOrtho(0.0f, width, 0.0f, height, 0.0f, 1.0f);

Here you can decide how big influence a single float will have in your program. You can find more information about this here.

However, in this scenario your left edge is 0.0 and your bottom edge is 0.0. Your top edge is defined by height and your right edge is defined by width.

In this way you don't have to rely on a specific screen size since your world will always be as big as you define. For example, you don't need to define the orthographical width and height by the width and height parameters, but instead use some data telling your application how big your world should be.

Upvotes: 2

Brian
Brian

Reputation: 8095

Just do this:

Display display = getWindowManager().getDefaultDisplay(); 
int width = display.getWidth();
int height = display.getHeight();

Upvotes: 0

Related Questions