How to make a circle to navigate through events?

I am new to javafx so I try to learn from here, so please be reasonable and don't miss my question, I really appreciate any help, thanks!

I would like to know how I could move the object, let this circle on different events like keypress or mouseclick, mousemove, whatever.

Circle circle = new Circle();
circle.setCenterX(100.0f);
circle.setCenterY(100.0f);
circle.setRadius(50.0f);

      

Do I need to use this KeyFrame feature that I saw in the javafx site tutorial, or how does it work?

I wouldn't ask this here if I didn't feel so lost, honestly. So to make it clear: what is the code for the moving objects that I created using events?

EDIT: By moving this, I mean, press a key and it moves up a few pixels, transforms it maybe with another key, or clicks somewhere in the scene and makes it move there instantly or move there with a certain speed, I don't need to redraw it the way you need it with html5 canvas hopefully correct?

+3


source to share


1 answer


I dont need to redraw it as you need it with html5 canvas hopefully correct?

Not if you are using standard JavaFX scene graph and not JavaFX Canvas .

I would like to know how I could move an object, say this circle on different events like keypress or mouseclick, mousemove, whatever

There are three ways to move a Shape :

  • You can customize the geometry of the shape (for example, centerX / centerY properties of the circle).
  • You can customize the layout of the form (e.g. layoutX / layoutY properties).
  • You can customize the translation of the shape (eg translateX / translateY properties).


You can think of layout as the home position for an object; that is, where it normally should be in the context of its parent group. You can think of the broadcast of the broadcast as a temporary position for an object (often used when an object is being animated).

If you are using a layout pane like VBox or TilePane then the layout pane will handle setting the coordinates of the child node's layout for you. If you are using a simple Group or a regular Pane or Region , you are responsible for setting the correct layout values ​​for the child nodes.

To listen for events, install event handlers on Nodes or Scenes .

Here's a small example app that demonstrates above. It places an object on an element Group

and changes the position of the object Group

in response to various events.

movementevents

+13


source







All Articles