Bitmap flickers if it is drawn on the edge of surfaceview

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Bitmap flickers if it is drawn on the edge of surfaceview

Postby WarrenFaith » Thu May 07, 2009 7:59 am

hey,

i played a bit with surfaceview and bitmaps and found a problem i don't know how to fix.
i attached the application for better understanding.
Way to reproduce:
1. just install it,
2. start it,
3. touch somewhere on the screen, an icon will occur and move over the screen.
4. wait until it reaches the right edge or the bottom
5. the bitmap will start to flicker...

My code is also attached. I hope someone has a good idea to fix it...?!
Attachments
src.zip
sources including the manifest
(5.67 KiB) Downloaded 72 times
Tutorial2D.apk
(14.02 KiB) Downloaded 57 times
WarrenFaith
Moderator
Moderator
 
Posts: 227
Joined: Fri Mar 13, 2009 10:59 am
Location: Berlin, Germany

Top

Postby WarrenFaith » Thu May 07, 2009 4:58 pm

Finally I found the mistake: It was, of course, my fault. I simply made the wrong math :( should have worked harder at school....

Simply replace the updatePhysics() with this:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.     public void updatePhysics() {
  3.  
  4.         Coordinates coord;
  5.  
  6.         Speed speed;
  7.  
  8.         for (GraphicObject graphic : _graphics) {
  9.  
  10.             coord = graphic.getCoordinates();
  11.  
  12.             speed = graphic.getSpeed();
  13.  
  14.            
  15.  
  16.             // Direction
  17.  
  18.             if (speed.getXDirection() == Speed.X_DIRECTION_RIGHT) {
  19.  
  20.                 coord.setX(coord.getX() + speed.getX());
  21.  
  22.             } else {
  23.  
  24.                 coord.setX(coord.getX() - speed.getX());
  25.  
  26.             }
  27.  
  28.             if (speed.getYDirection() == Speed.Y_DIRECTION_DOWN) {
  29.  
  30.                 coord.setY(coord.getY() + speed.getY());                
  31.  
  32.             } else {
  33.  
  34.                 coord.setY(coord.getY() - speed.getY());                
  35.  
  36.             }
  37.  
  38.            
  39.  
  40.             // borders for x...
  41.  
  42.             if (coord.getX() < 0) {
  43.  
  44.                 speed.toggleXDirection();
  45.  
  46.                 coord.setX(-coord.getX());
  47.  
  48.             } else if (coord.getX() + graphic.getGraphic().getWidth() > getWidth()) {
  49.  
  50.                 speed.toggleXDirection();
  51.  
  52.                 coord.setX(coord.getX() + getWidth() - (coord.getX() + graphic.getGraphic().getWidth()));
  53.  
  54.             }
  55.  
  56.            
  57.  
  58.             // borders for y...
  59.  
  60.             if (coord.getY() < 0) {
  61.  
  62.                 speed.toggleYDirection();
  63.  
  64.                 coord.setY(-coord.getY());
  65.  
  66.             } else if (coord.getY() + graphic.getGraphic().getHeight() > getHeight()) {
  67.  
  68.                 speed.toggleYDirection();
  69.  
  70.                 coord.setY(coord.getY() + getHeight() - (coord.getY() + graphic.getGraphic().getHeight()));
  71.  
  72.             }
  73.  
  74.         }
  75.  
  76.     }
Parsed in 0.038 seconds, using GeSHi 1.0.8.4
WarrenFaith
Moderator
Moderator
 
Posts: 227
Joined: Fri Mar 13, 2009 10:59 am
Location: Berlin, Germany

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 5 guests