1

I am trying to get animated water tile and I cannot figure it out..

Here, I try to use the modulus to get the remainder and switch it from there, I set it up like I would in my player walking animation. Here is the code I try to use to get it to fluctuate.

public void update() {
    if (anim < 1000000) anim++;
    else anim = 0;

    if(anim % 30 > 20) {
        sprite = Sprite.water_;
    } else {
        sprite = Sprite.water;
    }
}

Then within my Main class I put in private WaterTile water; and called it, and put it in my update() method but it decides to not work.

If you would like to look at my overall code, here are my classes involved..:

Shzylo
  • 303
  • 1
  • 3
  • 13
  • 1
    Are you using `Swing or AWT` ? If `Swing` then please remove `Canvas` and put `JPanel` and draw inside it's [__paintComponent(Graphics g)__](http://docs.oracle.com/javase/7/docs/api/javax/swing/JComponent.html#paintComponent(java.awt.Graphics)) method. – nIcE cOw Jun 30 '13 at 04:30
  • would I have to rewrite my whole engine then? – Shzylo Jun 30 '13 at 04:39
  • 2
    Your `Game` class is extending `Canvas` so I guess only that class needs to use `JPanel`. The main advantage of using `JPanel` is using the full potential of Swing, which is [Double Buffering](http://docs.oracle.com/javase/tutorial/extra/fullscreen/doublebuf.html) – nIcE cOw Jun 30 '13 at 04:59
  • 1
    For better help sooner, post an [SSCCE](http://sscce.org/) direct to SO. – Andrew Thompson Jun 30 '13 at 06:27
  • 1
    Have a look at [Game Development Loop, Logic and Collision detection Java Swing 2D](http://www.daniweb.com/software-development/java/code/444547/game-development-loop-logic-and-collision-detection-java-swing-2d). It has most things for a 2D game, including *Animator class*. – David Kroukamp Jun 30 '13 at 07:31
  • 2
    In your [sscce](http://sscce.org/), access images posted here via `URL`, as shown [here](http://stackoverflow.com/a/10862262/230513). – trashgod Jun 30 '13 at 11:26

0 Answers0