Slick Forums

Discuss the Slick 2D Library
It is currently Sun May 19, 2013 8:12 pm

All times are UTC




Post new topic Reply to topic  [ 170 posts ]  Go to page Previous  1 ... 3, 4, 5, 6, 7, 8, 9 ... 12  Next
Author Message
 Post subject:
PostPosted: Mon Jul 11, 2011 12:05 pm 
Offline

Joined: Wed Jun 29, 2011 5:55 am
Posts: 32
Location: United States
Thanks so much! I can't believe that ... well, after you told me to check that, I went back and looked at it, and still didn't think that this was my issue. Sigh.

If you're not sick of me yet, I have two issues:

1) My character has a running animation that is 9 frames long. If I run for 3 frames, but then stop, the next time I switch currentAnim back to the running animation, it starts at frame 4, not the first frame.

2) I don't know where the gap in my logic is, but if I press right or left, my character enters the correct running animation, but it only executes that animation for one frame, and then goes back to the standing animation, despite moving correctly.

Here's the relevant code:

SetupAnimations():

Code:
private void setupAnimations() throws SlickException
   {
      // TODO Auto-generated method stub
      SpriteSheet standingSheet = ResourceManager.getSpriteSheet("standingSheet");
      SpriteSheet runningSheet = ResourceManager.getSpriteSheet("runningSheet");

      setGraphic(standingSheet);

//      duration = 150;

      addAnimation("StandingRight", true, 0, 0, 1, 2);
      addAnimation("StandingLeft", true, 1, 0, 1, 2);
      addAnimation(runningSheet, "RunningRight", true, 0, 0,1,2,3,4,5,6,7,8);
      addAnimation(runningSheet, "RunningLeft", true, 1, 0,1,2,3,4,5,6,7,8);
      
      currentAnim = "StandingRight";
   }


update():
Code:
public void update(GameContainer container, int delta)
         throws SlickException
   {
      
      super.update(container, delta);

      onWall = false;
      onGround = false;

      if (collide(SOLID, x, y + 1) != null)
      {
         onGround = true;
         canDoubleJump = true;
      }

      else
      {
         if ((collide(SOLID, x + 1, y) != null && check(CMD_RIGHT))
               || (collide(SOLID, x - 1, y) != null && check(CMD_LEFT))
               && !onGround)
         {
            Log.info("OnWall is true");
            onWall = true;
            canDoubleJump = true;

            // TODO slow down movement when hugging the wall

            // set up for wall jump
         }

         // initiating air-dashing
         if (check(CMD_DASH) && canAirDash)
         {
            currentSpeedModel = DASH_SPEED;
            isAirDashing = true;
            canAirDash = false;

         }
      }
      
      acceleration.x = 0;

      handleInput();

      // set the gravity
      gravity(delta);

      // make sure we're not going too fast vertically
      // the reason we don't stop the player from moving too fast left/right
      // is because
      // that would (partially) destroy the wall jumping. Instead, we just
      // make sure the player,
      // using the arrow keys, can't go faster than the max speed, and if we
      // are going faster
      // than the max speed, decrease it with friction slowly.
      maxspeed(false, true);

      // variable jumping (triple gravity)
      if (speed.y < 0 && !check(CMD_JUMP))
      {
         gravity(delta);
         gravity(delta);
      }

      // set the motion. We set this later so it stops all movement if we
      // should be stopped
      motion(true, true);

      previousx = x;
      previousy = y;

   }


handleInput():

Code:

private void handleInput()
   {
      if (check(CMD_RIGHT) && speed.x < maxSpeed.x)
      {
         acceleration.x = moveSpeed;
         
         facingRight = true;
         
         if(pressed(CMD_RIGHT) && onGround)
         {
            currentAnim = "RunningRight";
            
         }
      }
      
      
      
      
      else if (check(CMD_LEFT) && speed.x > -maxSpeed.x)
      {
         acceleration.x = -moveSpeed;
         
         facingRight = false;
         
         if(pressed(CMD_LEFT) && onGround)
         {
            currentAnim = "RunningLeft";
            
         }
                  
      }
      
      else
      {
         currentAnim = facingRight ? "StandingRight" : "StandingLeft";
      }

      // friction (apply if we're not moving, or if our speed.x is larger than
      // maxspeed)
      
      if ((!check(CMD_LEFT) && !check(CMD_RIGHT)) && !isDashing
            || Math.abs(speed.x) > maxSpeed.x)
      {
         friction(true, false);
      }

      // jump
      if (pressed(CMD_JUMP))
      {
         // normal jump
         if (onGround)
         {
            jump();
         }

         // double jump
         if (!onGround && canDoubleJump)
         {
            jump();
            canDoubleJump = false;
         }
      }

      // dash button is pressed
      if (pressed(CMD_DASH))
      {
         dash();
      }

      // the dash button is still held down
      else if (isDown(CMD_DASH) && canDash)
      {

      }

      // the dash button has been released
      else
      {
         currentSpeedModel = NORMAL_SPEED;
         canDash = true;
         isDashing = false;
      }
   }



Sorry I've got so damn many questions, but this is the first Java I've ever written, so I'm making tons of mistakes.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 11, 2011 6:45 pm 
Offline
Game Developer

Joined: Sun Nov 12, 2006 11:18 pm
Posts: 890
Location: Germany
1) Why do you think that the animation should begin with frame 0 again? An animation has some internal frame counter (currentFrame). If you want the animation to play again from the beginning you should restart the animation.
Code:
myEntity.animations.get("someAnimationName").restart();

should do the trick.

2) Phew. Much code :wink:
Let's try to approach it with logic:
- animation is only modified in method handleInput(). So that method is the key.
- you only switch back to the standing animation if those two conditions are wrong:
Code:
      if (check(CMD_RIGHT) && speed.x < maxSpeed.x)

and
Code:
      else if (check(CMD_LEFT) && speed.x > -maxSpeed.x)

because then you fall into the else part where you change currentAnim to some standing animation.

So assuming you still keep the finger on your direction key the only possible solution is that the second part of your conditions are false where you compare speed.x and maxSpeed.x.

I don't know how you modify these values.
Suggestion: add some debug statements (Log.debug("....")) and see what happens to your speed and maxSpeed values. That should point you in the right direction.

Hope that helps,
Tommy

_________________
Right Angle Games | Marte Engine
Back to the past | Star Cleaner | SpiderTrap


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 12, 2011 5:46 am 
Offline

Joined: Wed Jun 29, 2011 5:55 am
Posts: 32
Location: United States
Thanks again Tommy. I'm gonna have to buy you a Westvleteren 10 some time. My question about the animation restarting was simply because I had no understanding of the animation engine. I wanted to manually restart the animations, I just didn't know how. Thanks!

As for question 2, I think it's really going to come down to a ton of debugging output. I'll report back (in an edit to this post) when I've got it fixed, on the off chance that someone else runs into a similar situation.

Cheers!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 12, 2011 6:38 am 
Offline
Game Developer

Joined: Sun Nov 12, 2006 11:18 pm
Posts: 890
Location: Germany
Hmmmm, beer from belgium, yummy :lol:

In a former company I had a dispute with a belgian friend which country brews the best beer: germany or belgium.

He convinced me with a nice little collection of bottled beers from Brugge and Gent that the belgium beer is at least as good as the best german ones.

I've been in Brugge and Gent in some nice little breweries myself (back in '99) and I must admit that they brew some great beers!

Looking forward to it :wink:

Good luck on your debugging endeavour! If you're stuck shout for help!

_________________
Right Angle Games | Marte Engine
Back to the past | Star Cleaner | SpiderTrap


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 13, 2011 4:09 pm 
Offline

Joined: Wed Jun 29, 2011 5:55 am
Posts: 32
Location: United States
Hey Tommy, do you think that there is a large efficiency difference between setting a new one-off alarm every time you perform an action, or keeping a reference to one alarm, and just restarting it every time you need it?

I'm still very unfamiliar with where Java efficiency issues come from.

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 13, 2011 5:34 pm 
Offline
Game Developer

Joined: Sun Nov 12, 2006 11:18 pm
Posts: 890
Location: Germany
It depends :lol:

When your action is performed on every update() call I would say restart the existing alarm.
If your action is performed say every half a second or every 2 seconds you can easily create a new oneshot alarm on each action perform.

If you have thousand entities performing ten actions where each action requires an alarm I would again vote for restarting an existing one (per entity).

Creating a new alarm object is cheap performance wise. Creating many objects and thus initiating a garbage collect is always expensive.
So as long as we're talking about a few objects/alarms created occasionally (every second for example) you're completely fine.

But just to say it: restarting is indeed faster and avoids unnecessary object creation.

_________________
Right Angle Games | Marte Engine
Back to the past | Star Cleaner | SpiderTrap


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 18, 2011 10:28 pm 
Offline
Slick Zombie

Joined: Wed Apr 02, 2008 1:32 pm
Posts: 1313
Location: Italy
Note: I've just closed some issues on github, on dev branch (see first post), if anyone have suggestions, feel free to say something!

_________________
Blog | Last game Gravity Duck tribute | In progress Gravity Duck tribute


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 23, 2011 9:34 am 
Offline

Joined: Fri Jul 22, 2011 11:52 pm
Posts: 8
is there any possibility to use marte engine and the "World" class together with nifty?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 23, 2011 11:16 am 
Offline
Slick Zombie

Joined: Wed Apr 02, 2008 1:32 pm
Posts: 1313
Location: Italy
well, I see no problem, can you describe your scenario? Maybe I can help with an example project, something like MarteEngine+Nifty Hello world?

_________________
Blog | Last game Gravity Duck tribute | In progress Gravity Duck tribute


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 23, 2011 12:06 pm 
Offline

Joined: Fri Jul 22, 2011 11:52 pm
Posts: 8
Gornova81 wrote:
well, I see no problem, can you describe your scenario? Maybe I can help with an example project, something like MarteEngine+Nifty Hello world?


I think an example could really help me alot :)
Btw, shall i use Nifty or TWL? ;)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 27, 2011 9:30 pm 
Offline

Joined: Fri Jul 22, 2011 11:52 pm
Posts: 8
Okay, i decided to try TWL, but how to make a class that extends both marte-engine world class and TWLbasicgamestate?
How to do this? :?:


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 28, 2011 7:57 am 
Offline
Slick Zombie

Joined: Wed Apr 02, 2008 1:32 pm
Posts: 1313
Location: Italy
Because there is no multiple inheritance in java, you can use composition: put a world variable into your class that extends TWLBasicgamestate and then in render/update method, render and update world variable (init it first of course)

_________________
Blog | Last game Gravity Duck tribute | In progress Gravity Duck tribute


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 28, 2011 4:22 pm 
Offline

Joined: Fri Jul 22, 2011 11:52 pm
Posts: 8
I tried it but i failed.
when entering the InGameState, i create a new GameWorld but i always get this:

Thu Jul 28 18:19:14 CEST 2011 ERROR:no world set
org.newdawn.slick.SlickException: no world set
at it.marteEngine.ME.update(ME.java:83)
at it.marteEngine.World.update(World.java:206)
at GameWorld.update(GameWorld.java:211)
at InGameState.update(InGameState.java:77)
at org.newdawn.slick.state.StateBasedGame.update(StateBasedGame.java:268)
at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:663)
at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:411)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:321)
at Project_Islands.main(Project_Islands.java:67)


And what about input handling etc... does all of this work when i just call Gameworld.update() and Gameworld.render() ?


Is there no other possiblity to achieve marte engine and TWL?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 28, 2011 8:27 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1171
The TWLStateBasedGame and BasicTWLGameState (found on the wiki) are really simple classes - it should be no problem to change these to extend the MarteEngine classes instead.

I have never worked with ME before but TWL was designed to be verify flexible so it should be problem to adapt the wiki code to ME.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 30, 2011 2:37 am 
Offline

Joined: Fri Jul 22, 2011 11:52 pm
Posts: 8
MatthiasM wrote:
The TWLStateBasedGame and BasicTWLGameState (found on the wiki) are really simple classes - it should be no problem to change these to extend the MarteEngine classes instead.

I have never worked with ME before but TWL was designed to be verify flexible so it should be problem to adapt the wiki code to ME.


Okay i gave it a try, I have a TWLGameState class that extends World of marte engine, and my "GameWorld" class now extends TWLGameState.
But now, whenever super(ID, GameContainer) in the render() or update() method is called, i get this "no world set" error from above.
What did i do wrong?
:?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 170 posts ]  Go to page Previous  1 ... 3, 4, 5, 6, 7, 8, 9 ... 12  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group