Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (580)
games submitted by our members
Games in WIP (500)
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  
  How to Control the "Button is pressed" ?  (Read 1167 times)
0 Members and 1 Guest are viewing this topic.
Offline Andre Lopes
« Posted 2013-05-10 21:38:41 »

Hola como estas?
"Except you give me something i can feeeeeeel" 
ok sorry for that , anyway haha :

I have a little problem... in game update i have this :


If i press backspace just one time , it shoots 3 missiles in one time... How can i control that? i want a delay.. i tried to make some System.currentmilis etc but, well, i couldnt make it work.

I was looking for some gdx method to tell me when the button is released but couldnt find it.

How can i "fix" that ?

Cheesy



Offline alaslipknot
« Reply #1 - Posted 2013-05-10 22:07:40 »

1) you should post in newbie, debugging, questions section

2) don't give us screen shot of your code, because it's not clear and in case we want to test it, no one will re-write it, plus your screen shot is completely useless it has ZERO information on it .

now for your question, this is how it works to make a "delay"

1)create a loading variable (integer) 
2)create a counter variable (integer)
3)when you make a shot, the counter variable increase, in the current time, you disable shooting until the counter is equal to the loading variable
4)once they are equal, you make the counter equal to zero again

in case you want a working example, check the player class in this tutorial i wrote about moving and shooting bullets, it's in Java2D but the principles are the same     

Am trying ...
hoping that it works
Offline NegativeZero

JGO Coder


Medals: 14
Projects: 2


Zero but not.


« Reply #2 - Posted 2013-05-11 00:14:40 »

To reiterate what alaslip said, here's some pseudo code:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
int counter = 0
int startFiring = 5
update {
   if Key_Pressed {
      if counter = 0 {
         fire missile
      }  
      else {
         counter + 1
      }
   }
   if counter > startFiring {
      counter = 0
   }
}
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Zhon

Junior Member


Medals: 4



« Reply #3 - Posted 2013-05-11 00:58:57 »

Correct me if I'm wrong, but in that way /\ the counter is gonna update only when the key is pressed.
Shouldn't the counter update even if the key is down? something like
1  
2  
3  
4  
5  
counter = counter > 0 ? counter - 1 : counter;
if (counter == 0 && keydown){
fireMissile();
counter = 5;
}
Offline Andre Lopes
« Reply #4 - Posted 2013-05-11 04:38:59 »

1) Dont need to be mean

2) if everyone here were Pro's , we wouldnt need a forum.

3) ZERO information? Well, you need learn to read topics and interpret and be a little more nice to newcomers.

Thanks for the help.


Offline HeroesGraveDev

JGO Kernel


Medals: 212
Projects: 11
Exp: 2 years


If it wasn't Awesome, it wasn't me.


« Reply #5 - Posted 2013-05-11 05:01:47 »

@Andre Lopes:

Don't worry, quite a few new people become like that on the forum. It either wears off after a few weeks/months or they just disappear.

Offline Andre Lopes
« Reply #6 - Posted 2013-05-11 05:05:36 »

Im sorry i got mad, its just that, i came so peacefully and with happiness to this forum... And now to be trolled seems unfair.

Anyway, i will do this counter strategy tommorow morning, i think it will work perfectly Tongue

Offline HeroesGraveDev

JGO Kernel


Medals: 212
Projects: 11
Exp: 2 years


If it wasn't Awesome, it wasn't me.


« Reply #7 - Posted 2013-05-11 05:15:36 »

Im sorry i got mad, its just that, i came so peacefully and with happiness to this forum... And now to be trolled seems unfair.

I wasn't referring to you.

I too am annoyed at people who respond like that, even when it's not my question.

Online Jimmt
« League of Dukes »

JGO Kernel


Medals: 114
Projects: 4
Exp: 3 years



« Reply #8 - Posted 2013-05-11 05:27:26 »

See, it pisses me off when I see noobs acting all high and mighty to other newbies. If Riven/princec/other pros don't do it there's no reason for you to.
Offline Z-Man
« Reply #9 - Posted 2013-05-11 05:30:18 »

While alasipknot is correct, he could've been a little nicer. New people don't know any better so it is good to inform them, but in a nicer way. "Hey, welcome to JGO! *answer question* and for future reference posts like this go in *insert board here*" or something like that.
EDIT: Also, take a page out of Cas' book and use a lot of smileys Grin they always help


On topic:
Another approach would be to have a set fire rate and simply check the time since you've last fired. The fire rate would be some amount of time, and you would need to initialize it somewhere. Then simply store a lastFire for the last time you fired. For example:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
// I suggest using System.nanoTime() instead of System.currentTimeMillis() as the millis timer resolution isn't very good

private fireRate = 1000000000; // This is 1 second in nanoseconds
private lastFire = System.nanoTime() - fireRate;

public void fire() {
   if(System.nanoTime() - lastFire >= fireRate) {
      // fire code
     lastFire = System.nanoTime();
   }
}
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline alaslipknot
« Reply #10 - Posted 2013-05-11 07:47:12 »

i didn't mean any harm at all   Undecided
plus i don't think that i said something wrong ...  and i also answered his question
so why so serious guys ??

@Andre Lopes
sorry if i offended you

Am trying ...
hoping that it works
Offline heisenbergman

JGO Coder


Medals: 14
Projects: 1


L___ o_ G___ a__ P___


« Reply #11 - Posted 2013-05-11 08:22:22 »

Yeah, dunnno why Andre reacted the way he did, I felt alaslipknot didn't say or mean anything negative.

alaslipknot's answer was not all rainbows and unicorns, but very informative and helpful.

Offline HeroesGraveDev

JGO Kernel


Medals: 212
Projects: 11
Exp: 2 years


If it wasn't Awesome, it wasn't me.


« Reply #12 - Posted 2013-05-11 08:55:42 »

Just that post alone means nothing.

But when put in the context of some of his previous posts, you see some of the tone behind it, and the tone isn't very nice.

Offline Cero
« Reply #13 - Posted 2013-05-11 09:59:13 »

Yo Andre, dont listen to them.
You could do something with a delay and stuff. But let me first introduce to InputAdapter

Now Gdx.input.isKeyPressed tells you if the key is down
The InputAdapter das a keydown and keyup method, which are only invokes once. Once you press and once you let go, respectively.

You write a small class extending InputAdapter or implementing InputProcessor, I would recommend at the end of you game class, so that you have access to game things.

and in you create() method you have to call Gdx.input.setInputProcessor(INSTANCE OF YOUR INPUTADAPTER CLASS)

if you have any follow-up questions, dont hesitate.

Offline Andre Lopes
« Reply #14 - Posted 2013-05-12 03:53:23 »

Guys, thanks Tongue
It worked perfectly, i did the counter strategy, i will try the input processor later.

Thanks!!! i will make another topic in newbies because im having problems finding rectangle intersection collision method oin libgdx.
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.

xsi3rr4x (50 views)
2014-04-15 18:08:23

BurntPizza (46 views)
2014-04-15 03:46:01

UprightPath (62 views)
2014-04-14 17:39:50

UprightPath (44 views)
2014-04-14 17:35:47

Porlus (61 views)
2014-04-14 15:48:38

tom_mai78101 (84 views)
2014-04-10 04:04:31

BurntPizza (142 views)
2014-04-08 23:06:04

tom_mai78101 (242 views)
2014-04-05 13:34:39

trollwarrior1 (201 views)
2014-04-04 12:06:45

CJLetsGame (208 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!