Results 1 to 2 of 2
- 01-14-2011, 11:46 AM #1
Member
- Join Date
- Jan 2011
- Posts
- 5
- Rep Power
- 0
How to catch a value that changes all the time?
Hi guys ^_^
I'm wondering how to catch a value before it changes?
in another word, how to save a specific value so that when it changes, my saved value doesn't change?
for example:
if I have:
and I want to save the value of it(10) in another varible.Java Code:int y = 10;
so that when y changes(to 15 for example), x doesn't change.Java Code:int x = y;
another example:
here i'm developing a game and I want to save the coordinate of the pistol so that the bullet fired from the right place.Java Code:int x = pistolX2 + 10; int y = pistolY2 + 2;
the problem is, when the bullet fired, and the character moved, pistolX&Y will change, and that will effect the direction of the bullet (since it's dependent on the pistol X&Y).
So, how to make my x&y independent from pistolX&Y?
thanks. :)
- 01-14-2011, 11:53 AM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
x wouldn't change there anyway.
By creating a "Trajectory" class, or something like that, that conatins the original coordinates (and probably the calculation methods as well) and do your "calculations" using those saved coordinates.another example:
here i'm developing a game and I want to save the coordinate of the pistol so that the bullet fired from the right place.Java Code:int x = pistolX2 + 10; int y = pistolY2 + 2;
the problem is, when the bullet fired, and the character moved, pistolX&Y will change, and that will effect the direction of the bullet (since it's dependent on the pistol X&Y).
So, how to make my x&y independent from pistolX&Y?
thanks. :)
Edit: Then again, you don't need the coordinates of the pistol anyway. As long as the "bullet" knows where it is, and the trajectory its on (i.e. the direction it is going), that's all you need.Last edited by masijade; 01-14-2011 at 11:56 AM.
Similar Threads
-
JAVA Programmers Wanted - Full-Time and Part-Time Positions open
By javatrek2020 in forum Jobs OfferedReplies: 3Last Post: 08-23-2011, 12:46 PM -
calculate time diff for particular time period
By baktha.thalapathy in forum New To JavaReplies: 2Last Post: 05-24-2010, 04:10 PM -
Class Time - represents time of day
By verbazon in forum New To JavaReplies: 1Last Post: 04-13-2009, 01:06 AM -
how to catch two exceptions in one catch()?
By arnab321 in forum New To JavaReplies: 1Last Post: 11-06-2008, 10:54 AM -
Try Catch
By Renegade85 in forum New To JavaReplies: 4Last Post: 12-03-2007, 04:10 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks