Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (115)
games submitted by our members
Games in WIP (562)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  translate and animate simultaneously  (Read 290 times)
0 Members and 1 Guest are viewing this topic.
Offline herah

Senior Newbie





« Posted 2013-03-26 23:50:17 »

I am having trouble with getting my animations to work while my characters are moving. I have a player, who will run right and left. When he starts to run either direction, the animation starts, and stops after about 1 second then wont start again unless I let go of the run button and press it again. The zombies will only translate across the screen until they reach their destination then they will stand in place and animate. I need them to animate and translate simultaneously. Can anyone spot the error? I had this working before I cannot figure out how I messed it up!

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
   public NinjaSprite(ImagesLoader im, String name, int p) {
      super(Variables.pWidth/2, 0, Variables.pWidth, Variables.pHeight, im, name);
      setStep(5,0);
      locy = Variables.pHeight/2 + 25;
      period = p;
   } // end of ninja sprite

    public void moveLeft()
     /* Request that the sprite move to the left. It doesn't
        actually move, but changes its image and status flags. */

     { setImage("leftPlayer");
     System.out.println("player period: " + period);
       loopImage(period, DURATION);   // cycle through the images
      isFacingRight = false;  isStill = false;
       super.updateSprite();
     }

     public void moveRight()
     /* Request that the sprite move to the right. It doesn't
        actually move, but changes its image and status flags. */

     { setImage("rightPlayer");
       loopImage(period, DURATION);   // cycle through the images
      isFacingRight = true;  isStill = false;
       super.updateSprite();
     }

     public void stayStill()
     /* Request that the sprite stops. It stops the
        image animation and sets the isStill status flag. */

     { stopLooping();
       isStill = true;
     }


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
public class Zombie extends Sprite{
private String zName;

   public Zombie(int x, ImagesLoader imsld, String name, int p){
      super(Variables.pWidth/2, 0, Variables.pWidth, Variables.pHeight, imsld, name);
      period = p;
      locx = x;
      zName = name;
      setStep(1,0);
      System.out.println("zombie period " + period);
   }  
   public void move(int target){ // zombies attempt to move towards the player
     if(locx > target){
         this.setImage(zName);
         locx -= Variables.zombieSpeed;
         loopImage(period, DURATION);   // cycle through the images
        }
      else if(locx < target){
         this.setImage(zName);
         locx += Variables.zombieSpeed;
         loopImage(period, DURATION);   // cycle through the images
     }
   } //end of updateSprite
}
Offline philfrei
« Reply #1 - Posted 2013-03-27 01:11:48 »

For the Zombies -- I'm guessing that you keep restarting loopImage() over and over until "locx = target", after which the routine finally gets a chance to play out.

Probably the same thing with Ninja. And it doesn't move because there is no locx change included outside of the loopImage() as there is with the Zombie.

"Greetings my friends! We are all interested in the future, for that is where you and I are going to spend the rest of our lives!" -- The Amazing Criswell
Offline Slyntax

Junior Member


Medals: 3



« Reply #2 - Posted 2013-03-27 03:21:40 »

Edit: Nevermind I was reading the code wrong.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

radar3301 (10 views)
2014-09-21 23:33:17

BurntPizza (28 views)
2014-09-21 02:42:18

BurntPizza (18 views)
2014-09-21 01:30:30

moogie (20 views)
2014-09-21 00:26:15

UprightPath (27 views)
2014-09-20 20:14:06

BurntPizza (29 views)
2014-09-19 03:14:18

Dwinin (46 views)
2014-09-12 09:08:26

Norakomi (74 views)
2014-09-10 13:57:51

TehJavaDev (102 views)
2014-09-10 06:39:09

Tekkerue (50 views)
2014-09-09 02:24:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!