I'm developing a game with vertical screen orientation. Default of Libgdx screen is horizontal orientation. So I don't know should I rotate the background (texture/sprite) or I rotate camera 90 degrees, which solution is easy to develop later?
Don't rotate anything.
Go to the Android subproject, open the AndroidManifest.xml file and change (or add) the "android:screenOrientation" attribute of the "activity" XML tag to "portrait".
Rotating the content would cause problem in many cases (default text direction, virtual keyboard appearence...).
Rada
Related
We are designing an experience in Spark AR Studio and have run into a conundrum. Basically, our goal is to pin a Rectangle element containing an image texture so that it always lies just above the effect picker UI in Instagram across all devices, as in the placement in this image:
Goal Placement
We are attempting to accomplish this via pinning the Rectangle item item to the bottom and left side of a Canvas element set to Camera Space and Safe Touch Area. This seems to create a successful positioning like in the Goal Image on some devices, but on others (especially the iPhone 8 and iPhone 11) the image is still partially obscured by the UI, which is counter to our goal.
Here is our scene setup:
Rectangle element properties
The Rectangle element in the Scene panel
The Rectangle's position in the 2D Scene editor
An example of undesired behavior:
The Rectangle is obscured by the Effect UI
We have also tried to achieve this via placing the Rectangle dynamically using the Device Insets patch, but this also seems to not help and only provides an accurate pinning above the UI in some circumstances.
Any advice is greatly appreciated!
I need to disable auto rotation (when device orientation changed) for one single element on page. I can disable it in all app by:
Windows.Graphics.Display.DisplayInformation.AutoRotationPreferences = DisplayOrientations.Portrait;
But this is not what i want. How can I do that?
Cannot disable rotate for an individual item.
If your application changes the screen orientation is rotated all the elements.
If only track event screen rotation, and resize this element in the opposite direction. But I don't think it's a good solution.
Handle the rotation event and transform(rotate) your element accordingly to current orientation.
Available orientations
How to rotate element.
In Cocos2d-x's sample code cpp-tests, there is a UIVideoPlayer sample in android platform.
I change the video's position to (0,0) and even add a layer(or a sprite) overlapped on it, the video just can't be covered any way(video playing is fine), even the FPS and the vertex count info are the same.
Is it normal? Nothing can overlaps the video? If not, how can I overlap my sprite(or layer) on it?
By default, all non-cocos2d views are on top of everything drawn by cocos2d.
You can only add the video in the background, with cocos2d drawing everything on top.
What you can not do is to have a cocos2d node drawn in the background, draw the video over it, then draw another cocos2d node on top of the video. The reason is simple: cocos2d draws everything to its own view, and there's only one cocos2d view. So you can only change the draw order of everything drawn by cocos2d with some other view, since nodes aren't views themselves.
I am trying to move a sprite to the mouse position on click.
However, the coordinates I am getting from Gdx.input.getX()and Gdx.input.getY() is relative to the top left corner, and the setPosition() method of Sprite is relative to the bottom left corner.
Why is this so, and how do I position my sprite where the mouse was clicked?
Screen coordinates come from Android and use a Y-down frame of reference. Cameras in libgdx by default use a Y-up frame of reference (because OpenGL by convention also uses a Y-up frame of reference).
If you prefer the Y-down frame of reference, you can use camera.setToOrtho(true); method to flip it upside down. You might prefer this if coming from a Flash background.
But in general, the safe way to translate screen coordinates from a touch into the camera's coordinate system is to do the following. This will work regardless of what platform you're on and whatever coordinate system you chose for the camera. For example, for some types of games, you wouldn't even be using a camera that matches the screen resolution, but you'd still want screen coordinates converted to camera coordinates. Also, if you have a camera that moves around the world, this will automatically change the touch point to world coordinates.
tempVector3.set(Gdx.input.getX(), Gdx.input.getY(), 0);
camera.unproject(tempVector3);
//now tempVector3 contains the touch point in camera coordinates.
It uses Vector3 because this also works for 3D cameras.
I have a mobile application that I am going to allow for landscape mode when you are playing stagevideo.
I'm farmiliar with creating a veiwport and getting stagevideo to play on ios. I am detecting when the device orientation changes and I would then like to rotate stagevideo object when the orientation changes. I'm not finding any examples or documentation on how to do this.
I notice that the Rectangle object has topLeft and bottomRight values that can be set. I'm wondering if changing the values will do the trick, or will creating a new view port setting X, Y and width and height will rotate the video if I set the X and Y to the corner that is now "0, 0" after rotation ? In other words if I rotate my phone clockwise in landscape then the new view port would be something like this.
sv.viewPort = new Rectangle(0, view.stage.stageHeight, view.stage.stageHeight, view.stage.stageWidth);
You can rotate the video played by the StageVideo class by encoding it rotated!
For example, in After Effects, just rotate the composition containing the video after nesting it into a new composition. Then render. Then pick it up with StageVideo. Voila.