How to fix overlapping objects on the stage in AS3 - image

I have a flash game where I have a picture designed to be the textbox for a prompt and textbox inside with the relevant text but the textbox is being hidden by the image. Anyone know how to make is so that the textbox is guaranteed to be on top or whatever I need to do to keep this from happening?

The other answer using setChildIndex will definitely work, however, I think a different design approach is really what you should be doing to remove the headache altogether.
For example in a game I might have different layers such as :
backgroundLayer
gameLayer
interfaceLayer
Those 3 Sprite layers would get added to the stage in that order. I would then add display objects to the appropriate layers. So anything I added to the backgroundLayer or gameLayer would ALWAYS be 'behind' my user interface on the interfaceLayer.
That allows you to not have to worry about the layering constantly. The answer with setChildIndex will fix the problem for that moment, but should something else be added to the container it will overlap your textbox, which is something I don't assume you want.
here's an example :
var backgroundLayer:Sprite = new Sprite;
var gameLayer:Sprite = new Sprite;
var interfaceLayer:Sprite = new Sprite;
addChild(backgroundLayer);
addChild(gameLayer);
addChild(interfaceLayer);
now, whatever you add to interfaceLayer, will ALWAYS be on top of objects you add to gameLayer or backgroundLayer.
So in the case of your text box, just add it to your interfaceLayer and any other objects you want behind it, you add to the gameLayer or backgroundLayer.

The order of adding display objects to display object containers effect their z-order, in other words the front to back order. The last added display object becomes the frontmost. So the child index of the children of a display object container is important for drawing of overlapped children.
If you put picture and text on the same DisplayObjectContainer such as a MovieClip:
Lets say your DisplayObjectContainer is mc.
And your textbox is txt
Please try this:
mc.setChildIndex(txt, mc.numChildren-1);

Related

Draggable and swipable container in flutter

I'm new to flutter and I'm looking for a way to implement a simple feature. A draggable container.
I have two groups of UI elements wrapped in a Container widget. I want to be able to go from one group to another by dragging or swiping in different directions.
How would I go about doing this?
Here are sample images of my UI design to help you understand what I want to achieve:
Image #1
Image #2
As you can see, Image #1 and Image #2 are only different in the bottom part of my design. I have already created all the necessary UI elements and wrapped them in the Container widget. Now the only thing I need is the ability to go from one group to another. It would also be nice if there was a callback method that could update the buttons above upon transitioning from one group to another.
Thanks in advance!
There are many possibilities to achieve this, depends on your exact wishes, here are 3 ideas:
Using a TabBarView to swipe the entire screen, Tab1 will be the first screen you showed, and Tab2 will be second screen - only the contents. (you probably did not want that, but just putting it out there).
Dividing the container into 2 pieces (vertically), and placing the TabBarView on the bottom part, having 2 tabs: 1 with the Today part and one with the Weekly part. (there are a few examples out there, for instance: divide screen into two equal parts in flutter).
You can also customize the build method to change anything (for example the top indicator) based on the current tab index (as asked and answered here: How to get current tab index in Flutter)
For a more custom solution you can use:
GestureDetector wrapped around your container, and handle OnHorizontalDragX (where X is Start, End etc.) to do any custom stuff - maybe changing the state and trigger a rebuild with the new image

User Interface on Top Rajawali Surface View

Anyone who knows how to add User Inteface on top of Rajawali Surface View?
I check the rajawali documentation but it doesn't work
The following approach worked for me: Create your UI elements that you want to add to your layout, I used a ConstraintLayout as a container. Do not create the SurfaceView by xml, but instead programmatically. Create it in a way that it will overlap all other UI elements and that it uses all available space. By this, the UI elements are still visible even though technically they should be hidden by the SurfaceView which is in front.
Below is my code how I setup the SurfaceView. Note that constraintLayout is the name of the container layout that has other buttons in it as well.
surfaceView = new SurfaceView(getContext());
surfaceView.setFrameRate(30.0);
surfaceView.setRenderMode(ISurface.RENDERMODE_WHEN_DIRTY);
surfaceView.setSurfaceRenderer(YOUR_RENDERER);
surfaceView.setLayoutParams(new ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.MATCH_CONSTRAINT, ConstraintLayout.LayoutParams.MATCH_CONSTRAINT));
surfaceView.setId(View.generateViewId());
constraintLayout.addView(surfaceView, 0);
ConstraintSet constraintSet = new ConstraintSet();
constraintSet.clone(constraintLayout);
constraintSet.connect(surfaceView.getId(), ConstraintSet.LEFT, ConstraintSet.PARENT_ID, ConstraintSet.LEFT);
constraintSet.connect(surfaceView.getId(), ConstraintSet.RIGHT, ConstraintSet.PARENT_ID, ConstraintSet.RIGHT);
constraintSet.connect(surfaceView.getId(), ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM);
constraintSet.connect(surfaceView.getId(), ConstraintSet.TOP, ConstraintSet.PARENT_ID, ConstraintSet.TOP);
constraintSet.applyTo(constraintLayout);

LibGDX (Scene2D): Using Table with Labels to do a chat menu

I am trying to do a chat menu in my game using a Table and Labels but I can't seem to get the labels to behave the way I want them to.
By default they are drawn in the middle of the table. I added this settings to fix that but now when I add new labels they expand to fill the table, which I don't want.
After adding settings:
After adding a new label:
Note: The second message is there, it's jsut very faint. Just another bug I am having :/
Also, you may notice that the "Send" button is half off screen, trying to fix that too, but one problem at a time I guess.
By the way, the table is within a ScrollPane.

How to put shapes (oval, rectangle, line) in VisualBasic tableLayoutPanel?

Sounds like a silly problem, but whenever I drag an oval to the table, an error pops out: "Cannot create component of type 'Shape' in container of type 'TableLayoutPanel'. Is there a way I can work around this?
The Shape classes require a container, an instance of the ShapeContainer class, pretty invisible when you use the designer to drop shapes on a form. Technically you can find it back from the control selector combobox at the top of the Properties window, the default name is "shapeContainer1" and has no properties at all. The surface of this container class is used to draw the shapes.
All of this is done completely automatically with a custom designer, it ensures that the ShapeContainer instance is created when you drag a shape from the toolbox onto the form. Problem is, this designer isn't quite smart enough to deal with the TableLayoutPanel class. What it should do is create a ShapeContainer that can be embedded in a cell of the TLP, it doesn't. Instead it just gives up and displays the message box. Or to put it another way, you are seeing the Microsoft programmer having given up on making this work. It is not very simple to do correctly, pretty hard to get rid of those otherwise invisible containers again.
Only workaround you have is to write the code yourself. You do so in the constructor of the form. A simple example that puts a LineShape in the upper/left table cell:
public Form1() {
InitializeComponent();
var line = new Microsoft.VisualBasic.PowerPacks.LineShape() {
X1 = 0, Y1 = 0, X2 = 50, Y2 = 20
};
var container = new Microsoft.VisualBasic.PowerPacks.ShapeContainer();
container.Shapes.Add(line);
container.Size = new System.Drawing.Size(50, 20);
tableLayoutPanel1.Controls.Add(container, 0, 0);
}
I know this is an old thread... but for the sake of someone who might be looking into an easier option in the future this is the solution I found:
Insert a Panel inside of your TablePanelLayout where you want to place a shape and VisualStudio should allow you to place the shape inside the newly created panel.
Good luck.

How to break a sentence in Xcode

I'm new to this, and new to coding.
I'm working on a quiz app, and here is one of the lines of code:
[questions addObject:#"When was the Declaration of Independence signed?"];
[answer addObject:#"1776"];
But when I test it, the question is too long, so it makes the text extra small, how can I make it so half of it will drop down to the next line?
There are a couple options.
The most basic is to "hard-code" the line break, which is NOT the best option, but I'll spell it out so that you are aware of the difference: this involves splitting the question into two lines by adding a "newline" code (\n) at the point in the question where you want the newline to start. For example:
[questions addObject:#"When was the Declaration\nof Independence signed?"];
This isn't flexible or adaptive, and whether you are using the Interface Builder to configure the object displaying the text (UILabel or UITextView, or other class), the second line of the text may disappear because it falls below the visible area set-up when you create the UILabel or UITextView. This method also goes against best practices because it confounds display with data. There is nothing wrong with your data as it stands.
The better option is to work ONLY with the object displaying the text - which you'd need to do anyway. I'll use UILabel as an example here, but both UILabel and UITextView objects have properties you can set programmatically or in Interface Builder that will effectively enable them not only to stretch their display area instead of shrinking your text, but also to wrap your text at the most logical point based on the new size of the display area.
Programmatically, first make sure that the number of lines for your UILabel object is set to 0:
textLabel.numberOfLines = 0;
You can also do this in Interface Builder if that's where you've created your UILabel.
If that doesn't work, something else is probably not set-up properly - check on the UILabel's metrics to make sure you haven't "locked" its size in any way (its ability to auto-grow or auto-shrink based on the size of its contents).

Resources