I'm pretty new to javafx so I'm trying to learn here so please be reasonable and don't dis away my question, I really appreciate any help at all, thanks!
I would like to know how I could move an object, let's say 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 that KeyFrame thing I saw on the javafx site tutorial, or how does this work?
I would not have asked this here if I weren't feeling so lost, honestly.
So to make this clear: What is the code for moving objects that I created, by using events?
EDIT: By moving it I mean, press up key and it moves up by a few pixels, transform it maybe, with another key, or click somewhere on the scene and make it move there instantly or travel there with a certain speed. I don't have to redraw it like you need to with html5 canvas, I hope, right?
I don't have to redraw it like you need to with html5 canvas, I hope, right?
Not if you are using a standard JavaFX scene graph as opposed to a JavaFX canvas.
I would like to know how I could move an object, let's say this circle on different events, like keypress or mouseclick, mousemove, whatever
There are three ways to move a Shape:
You can adjust the shape's geometry (e.g. the centerX/centerY properties of a circle).
You can adjust the shape's layout (e.g. it's layoutX/layoutY properties).
You can adjust the shape's translation (e.g. it's translateX/translateY properties).
You can think of the layout as the home position for the object; i.e. where it should normally be in the context of it's parent group. You can think of it's translation transform as a temporary position for an object (often used when the object is being animated).
If you are using a layout pane such as a VBox or TilePane, then the layout pane will handle setting the layout co-ordinates of the child node for you. If you are using a simple Group or a plain Pane or Region, then you are responsible for setting the correct layout values for the child nodes.
To listen for events, set event handlers on Nodes or Scenes.
Here is a small sample app which demonstrates the above. It places the object to be moved inside a Group and modifies the position of the object within a Group in response to various events.
Related
I'm implementing a login screen. It has a centred Column containing a TextField for entering an email address and a number of buttons for social sign-in. When a button is pressed, the Column is rebuilt with a CircularProgressIndicator (spinner) added at the bottom. I've wrapped the spinner in a custom widget that manages a ScaleTransition animation. That works OK, but the Column grows and shifts up to accommodate the final full size of the spinner immediately instead of moving smoothly with the animation.
I also wrapped the Column in an AnimatedSize widget using the same curve and duration as the ScaleTransition, but it hasn't helped. The root of the tree is a Consumer of the state that triggers the addition of the spinner so the animations should both be starting together. Maybe the the spinner needs to be permanent for this to work, but it doesn't seem desirable because its API doesn't provide a way to pause the animation. It would presumably constantly use some power to animate itself even when it isn't visible. I'm fussy about that sort of thing.
It looks like I might have to use an AnimatedList, but it doesn't seem semantically correct because the contents aren't really a list. So is there a more generic way to animate the size (and position) of parent widgets like Column and Center to track an animated size change of their children?
I want to build a game and therefore I would like to create a game menu. This menu should be in front of the scene, but not totally hide it, somehow sticking at the lens of the camera. My first idea was to create planes as buttons and position them at the same position as the nearplane and move it with the camera.
Is there also a easier way to do this?
(I also saw this, but I don't know how to do it without qml)
The way games make HUDs or menus is by (I think) using orthographic projection which makes it unnecessary to have them at the near-plane (and gets rid of some side effects). I didn't find anything nicer than this to describe orthographic projections.
So to implement this you would have two framegraph branches:
Draw your objects as normal
Draw your menu using orthographic projection
The elements of the menu could be planes like you said. You can add QObjectPickers to the planes and then react to the clicks.
I have implemented an example for the opposite thing: I created a framegraph that draws a background image behind the 3D scene. It needs adjusting for rescaling the window but should give you the general idea. You can find the project here.
(This is a related question regarding how to put normal Qt widgets like QPushButton in a Qt3D window.)
I've just got started with Godot yesterday, and I'm starting a game. I drew a few spritesheets for it. It seems much more efficient to pack all of the frames of an animation into a single image file, right?
Anyway, in Godot I have an AnimatedSprite, who of course has a SpriteFrames property, or whatever it's called. I want to split my spritesheet up into multiple images so that I can use each image as a separate frame in the animation, but as far as I can see Godot provides no such feature. Is this the case?
I've been searching for an answer on the web for a while now, and I can't find anything relevant.
I'd be very surprised if I can't do this in Godot, since I can do it in just about every other game engine I've seen.
Thanks!
(Just to clarify, I want to (programmatically or otherwise,) split a spritesheet into multiple textures, within Godot.)
Click New SpriteFrames in the Frames property menu of the AnimatedSprite node. Now click on the just created SpriteFrames next to the name of the Frames property. Animation Frames window should appear.
Click this Add frames from a Sprite Sheet button. Select your spite sheet file, set grid sizes and finally select individual frames from that sprite sheet.
(This works for me in Godot v3.2.2)
As it says: "Sprite node that can use multiple textures for animation."
Source: http://docs.godotengine.org/en/3.0/classes/class_animatedsprite.html
What you are searching for is using normal Sprite(2D), and set regions for it if you are using AnimationPlayer at each frame.
Example: https://www.youtube.com/watch?v=IGHcscKpA7Y
If you want to do all programmically, you just have to set the sprite to Sprite(2D), and then:
func _ready():
set_region(true)
set_region_rect(Rect2(positionx,positiony,width,height))
but i guess using AnimationPlayer is better option.
This is not tested because i should be sleeping right now, but it should work.
I want to make a simple paint program on visual c++ which allows the user to draw a path of a series of straight lines which follow on from each other. Once the user is done this, they should double click to stop drawing. It is important that I record the co-ordinates of the beginning and end points of each line of the path because I want to use this information to find the magnitude and direction of each line using simple math. Please can someone give me somewhere to start and any other guidance.
You should start with a tutorial in: MFC.
Learn the basics: Document/View architecture and
how painting is done (GDI and device contexts).
Basically, you should:
1. create an MFC application (SDI - single document interface),
2. Handle the OnLButtonDown (WM_LBUTTONDOWN), OnMouseMove (WM_MOVE), OnLButtonUp (WM_LBUTTONUP).
3. Maintain an dynamic array/List (TypedPtrList) of the points
4. handle the double-click event for detecting completion.
You should use the Invalidate() function on (after) each click, in order to see the changes
on the screen.
That's just a little bit of information to get you started
You'll want:
a class or struct to represent a point (if you make it a class, it could have computation methods that would, for example, calculate the distance and direction to another point)
a member variable: an instance of a container class (list, array, etc) to hold your points
a member variable: a boolean flag to represent whether you are drawing or not (starting with not)
and you'll need to handle:
the mouse click event to instantiate a point and add it to your container
the mouse move event to draw a line from the last point to the current mouse position if the drawing flag is true
the mouse double-click event to add the double-click location to your container of points and turn off the drawing flag
Yaron's strategy doesn't draw lines until 2 points are clicked. Mine uses "rubberbanding" to anchor the first end of the line then let the second end follow your cursor until you click to anchor it down. Use whichever one you like better.
if i were you i would use Qt.
Qt widgets are great for user interface. you should check qt examples...
if you want to make an image processing behind, you can use imagemagick library.
this library is great for any image manipulation.
I have a grid/canvas that has an element (say an icon with an image and text overlayed) added to it dynamically via code.
Most of the time it renders correctly when added (content is aligned properly inside it),
but sometimes all the content sits in one corner.
I can remove/add/remove/add/remove/add and it will eventually do it
After a movement of the parent canvas, the element corrects itself as if the layout has been updated.
I have tried the following on Loaded and OnApplyTemplate for both the element and the element parent but it still seems to happen occasionally
InvalidateMeasure()
InvalidateArrange()
UpdateLayout()
Any ideas on why the content wouldn't arrange would be appreciated cause its driving me nuts
I'm not sure why it works for you sometimes but not others. But a grid has the inherent ability to dynamically resize itself and its contents. A canvas doesn't (you'd have to handle that manually in code).
If you change your canvas to a grid does it work? A grid has slightly more overhead than a canvas but it sounds to me like you need its functionality anyway.