Change object by pressing button while showing animation

edited May 2014 in How To...


I'm trying to add animation in my code. What I have so far is an object that can be changed by pressing a button. So every time you press the button, the object changes (it is a tree and I'm changing its branches). Is it possible to add some kind of animation like snow? The problem with that is that I have to put it inside the draw method so it will be called automatically and make us think that it is animation. Thus, I also have to add the background / button and everything all the time. But I can't do that with my main object (tree) as I want to change it only when you press the button.

Is there any solution to that?

Thanks in advance


  • Redraw the button and tree each time too. This comes up a lot. It's not usually wasteful to redraw the whole scene. You'll probably need some variables that remember the state of the tree. If your tree really is too complex to store in variables, consider storing the resulting image of a tree in a PImage.

  • edited May 2014

    This online example shows how to create a static background PImage.
    So only the actual dynamic drawings need to be rendered upon it:

Sign In or Register to comment.