Java-Gaming.org
Java4K winners:
[
by our judges
|
by the community
]
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members
News
: Read the
Java Gaming Resources
, or peek at
the official Java tutorials
Home
Help
Search
Login
Register
Java-Gaming.org
>
Game Development
>
Game Play & Game Design
>
firing timer
Pages: [
1
]
Print
firing timer
(Read 980 times)
0 Members and 1 Guest are viewing this topic.
javatypo
Full Member
Posts: 143
firing timer
«
on:
2005-03-09 14:07:15
»
hey everyone, what im asking is fairly basic, but anyway here goes. in some of the space shooter games i made u always had to continually press the space bar to fire, but i want to make it so that u can press and hold the space bar, and it will fire bullets at a constant rate, but not so that it shoots them out really fast.
so what im asking is how would one go about coding up some sort of timer or something to do this? i usually just make a variable that counts miliseconds and then when i get a certain amount i fire the next shot, or do the next thing. but i was thinking that there must be a better or different way to do this.
thanks
Vorax
JGO Ninja
Posts: 666
Medals: 1
System shutting down in 5..4..3...
Re: firing timer
«
Reply #1 on:
2005-03-09 15:43:22
»
Set a time ahead variable something like:
private long nextShotTime = 0;
private static final int SHOT_DELAY = 100;
private void shoot() {
long currentTime = System.currentTimeMilleseconds();
if (currentTime >= nextShotTime) {
... fire your weapon here ...
nextShotTime = currentTime + SHOT_DELAY;
}
}
That's about it.
Vorax Games
|
Nibble's & Bits
|
VG Forums
javatypo
Full Member
Posts: 143
Re: firing timer
«
Reply #2 on:
2005-03-12 20:19:41
»
hmm cool. thats what i did for something else, i forget what.. but it was the same type of code.
thanks
Pages: [
1
]
Print
Jump to:
Please select a destination:
-----------------------------
Games Center
-----------------------------
=> Featured Games
=> Showcase
=> Contests
===> LWJGL16k - 2011
===> 4K Game Competition - 2012
===> JGO Comp Petite
===> Finished Contests
=====> 4K Game Competition - 2011
=====> 4K Game Competition - 2010
=====> 4K Game Competition - 2009
=====> 4K Game Competition - 2008
=====> 4K Game Competition - 2007
=====> 4K Game Competition - 2006
=====> 4K Game Competition - 2005
=====> Tiny Game 2010
=====> JGO Comp 2009
=====> 16K LWJGL Competition - 2005
=====> Java Technology Game Development Contest - 2004
-----------------------------
Discussions
-----------------------------
=> General Discussions
===> Suggestions
=> Business and Project Discussions
===> Jobs and Resumes
===> Community & Volunteer Projects
=> Miscellaneous Topics
-----------------------------
Game Development
-----------------------------
=> Newbie & Debugging Questions
=> Articles & tutorials
=> Game Play & Game Design
=> Game Mechanics
===> Artificial Intelligence
=> Networking & Multiplayer
=> Performance Tuning
=> Shared Code
-----------------------------
Java Game APIs & Engines
-----------------------------
=> Engines, Libraries and Tools
===> Java 3D
===> JInput
===> jMonkeyEngine
===> Xith3D Forums
===> Tools Discussion
=> Java 2D
===> JavaFX
=> OpenGL Development
===> JOGL Development
===> LWJGL Development
=> Java Sound & OpenAL
===> JOAL Development
=> Java on Mobile Devices
===> Android
===> J2ME
Loading...