How do I make my UI text centered to my 2d object when changing resolutions in Unity? - unity3d

I have a 2d circle in the scene, and a text inside it that I want to always be in the middle of the circle when I am changing resolutions.
For better understanding, it's just like a replica game.

You can create a circle including a text box. Make the text box child object of your circle and add HorizontalLayoutGroup to your circle
Tick all of its properties.

Related

Custom Shaped Buttons Unity UI

Hi I am trying to create custom buttons on unity (trapeziums). I successfully created the visible area on Photoshop and imported it as Sprite 2D UI as per the following image:
The issue arises, when I'm trying to select one of the buttons in game, their border overlap each other, since the transparent area is still being considered as part of the clickable button area. How can I remove this?
EDIT:
Practically when I import I want the squared boxes to not be counted with the image. I need the edges of the orange area to be cut flush with that and not the entire area(i.e. including the transparent boxes).
You may achieve this by using Alpha Hit Test Minimum Threshold. Take a look at this nice video tutorial.
There is one extra step that is not shown in the video but mentioned in the comments: you have to change "Mesh Type" to "Full Rect" and not "Tight" as it is.
Hope that helps.
The clickable area is based on the Rect Transform component of the GameObject. Adjust the width and height to the clickable area you want. You may have to crop your image in photoshop accordingly. If you select 'Gizmos' in the editor you can toggle viewing the click region.

Canvas Text not visible

I have a rectangle that I want to display score on. I want the text to be on this game object, so I set the canvas to World Space and not Screen Space (Overlay) which is the default. I change the size of the canvas & text and place them a bit in front of the rectangle.
Here you can see the text object in front of the rectangle:
Here is the game view - there should be some text visible here but there isn't:
Here is the hierarchy - the grey rectangle is the outermost object. When I added a text component as a child it got its Transform changed to a RectTransform.
Set the canvas size big like 800x600 and then scale it down to 0.001 or so, then set the font size accordingly. :)
World space canvas are capricious.
Your canvas is attach to your camera?
In all case if it's just to display only a text some where in world space like your score, take a look to TextMesh that is at "3D" text, you can attach where you want in your world.
Hope this helps.

Sprite-Kit: change the contact points color

The scene background color is white.
In the scene there are two sprite nodes (SKSpriteNode) sprite 1 and sprite 2 with black borders and transparent backgrounds.
sprite 2 moves.
sprite 2 reaches sprite 1 and contacts it.
What I'm trying to do is merging the two sprite contact borders when they contact each other. With other words: I want to change the color of the contact points of both sprites into the scene background color. I tried to do this with the blendMode property. But it seems that the blendMode property works only with a node and his parent.
Does the blendMode property work only with a node and his parent? If yes, is there any way to change the colors of the contact points of two "normal sprite nodes"?
Thanks for any ideas.
EDIT:
the background color is white.
each sprite is transparent and has a border with black color.
when a sprite contacts OR is moving along the border of another sprite, the black color of all contact points of both sprite borders changes to white (that is the background color). The color of all other border points of both sprites stays black.
I put another picture with more details.
Thanks in advance.
Blend mode will only blend textures together, it will not remove that black border unless you are applying something like Xor Blending. The actual sprite would blend to the destinations frame buffer, not the parent, so whatever is below the sprite at the time of rendering it.
Blending the Sprite into the Framebuffer
The final stage of rendering is to blend the sprite’s texture into its destination framebuffer. The default behavior uses the alpha values of the texture to blend the texture with the destination pixels. However, you can use other blend modes when you want to add other special effects to a scene.
You control the sprite’s blending behavior using the blendMode property. For example, an additive blend mode is useful to combine multiple sprites together, such as for fire or lighting. Listing 2-6 shows how to change the blend mode to use an additive blend.
Source: https://developer.apple.com/library/ios/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/Sprites/Sprites.html
To achieve what you are looking for, I wouldn't even mess with blending, instead have your sprite broken up into 2 sub sprites, the border, and the inside color.
What I mean by this is lets say you have a circle with radius 10 and a 1 pixel thick. We create a node, that has a child that is just the border with a transparent area at radius 10, and another child that has a radius of 9, which will be filled with white.
Set the borders zposition to 0
Set the inside sprites zposition to 10.
When 2 sprites merge together, here is how drawing will be rendered
Sprite 1 border
Sprite 2 border
Sprite 1 inside
Sprite 2 inside
This will give you the effect you are looking for with the sprites merged together.
Of course, if your inside has transparent and not a solid color then we have a
problem. (Right now you are saying your BG is white, so we do not need transarency, your circle cam be white, but if you want to put a texture on the BG, then we have an issue.)
If you indeed want to keep your circle "transparent", then what you need to do is capture the background underneath before the border gets drawn, and make that the texture of your inner circles

Transformation Sprite with finger move

I am making an Drawing App in someway like Paint in Windows
I have a toolbar with many shapes button such as Rectangle, Circle, Triangle, etc. When tap a button i add a sprite with shape with button's name.
I want to add functions like this
- When tap on shape it show four 4 points each corner of shape that i can touch and drag to skew or scale.
Same as we do with an image in photoshop or MSWord
anyone have sample code or tutorial ?
Use this code for your app.
Paint
Drawing
Drawing2

ios game make a mask layer effect

I need a 'mask' layer that covers the whole screen, with the center part (a circle) to be transparent. Then I can move the mask layer around using touch. User are only able to see the transparent part in the middle.
I don't think a png file can help because the file need to be very large to cover the whole screen.
So is it possible to do it by coding?
i found this online, but don't know much about openGL. http://www.cocos2d-iphone.org/forum/topic/7921.
it would be great if i can use a CCMaskLayer and input with the radius. i can handle the touch event by my self.
the attached png file is expected result, the center part is transparent. i need this to cover my screen, and only show the middle part. the red part is covered.
I write a CCMaskLayer to do the exactly same thing.
https://github.com/smilingpoplar/CCMaskLayer
You may solve this task with cropped circle texture in two ways:
1) Draw sprite with circle texture in screen center and draw another 4 sprites around (on top, bottom, left and right sides) with small red texture but scaled to cover all screen.
2) (more elegant but harder to implement) Make your mask layer fullscreen but adjust texture coordinates. In details:
set wrap mode to GL_CLAMP_TO_EDGE to your circle texture
adjust texture coordinates of your layer vertices (to do this you need to subclass base CCLayer):
Here v means vertex position and t - texture coordinates. You need to set correct texture coordinates for four corner vertices of layer. For future if you will want to drag circle you will need to add some offset values to texture coordinates.