Pacman open/close mouth animation

前端 未结 3 2122
死守一世寂寞
死守一世寂寞 2020-11-30 13:35

I want to make the pacman open/close mouth animation using the easiest method. Here is my recent code: The problem is, nothing is happening?

package ordner;
         


        
3条回答
  •  一生所求
    2020-11-30 14:10

    For the animation, you could use a Swing Timer to move the Pacman graphic as well as adjusting the angle by which the "mouth" opens, by varying the parameters used by fillArc.

    Interaction with KeyEvents for movement control can be acheived using Key Bindings.

    Also, I would move the paint functionality to a paintComponent method in a sub-classed JComponent for better paint performance.

    Related: Painting with Swing


    Edit:

    As youre starting Java there are a number of tasks to get working first

    1. Create the JComponent based class with a static Pacman graphic. Move your painting logic to paintComponent
    2. Get the Swing Timer functionality working. Follow the Oracle guide for Timers.
    3. Implement the Key Bindings
    4. Other functionality such as score keeping, etc.

提交回复
热议问题