user interface - How do you smoothly move a graphics object 360 degrees in Java? -


I am trying to create a geometry war style style and I am on a roadblock. I'm trying to easily remove a way to move my graphics object. But it only walks in one direction, for example, if I press the up button it grows and then when I press the button on top of it, I move the diagonal upwards to the right but I want my Turn directly from top to top to move the object right from top to bottom This is my code yet:

  Public class Moovest implemented JPNL ActionListener, KeyListener {Timer T = New Timer (5, this); Double x = 0, y = 0, velax = 0, well = 0; Private set & lt; Integer & gt; Pressed = NewHashet & lt; Integer & gt; (); Private static id WIDTH = 800; Private stability HEIGHT = 600; Private double D = 0; Private Double Top Speed ​​= 0; Private boolean stop = wrong; Private double A = 0; PVector location; PVector velocity; PVector acceleration; Public MovStest () {place = new PV reactor (width 2, height / 2); Velocity = new PV reactor (0,0); Acceleration = new PVector (0,0); Topspaid = 5.0; T.start (); AddKeyListener (this); SetFocusable (true); SetFocusTraversalKeysEnabled (false); } Public Zero Paint Component (Graphics G) {Superpact Component (G); Graphics 2DG2 = (Graphics 2D) G; G2.setColor (Color.GREEN); G2.drawOval ((int) location.x, (int) location.y, 40, 40); } Zero Update () {velocity.add (acceleration); If (stop == incorrect) {velocity.limit (topSpeed); } And {velocity.decellerate (0); } Location.add (velocity); } Public Zero Answer () {Acceleration = New PVector (0, -5); } Public Zero South () {Acceleration = New PVector (0,5); } Public Zero West (Acceleration = New PVAct (-5.0); } Public Zero Ex () {Acceleration = New PVector (5,0); } Public Zero Northeast () {Acceleration = New PVector (5, -5); } Public Zero Northwest () {Acceleration = New PVAct (-5, -5); } Public Zero South East () {Acceleration = New PVector (5,5); } Public Zero Southwest () {Acceleration = New PVAct (-5.5); } Public Zero Stop () {stop = true; } Public Zero Methodology (ActionAge RGET) {//System.out.println ("" + velocity.x + "" + velocity.y) "; Reprint (); Update (); checkEdges ();} Public Zero Key pressed (keyway e) {int code = e.getKeyCode (); stop = false; pressed.add (code); if (pressed.) (1) {if (pressed contents (keven.vq_w) & amp; ; Amp; amp; and pressed consents (KAVENT.VKD)) [Northeast ();} (Pressed Contain (KEVent.VK_W) & amp; amp; Pressed Contain (KEYVENT.VK_A)) {Northwest (;);} (If the pressed container (KAVT.VKSI) & amp; amp; and pressed contections (KEVEN.VKD)) {SouthEast ();} (if pressed Contain (KEVV.VKSI) & amp; And pressed ears (KAVENT.VK_A)) {Southwest ();}} and if (pressed.) () == 1) {if (code == KeyEvent.VK_W) {Answer ();} If ( Code == KeyEvent.VK_S) {South ();} If (code == KeyEvent.VK_D) {East ();} If (code == KEVENT.VK_A) {West ();}}} Public Zero Key Related ( Key Event e) {Pressed. Ala (e.getKeyCode ()); If (pressed). () (== 0) {stop ();}} Public Zero Key Type (keyEvent E) {} Zero Check Agencies () {if (location.x> WIDTH) {location. X = 0;} and if (location x & lt; 0) {location.x = WIDTH;} if (location.y> HEIGHT) {location.y = 0;} and if (space. ; 0) {location.y = HEIGHT; Any help will be appreciated.   

   

code> // moostest toppid = 5.0; // update velocity.add (acceleration); if (stop == incorrect) {velocity.limit (topSpeed); // South acceleration = new PVactor ( 0,5);

So if you press your key If your acceleration is always units 5 or 7 (which is probably an error) then you add it to your velocity which is then limited to 5. Your acceleration is so strong that you do not have almost inertia, small acceleration or bigger top Try speed and it should be smooth.

On one side: Are you compensating for the frame rate? I do not see it in your code, but I do not see the PVector Implementation not addressed.

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -