I am experimenting with Haxe and OpenFL and am wondering if the Sprite class is synonymous with a GameObject in Unity. It seems that sprite instances have a hierarchical structure and I am wondering if this can be utilised to manage objects.
For example:
Game (Sprite / container / no visual representation)
|--> Grid (Sprite / container / no visual representation)
|--> Tile (Sprite)
|--> Tile (Sprite)
|--> ...
|--> ...
Am I correct with the above assumption, or should the Sprite class be extended purely for objects with visual representation?
If you only need a container, you should extend DisplayObjectContainer. But for abstract things like Game, I wouldn't use a DisplayObject at all, but custom classes.
Use classes extending from DisplayObject only for things that should be added to the Display List. In your example, Game shouldn't be a Sprite, but Tile and Grid probably yes.
Well, I use that in my project, so probably the answer is 'yes' :)
In particular I use a grid with N horizontal sprites, so my isometric map is rendered in proper top-to-bottom order. I also use a single container for my HUD etc.
There are some caveats to this approach - "invisible" sprites cannot capture mouse events, and they cannot have their width/height set programmatically (only by adding children at appropriate positions).
Related
I want to log some text on the screen, but not to all actors at once. I have several ai car actors, which all have a Scene Capture Component 2D component, on which their camera view can be seen.
I want to print to that object, but I cannot find any suitable function for this purpose. I found different print/draw text functions, but their target is either HUD or Canvas or Context, or simply the main screen. I tried to cast to one of the target types that have a function for this operation, but it always fails since Scene Capture Component 2D is not a subclass of any of them.
Is that even possible to do what I want?
(I use Unreal Engine 4.25 version with Blueprints.)
Maybe a way to this would be to add a HUD to each actor and have a text as a UI widget in it. Then you could play the visibility and Value of that text to show what you need at any point.
I have 2 prefabs (a character and a wall), I attached a capsule to the player and a cube to the wall. Both capsule and player, have the collider component. The problem is that my character walks through the wall. I need your help, please!
Collider defined without RigidBody component is called Static Collider in Unity. If you do so, Unity assumes that the object will never move in the scene.
On the other hand, if your object is an active one (moving), you need to attach RigidBody component in addition to Collider component.
In your case, you need to attach a rigidbody to your character.
For more info: http://docs.unity3d.com/Manual/CollidersOverview.html
Add a RigidBody component to them.
Swing had LayoutManager's separate from the containers. So far as I can tell, JavaFX doesn't do that.
I have a complex structure of nodes that I want the user to be able to toggle between several different layout approaches. Something equivalent to the user specifying flow and all containers are converted to the equivalent of FlowPanes. Then they could choose vertical and everything is laid out vertically.
Is there a way to do this other than swapping out the nodes/recreating the whole structure?
I should note: the hierarchy changes at runtime and it is deeply nested.
I mention Swing because this is straightforward to do in Swing by maintaining a list of all containers in the entire hierarchy, and with a simple loop (or tree traversal without the list) setting a new LayoutManager on them. JavaFX doesn't seem to have this possibility because the layout behavior appears to be internal to the nodes.
Isn't something like this working ?
AnchorPane main=new AnchorPane();
AnchorPane sub1=new AnchorPane();
sub1.getChildren().add(btn);
main.getChildren().add(sub1);
When you want to switch the layout
AnchorPane sub2=new AnchorPane();
main.getChildren().remove(sub1);
main.getChildren().add(sub2);
Edit
I guess I missed how you are doing layouts. This is how I envisioned it.
Definitions to Various Components
MainLayout
-> CustomLayout 1
-> References to various components. ( Essentially you are not creating all the components for every layout, rather you are referring to them in each layout )
-> CustomLayout 2
-> References to various components. ( More or less a different arrangement of the same components, adds some component references and removes some )
-> CustomLayout 3
-> References to various components.
Making a bold statement, but if there were a tool in JavaFX, how would it do this automatically ? Each template needs to know where it should render a particular component and arguably the easiest way to do this is just create a new template that arranges the components in a different layout and swap the template when user wants to see a different layout.
This is not easy to do in Swing. You would still need to set all the layout constraints on the individual components again, unless your layout is very straightforward.
I don't see how there is much difference in this between swing and javaFX. In JavaFX you would need to add the same controls to a different container (VBox, HBox etc.) but you still don't need to recreate the controls every time. It is a little awkward to find the containers in the middle of the node hierarchy but I'm sure there is some kind of elegant recursive solution :)
I have been trying to find an example or some hints on how to create an app that I could drag, resize, rotate images onto a UIView and then save the individual pieces (including their size, rotation and placement) and the entire UIView into CoreData. Kind of like the omnigraffle app.
Any tutorials, examples or anything on any piece of the app would be greatly appreciated.
for dragging a view
http://www.cocoacontrols.com/platforms/ios/controls/tkdragview
for roting a view http://www.cocoacontrols.com/platforms/ios/controls/ktonefingerrotationgesturerecognizer
for resizing a view
http://www.cocoacontrols.com/platforms/ios/controls/spuserresizableview
What respects to core data, its actually pretty straightforward just, gather the classes in one view, see the properties you need to save, and the new one you will need for your app and thats it.
Like:
Object Canvas containing a many relationship to morphlingViews wich contain all the properties as center, color, width, height, angle, UIPath (if you plan to create custom shapes) layer position (so it gets drawn correctly) and if you plan to connect the views as omnigraffle add a many realtionship to self (in morphlingViews) so you can take the center of different morphlingViews and add a simple line between them. (and a string if you plan to add drawInRect method to allow users to write in the objects, then it will be a good idea to add the text properties as well).
You can also add Quartz Composer drawing styles properties to the object, as shadow, shadowColor, shadowOffset, or add patterColor to add resizable background.
I'm using JUNG2 to draw some graphs.
This is the image I get:
http://img841.imageshack.us/img841/205/graphvizkk3312164f020b4.png
I'd like to:
1) change the rendering order (labels should be the last objects to be drawn);
2) add a semi-transparent background to the labels.
3) change background color of the whole image.
Any idea on how to do this?
The JUNG2 documentation is not very extensive on these issues.
Mulone
(1) To do this you'd have to hack the rendering code; I don't believe that we support this at the moment.
UPDATE: I took a closer look. Actually JUNG does support this without hacking the existing libraries; the easiest way is perhaps to subclass BasicRenderer and then override the render() method so that things happen in the order that you want. (I recommend that you render vertices after edges.) Once you do that, you create an instance of your custom Renderer, and call VisualizationViewer.setRenderer(customRenderer).
(2) The labels respect HTML code (i.e., surround your label with <html></html> and then put whatever tags you like in it).
(3) BasicVisualizationServer (and its subclasses, e.g. VisualizationViewer) inherit from JComponent, which defines setBackground(Color).