glegris / pulpcore

Automatically exported from code.google.com/p/pulpcore
0 stars 1 forks source link

Sprite.drawSprite() called even if sprite is not dirty. #14

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
For some reason, drawSprite() is called more than necessary in a Sprite. I
made a test on FilledSprite, but there should be a problem with other types
of sprites too. 

What steps will reproduce the problem?
1. add a trace in FilledSprite.drawSprite().
 System.out.println("redrawing FilledSprite").
2. create a small example:
public void load() {
    sprite = new FilledSprite(Colors.BLACK);
    add(sprite);
    photo1 = new ImageSprite("photo1.png", 0, 0);
    add(photo1);
 }
 public void update(int elapsedTime) {
   if(Input.isPressed(Input.KEY_SPACE)) {
    photo1.x.animateTo(10, 1000);
    }
3. run the app. Hit space
4. You see in the console that FilledSprite is drawn 10 times during the
animation. BUT this shouldn't be the case because it's not dirty. The only
way the method should be called is by changing one of it's property
(height, width, x, y  or fillColor). Other cases shouldn't redraw this sprite.

What is the expected output? What do you see instead?
drawSprite should be call only once in this example.

Original issue reported on code.google.com by florent....@gmail.com on 5 Apr 2009 at 5:28

GoogleCodeExporter commented 9 years ago
Not a bug - the portion of the FilledSprite underneath the ImageSprite is 
redrawn as the ImageSprite moves. 
(The scene is drawn back-to-front) The clip of the CoreGraphics instance 
contains the bounds of the dirty 
rectangle. 
A dirty-rectangle optimization would be to check if the ImageSprite is opaque, 
and if so, not draw the portion of 
the FilledSprite directly underneath the new location of ImageSprite. However, 
a portion of the FilledSprite would 
still need to be drawn as the ImageSprite moves to show what was underneath the 
old location of the 
ImageSprite.

Original comment by brack...@gmail.com on 5 Apr 2009 at 5:41

GoogleCodeExporter commented 9 years ago
OK. Thanks for the precisions.

Maybe a dumb question but : Is there a way to know if a drawSprite() is called
because it was dirty or because it was underneath a sprite that changed ?
checking the isDirty() method into the drawSprite() always give 'false'. Is 
there any
other flag to test or a way to know if a Sprite is redrawn because one of its
property changed ?

Thanks for the help

Original comment by florent....@gmail.com on 5 Apr 2009 at 6:01

GoogleCodeExporter commented 9 years ago
No, there's no way to tell. It could be dirty, something over/under could be 
dirty, its filter could be dirty, its 
parent could be dirty, something nearby could be dirty (Scene2D expands dirty 
rects in some cases) or it could 
be a full-scene redraw. Also, a sprite's drawSprite() method can be called 
multiple times per frame - once for 
each dirty rectangle.

You can, however, get the dirty rectangle in drawSprite() - it's the 
CoreGraphics' clip.

Original comment by brack...@gmail.com on 5 Apr 2009 at 6:20