473,378 Members | 1,680 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

go inside if statment onces every time.

59
in main. when user press space bar set 'space' to true.
if user let go of space bar set 'space' to false.

Expand|Select|Wrap|Line Numbers
  1. boolean space
  2. boolean shooting = false;
  3.  
  4. if(space && !shooting)
  5.         {    
  6.             //shoot bullets
  7.             shooting = true;
  8.         }
  9.         if(!space)
  10.         {
  11.             shooting = false;
  12.         }

when user hold space bar than it will only go inside this if statment onces. so it will shoot one bullet. if user want to shoot another bullet than they have to press the space bar again.

is their way to set same effect by only using space variable?

i tried this code below but it doesnt really work. bc this is in game loop so it will keep going in side it.
Expand|Select|Wrap|Line Numbers
  1. boolean space
  2. boolean shooting = false;
  3.  
  4. if(space)
  5.         {    
  6.             //shoot bullets
  7.         m.setSpace(false);
  8.  
Apr 13 '13 #1
1 1089
r035198x
13,262 8TB
You'll need to listen for keyPressed and keyReleased separately. In keyPressed start a loop that depends on a variable that is accessible in keyReleased so that you can stop the keyPressed loop from a keyReleased event.

http://docs.oracle.com/javase/tutori...ylistener.html
Apr 13 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Brian Henry | last post by:
This is just wierd... if I go to the MSDN web site and try to view an article like this... http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemwebhttpbrowsercapabilitiesclasstopic.asp ...
0
by: Chad | last post by:
I have COM component embedded on html page. It has version 1.0.0.1 (by default). I have converted it in cab file. Code of html is something like: <HTML><HEAD></HEAD><BODY><OBJECT...
0
by: seanick | last post by:
Hi, I was profiling one of my apps in depends.exe, and noticed the functions FlsAlloc, FlsFree, etc. being searched for every time that msvcr71.dll was loaded. I have seen it before too, but I...
0
by: sonic | last post by:
hello, I have this custom datagrid control, that inherits from DataGrid. In addition to datagrid, I am adding a "status" table under it, and another html button, which will trigger a new row. ...
11
by: Joseph S. | last post by:
Hi all, how do I avoid typing the keyword "$this->" every time I need to reference a member of a class inside the class? (coming from a world of cozy auto-complete enabled Java / .Net IDEs I...
3
by: palepimp | last post by:
Hello all, I have searched far and wide for a solution to my issue. In short, here is the problem: 1. 3 PC's enter data into an Access 2003 database (PC's are running Vista w/ Office 2007...
5
by: elbin | last post by:
Hello, first to say that I am a total beginner in Javascript but I know some programming (python in particular) and am able to understand methods/parameters and so on. Here's my problem: I am...
26
by: Ravindra.B | last post by:
I have declared a global variable which is array of pointers and allocated memory for each array variable by using malloc. Some thing similar to below... static char *arr; main() { int i;
4
by: Frank Lund | last post by:
Should we call .Dispose() every chance we get... on every object that exposes .Dispose()... and every time we have such an object? For example, is it true that *every* time I create a DataTable...
1
by: OBAFGKM_RNS | last post by:
In my html, I have an embedded sound wav. I access that sound from my javascript using Play() and Stop(). However, once stopped, the sound will aways resume from where it left off, (making Stop...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.