Mouse tracking incorrect positions?

Currently working on a 2D shooting game, that looks like the old Liero.
I'v stumbeled up on a problem, the mouse positions i get seems to be wrong, or im missunderstanding something about it.
Inside my MouseMoveListener:
   public void mouseMoved(MouseEvent e) {
      player.reportCurrentMousePosition(new Point((int)e.getPoint().getX(),(int)e.getPoint().getY()));
   }Inside the player object:
   public void reportCurrentMousePosition(Point poss) {
      this.currentMousePos = poss;
   }And the drawing in player:
g.drawLine(locationX, locationY, (int)currentMousePos.getX(), (int)currentMousePos.getY());The line that im drawing, misses the cursor.. Anyone have any idea why?
As i am also fiering bullets using the same position, it also seems to be out of position.
Bullet path code:
   public void move() {
      double angle = Math.atan2(getDestinationY(), getDestinationX());
      double ySpeed = Math.sin(angle) * getSpeed();
      double xSpeed = Math.cos(angle) * getSpeed();
      this.setLocationX((int) (this.getLocationX() + xSpeed));
      this.setLocationY((int) (this.getLocationY() + ySpeed));
   }Where getDestinationX() and getDestinationY() is the mouse pointer position.
Anyone have any clue whats wrong?

Fixed the problem with the line.. I had to add the mousemovelistener to the panel instead of the JFrame..
Stupid misstake..
But still have the problem with the bullets.. Even when i add the mouselistener to the JPanel.
The problem is that when i shoot bullets, it can hit the spot where the mouse is, but if i move the mouse a little, it still shoots at the old position..
I have checked, and it is a different position that gets recorded.. But it seems like the bullets only shoot in some angle..
So if i dragg the mouse even further away from the first working position, then it works again..
[Picture example|http://www.aralll.net/javaHelp.png]
Check the picture, and you'll see the red line, is where the mouse is, and it should be blue dots (bullets) in the middle there aswell..
But as you can see, it only takes in 2 lines there, up, and a little to the side.. Never in the middle..

Similar Messages

  • Crosshair mouse tracker on Plot Chart

    Hi All,
    I have implemented a flex plot chart, which works fine (able to plot items to it).  I want to add a cross hair tracking device that will move along with the mouse.  The cross hair will draw a simple horizontal and vertical line crossing at the mouse pointer to the edges of the chart.  I already have registered for the mouse move event (I have a status line that prints the real world values based on x/y position as the mouse moves).  The crosshair implementation I have tried implementing causes the mouse tracking to act very strange...almost, in a lagging type behaviour.  I am using a Graphics object from the plot chart object.  I do a clear each time before I redraw the crosshair (as the mouse moves).  The 'clear' seems to be the core of the lag problem (if I comment out the 'clear', the tracking works fine..but of course the crosshair from the previous mouse position doesnt erase).  I didnt see an 'xor' type of function which is what I have used on like projects before. Any ideas or suggestions would be greatly appreciated.
    my plot char is  called tlat_chart.
    var G:Graphics = tlat_chart.graphics;
    G.clear();
    G.moveTo(somex, somey);
    G.lineTo(newx, somey);
    etc......

    Take a look at Eli's custom chart annotations here: http://demo.quietlyscheming.com/ChartSampler/app.html

  • Mouse Tracking Problem

    I've had my mac for quite a while and one of the only problems I have is with the mouse's acceleration. I know how to turn the speed up in sys. prefs. and the speed once I get it moving is fine. Except you can notice that as you move the cursor slowly it only moves very slowly on screen. And the same for faster quite obviously. The point here is that when you go to move the cursor to where you want it slows down dramatically as you reach the desired position, instead of maintaining its velocity despite the mouse's actual speed.
    Is there someway to override this inconsisent acceleration/tracking speed. Sure the default way the mouse tracking speed is set in osx is great and moves rather smoothly, I would prefer it to move rigidly.
    There have been other posts on this problem, none of which were resolved easily or without purchasing 3rd party apps. Please clearly read this issue I and other experience thoroughly so that this post doesnt end up with bad resolutions as others have. Thanks very much for your help in advance, and feel free to ask any questions if I've been unclear in what I'm actually asking.

    The following from: http://forums.macosxhints.com/
    Okay. I went back and found an old trick that never worked for me before but now it does. You need to edit the user/library/preferences/.globalpreferences.plist. This file is invisible. What I did was open it with SNAX (it can show invisible files) by dragging the pref file onto TextEdit's Dock icon. You could also use TinkerTool to make the file visible or perhaps do the whole thing in the Terminal.
    Look for a couple lines that looks like this:
    <key>com.apple.mouse.scaling</key>
    <real>1.000000000000000e+00</real>
    [the first digits might be "1.7" or something depending on how you've got your mouse speed set]
    Change the last part to look like this:
    <real>1.000000000000000e+05</real>
    This should bring the acceleration tracking curve to "normal." You can try changing the first part to speed up the mouse like this:
    <real>4.500000000000000e+05</real>
    You need to log out for the changes to take effect. If you go to the mouse System Preference and change a thing it will overwrite your changes and you're back to square one. I'm not sure that I've had much success in changing the mouse speed but the more annoying thing, the weird acceleratin curve, is fixed.

  • In need of a Mighty Mouse Track Ball

    Something small and hard, fell in the mouse track ball area and while i was pressing it (upside down) on a piece of paper to clean it, that little hard piece of dust, carved the surface of my track ball making it unable to scroll without jumping around!
    So im now in the need of purchasing a new ball and replacing it! Does the ball as a part exist? Because i can't find anything on ebay! Any help?

    What exactly am i looking for in the "about this Mac" specs? I mean i have found the mouses info, i think this is it:
    but what numbers must be used in order to locate it from mouseballz website?

  • Mighty Mouse Track Ball

    Does any one else have issues with the mighty mouse track ball?? My does not work half the time. When it is working it will only work in one direction half of that time.
    Does anyone know of ways to clean it?? Or keep this from happening?
    Cameron
    MBP 15.4"   Mac OS X (10.4.8)  

    I've read all the posting about this..in recent months I've been cleaning the track ball 6,7,8,9....times every day. I had planned to buy a wireless Mighty Mouse but not now, it'd be cheaper to sit in front of my Mac bashing my testicles with a mallet for the same effect. Apple, this is an utter design disaster. Like Joachim says, why not a mouse we can open and clean easily, or a larger, more robust track ball mechanism? I'm off to but a mouse by anyone but Apple...
    G5 i-Mac   Mac OS X (10.4.9)  

  • Mouse tracking always reset to a specific area point

    Hi,
    My iMac mouse always reset to a specific area of my screen every time I move it.
    I thought that it was the magic mouse tracking that was bugging but it's not : the same problem occurs when I'm using the ScreenSharing app with my computer on sharing mode.
    I tried to restart the computer, empty the PRAM after unplugging the computer but nothing worked..
    Here's the specs of my iMac :
    iMac 27-inch, Late 2012
    3,4 GHz Intel Core i7
    32 Gb of ram
    NVIDIA GeForce GTX 680MX 2048 Mb
    OS X Yosemite 10.10.1
    Someone could help me please?

    Everything is ok finally : I haven't seen that the pen of my graphic tablet was layed down on it..! -_-

  • IMAC 27 - attached a second monitor - mouse tracking problem

    After attaching a 19 inch lcd via the mini display port and a dvi adapter my mouse tracking has gone bad, not just from one screen to the other even just on the main screen if you move the mouse around it jumps several inches and is very inaccurate. problem goes away when the second mointor is unpluged.
    Can anyone help?
    Stephen

    I'll add to the chorus: I have the 27" iMac, and I get the same mouse jumpiness when I connect my 24" Acer P244W display via the Mini DisplayPort-DVI adapter. Oddly enough, the mouse jumpiness is more pronounced when I use my old wired MS Intellimouse Optical than when I use the included Magic Mouse. I've confirmed with another Mac (and with this Mac minus the second display) that the wired mouse is functioning normally.
    Basically, given slow, constant mouse movement, the cursor will hiccough for about a tenth of a second once every 1.0 seconds, like clockwork. Given more normal use, the cursor will continue to hiccough every second and will also occasionally jump to a completely unrelated location on the screen. (The wired mouse was the worse off here, jumping unpredictably several times a minute.)
    I've unplugged the secondary display for now, but I kinda sorta really need it for Flash and video work. Apple, help!

  • Keyboard & Mouse Settings - Mouse Tracking Problem

    Whenever I change the tracking setting for my mighty mouse in system preferences it works fine, but as soon as I close system preferences the tracking setting reverts to the default setting. I tried altering various settings and they all remain as I set them when I close system preferences, but the mouse tracking setting is the only one that will not remain as I set it. I tried changing the setting in Terminal, but it will not work that way either. Then I downloaded MouseZoom thinking that maybe it would work, but it also works fine until you close system preferences. Any input would be greatly appreciated.

    Have you tried repairing permissions?
    If that doesn't work try downloading Onyx
    http://www.titanium.free.fr/pgs2/english/onyx.html
    Run these scripts in the 'Cleaning' Tab
    * User Caches
    * System Caches
    * Core Files
    * Temporary Files
    See if that works for ya.
    Good Luck
    -Steve

  • Airport/freezing/mouse track won't work

    Hey guys, I'm wondering if you could help with my iBook G4. I'm beginning to get seriously annoyed with it. I bought it back in September and it was fine up until recently where it has begun crashing. It tells me that I need to push down the power button to power down. When that happens, I shut it down and then I power it back up again. However, when it does load up, Airport cannot be found/does not exist. When I try to run disk utility, or any other program, it freezes. Not only that but the mouse track will no longer respond.
    I'm bloody well tired of having to restart it over 10 times. I've updated all the necessary software and hardware on here. Maybe this happened when I updated the Airport software. I am running some third party software, but that hardly crashes the laptop. There are times when it won't respond and I just force quit applications.
    I'm really annoyed and I need this laptop to work. I've also found that the build of iBook is loose like it has been altered before being sent to me.
    Any help would be necessary. Thank you.

    Welcome to the Apple Discussions!
    It seems you are encountering a . The cause of a kernel panic could be hardware or software. If your AirPort card is not available after a crash like this, that could be a telling sign. Perhaps your AirPort card itself is loose? A loose connection could cause a kernel panic. You might try taking it out and putting it back in to make sure it's secure.
    If that doesn't help, you might visit Dr. Smoke's great FAQ about troubleshooting kernel panics here.
    -Doug

  • Mouse tracking

    OK, I have finally had a chance to play around with my newly purchases iMac 24" yesterday! So far so good, and as a now ex Windows users I am very impressed with the OS However, I have one little niggle, and if there's a solution I would love to see it.
    I have adjusted to mouse tracking speed to around 90% so that I can quickly cover the 24 inches of my screen, but I am getting a little frustrated by the fact that when I slow my hand movement down slightly (for instance, to click on a small object, or to highlight text etc.) the mouse slows down to a crawl. I am assuming that this is a deliberate feature of OSX to increase accuracy, but it is slowing me down. Is there any way to turn this "feature" off?

    A lot of people have been complaining about the acceleration curve algorithm used in the Intel Macs. You may have some success with an alternative driver such as http://www.versiontracker.com/dyn/moreinfo/macosx/13443
    USB Overdrive which has many more options than Apples's mouse driver.
    G4 Sawtooth, 400MHz (upped to 1.1 GHz), 1.2GB   Mac OS X (10.4.9)   120 GB HD, ATI Radeon 9000, DVR-105

  • HT2845 why doesn't my mighty mouse track ball scroll up or down vertically?

    why doesn't my mighty mouse track ball scroll up or down vertically?

    Hi:
    New ones are not that expensive, but I would try running it up and down (vigorously) on microfiber cloth or a towel or something.
    If that does not fix it...yes I would buy a new one.  I like wireless ones anyway
    Barry

  • Mighty mouse - tracking sluggish w/ new MacPro

    Set up a new MacPro w/ AirPort and BT with the Apple BT KB and Mighty Mouse. Arrived with dead batteries. With fresh batteries in my office mouse tracked fine. At new location, tracking now unusable. MacPro doesn't seem to support ext antenna for AP or BT, so is there any possible remedy for this poor signal/tracking?
    MacPro 2x2.6GHz, 4GB ram, Radeon X1900, 2x500GB SATA HD. MacOS X 10.4.8.
    Thanks

    Dear poor friend,
    I am facing the same very problem here. It started last monday when I updated the OS and the system requested to restart. I restarted it and then Voala!!! My Magic mouse stopped tracking. Like you I can scroll, click, perform some gestures... but thats all.
    I still have 8 months of warranty and as I discussed with "Apple Care Specialist" I should reinstall the Mac OS X overlapping the current system. I did that and nothing..... Then he recomnended me to take my mac to a service center.
    I live in Brazil and here the Service Center system is always down. I tried to take my MacPro there three times (iPlace in Shopping Ibirapuera) and I always heard that the system was down and they didnt even try to check it.
    So I called the Apple Care Again, this time the Super Advanced Specialist told me to FORMAT my disk and reinstall the system once more.... I had no option and I lost everything in this process....
    My mouse worked for few minutes and then..... Ta daaaa!!!... it stopped again...
    Then this super Advanced Specialist said that this problem might be related to the firmware and only Service Center can give a look...
    That means... DEAD END for me...
    I was an apple maniac fanboy until today... I cannot accept that my mouse is not working...
    APPLE, please, release a patch to fix this problem to occur again. Fix my Mac without the need to bring it to a Service Center.!!!
    Best Regards,
    Disappointed client.

  • Mighty Mouse tracking issue while downloading files

    Hi everybody ...
    I'm the owner of the Wireless Mighty Mouse... For about 2 months I'm recognizing a strange behavior.
    When I do start a download via Safari (I'm connected to the Internet via Wifi 54Mbits (2,4 GHz)) the mouse tracking start to bucking. During the download no fluent motion occurs. After the download finished the bucking stops and the tracking flows seamlessly. Does anyone have the same problem? I'm not quite sure what the exact problem is but could this behavior result from the connectivity frequency of bluetooth and wifi? And please don't tell me to reset my keyboard or my mouse. I already did that. I also updated to the latest official software update for bluetooth.
    Please help me.
    Thx destinationCloud

    Hi,
    I have the same problem, but mine usually shows up when I have MS Word opened for a while. It is as if there is some other process cycling that interferes with the tracking. Sometimes it shows up as a major lag (cursor stutters and moves a little bit for a large hand motion) or the cursor jumps way across the screen. It isn't always when MS Word is opened, but more frequent when it is (occasionally with Pages too). Changing batteries doesn't help, changing surfaces doesn't help. After some time, the problem resolves and mouse moves smoothly again, for a while. This has been more of a problem in the last few months than before.... was the Bluetooth driver changed? Does it have anything to do with a cache that is used before changes are saved?
    Where is the Bug Report link... I can never find it. Just put it right on the Support page please, BIG.
    Message was edited by: dammittakethealias

  • Mouse Track loosing sensativity... need help

    Hey. Sometimes, when I click on the bottom half of my mouse track, it does not work. I have to push A LOT HARDER than usual...
    Anybody know how i can solve this?
    thanks

    Hallelujah! Thank you!
    Really must get apple care number in US then!!! Not fair.
    Thanks a lot people!

  • IPhone does not remember song or track or position in playlist or audio book

    I am hoping Apple will fix a problem with Ios7.0.x where iPhone does not remember song or track or position in playlist or audio book.  It worked fine with ios6.x

    Hello SashMir,
    After reviewing your post, I have located an article that can help in this situation. It contains steps to complete a restore on your device. You may want to consider a restore then setting up as "new," to alleviate the issues you've described:
    iOS: Back up and restore your iOS device with iCloud or iTunes
    http://support.apple.com/kb/HT1766
    Thank you for contributing to Apple Support Communities.
    Cheers,
    BobbyD

Maybe you are looking for