Note that there are some explanatory texts on larger screens.

plurals
  1. POScene2d - Rotated actor not translated as expected
    text
    copied!<p>I asked this at the libgdx forums but didn't get a response so I was hoping y'all could help me out:</p> <p>I have Actors that represent game pieces. What I'm trying to do is make it so the player can click-and-drag the tile to move it around the screen and rotate it multiple times before submitting the placeTile command. From what I understand of DragAndDrop it doesn't seem to be designed with my use case in mind so I figured I'd instead attach a dragListener listener to each game piece (code below). It works well for dragging, except I can't figure out how to set the 'minimum distance before drag starts' to 0... but that's not my main question (though any insights would be appreciated )</p> <p>Anyway, the big problem comes in when I rotate the actor, and then try to drag it: At 30 degrees rotation, drag acts almost like normal: at 60 degrees, very small movements of the mouse send the actor moving in a tight circle very quickly. Another 30 degrees, the tile actor exits the screen in 1-2 frames, moving in a wide arc. If the actor is rotated clockwise, it's movements are clockwise; same pattern for counter-clockwise.</p> <p>It looks like the translation of the actor is taking rotation into account; I guess my question is, is it possible to rotate an Actor/Group without the rotation affecting future translations? Alternatively, is there a better way to drag an Actor around the screen based on touch/mouse input? I included some code below: I imagine I'm screwing up something basic, but I can't figure out what:</p> <pre><code>// during initial stage creation tileActor.setOrigin(tileActor.getWidth() / 2, tileActor.getHeight() / 2); tileActor.addListener(new DragListener() { public void dragStart(InputEvent event, float x, float y, int pointer) { chosenTileActor = event.getTarget(); } public void drag(InputEvent event, float x, float y, int pointer) { Actor target = event.getTarget(); target.translate(x, y); } }); </code></pre> <p>And for the listener that deals with rotation via scrolling mouse wheel:</p> <pre><code>multiplexer.addProcessor(new InputAdapter() { @Override public boolean scrolled(int amt) { if (chosenTileActor == null) return false; else chosenTileActor.rotate(amt * 30); return true; } }); </code></pre> <p>Any pointers? Am I even going the right direction by using DragListener? </p> <p>Thanks for reading!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload