Why is background() so much faster than image() ?

edited November 2015 in Programming Questions

I've got a game that has an animated starfield as the backdrop (stars randomly twinkle and fade out). It originally ran quite slow, around 37fps but eventually I found that if I took my Pgraphics object ("starfield") and placed it in a call to background(starfield), as opposed to image(starfield,0,0), it suddenly ran at 60fps without a problem. So my question is, why does using background() instead of image() make such a massive difference? It ran at 37 fps when I was trying to display an image using image() and 60 fps using background(). I'd like to understand this for future reference...

thanks!

Answers

  • Answer ✓
    • Both background() & set() merely raw dumps a PImage's pixels[] into a PGraphics.
    • No effects like alpha color, tint(), filter(), blend(), etc.
    • No transformations like translate(), scale(), etc.
    • Notice that it's restricted to JAVA2D renderer.
    • OpenGL-based renderers aren't good w/ bitmap access though.
Sign In or Register to comment.