Slick Forums

Discuss the Slick 2D Library
It is currently Tue Oct 15, 2019 1:04 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Sun May 01, 2011 9:37 pm 
Offline

Joined: Wed Mar 30, 2011 12:46 am
Posts: 1
I've noticed this problem a few times. It seems like isKeyPressed is being cached... or something. It's hard to describe.

Here is a portion of code:

Code:
  public void tick(int d) {
    dt = d;
   
    if (this.transitioning >= 0) {
      transitionRoom();
      return;
    }
   
    if (input.isKeyPressed(Input.KEY_S)) {
      sound.playSound("la_sword" + (int)(Math.random()*4+1) + ".wav");
    }
  }


What is basically coded is if the player is transitioning, return the function and don't perform any more player actions.

Here, you can try the game I'm working on:
http://dustyshouri.dreamhosters.com/LAdebug.zip

You can easily reproduce the effect by walking out of the scene, and while the scene is transitioning, press S. It will play the sword sound AFTER the transition is done. This sort of caching is happening all over the place.

I don't -think- it's from poor coding, but it may be... but I definitely think something weird is going on here. If I change the isKeyPressed() to isKeyDown() the problem disappears.


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 07, 2011 5:33 pm 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
The nature of isKeyPressed *is* that it's cached, thats the point of the method - it will hold the state until you check it.

Kev


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

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:  
cron
Powered by phpBB® Forum Software © phpBB Group