Does the DIP mechanism kill animation performance?

Problems with Canvas, OpenGL, etc...

Does the DIP mechanism kill animation performance?

Postby ardabro » Mon Oct 17, 2011 10:39 pm

Hello All. I'm new to this forum.

I would like to know if it is good idea to use density-independent pixels for animated 2D games.
Doesn't it kill frame rate?
Should I focus to create very flexible code handling any physical resolution?

Best regards for all
ardabro
Freshman
Freshman
 
Posts: 4
Joined: Mon Oct 17, 2011 10:17 pm

Top

Re: Does the DIP mechanism kill animation performance?

Postby jonbonazza » Sun Oct 23, 2011 12:12 am

density independent pixels are only available in XML.

For games, you need to scale your images based on the display metrics of the device running the app.
jonbonazza
Master Developer
Master Developer
 
Posts: 665
Joined: Thu Jul 15, 2010 2:58 pm
Location: WV USA

Re: Does the DIP mechanism kill animation performance?

Postby ardabro » Tue Oct 25, 2011 10:06 am

hi
Does it mean that canvas always returns width and height in real pixels?
ardabro
Freshman
Freshman
 
Posts: 4
Joined: Mon Oct 17, 2011 10:17 pm

Re: Does the DIP mechanism kill animation performance?

Postby jonbonazza » Wed Oct 26, 2011 11:01 pm

Yes.

What is it that you are trying to do?
jonbonazza
Master Developer
Master Developer
 
Posts: 665
Joined: Thu Jul 15, 2010 2:58 pm
Location: WV USA

Re: Does the DIP mechanism kill animation performance?

Postby ardabro » Fri Oct 28, 2011 11:15 am

jonbonazza wrote:Yes.

What is it that you are trying to do?


Thanks for information.
I'm new to Android development.
Now I try to create just just for education a simple puzzle game - moving elements on canvas and 3 buttons above.

The first concept was to create layout and view in code but after some studies about good practices of layout and screen size handling I decided to use xml and to render in code only canvas content.
ardabro
Freshman
Freshman
 
Posts: 4
Joined: Mon Oct 17, 2011 10:17 pm

Re: Does the DIP mechanism kill animation performance?

Postby jonbonazza » Fri Oct 28, 2011 2:58 pm

The best approach would be to pick a target Canvas size and scale your movements based on that screen size.

Say, for example, you are targetting an 800x400 Canvas. You would calculate the amount to move by diubg something like so:

Code: Select all
public int[] calcScaledMove(int x, int y, Canvas c, int orientation);

int[] scaledMove = new int[2];

if(orientation == 0)        //Portrait
{
     scaledMove[0] = x * (c.getWidth()/400);
     scaledMove[1] = y * (c.getHeight()/800);
}
else if(orientation == 1)     //Landscape
{
      scaledMove[0] = x * (c.getWidth()/800)
      scaledMove[1] = y * (c.getHeight()/400)
}

return scaledMove;
}

jonbonazza
Master Developer
Master Developer
 
Posts: 665
Joined: Thu Jul 15, 2010 2:58 pm
Location: WV USA

Top

Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 3 guests