I have a rather easy question I think.
I am having 2 FitViewports, if I resize my game, both Viewports are resized.
This is working out great:
When I resize my window (smaller).
But this happens when im resizing it to be bigger.
As you can see the white background is the right size, the square in the middle is also- but I want it to be just as wide as the white background.
#Override
public void resize(int width, int height) {
backViewport.update(width, height); //white background
gameViewport.update(width, height); //square
}
I want the program to do so:
#Override
public void resize(int width, int height) {
backViewport.update(width, height); //white background
gameViewport.update(backViewport.getWidth(), backViewport.getWidth());
}
Getting the new background width-size and setting my gameViewport to the same.
I will do both width- and height- .getWidth(), because I want it to be square.
This is not working because it is stretching my square in the y-axis.
Thanks for your time and hopefully somebody knows a solution.
EDIT: By doing this,
gameViewport.setScreenSize(backViewport.getScreenWidth(), backViewport.getScreenWidth());
I achieved to get the square the right size, but I still cant figure out, how to move it back to the center of the background.
Here is the wiki, take a look once more.
https://github.com/libgdx/libgdx/wiki/Viewports
You have one square viewport and one rectangle viewport. Your viewports are working as expected, they are trying to fit to the screen. You are experiencing a problem because they have different sizes.
I don't think you want to use 2 separate viewports if they are going to act same. Instead use one viewport and draw like;
draw(x, y + bottomPadding)
when drawing your game.
Related
I use ggez and would like to resize the window. The only way I found is
graphics::set_drawable_size(&mut ctx, width, height);
However, when I use it, the white circle I drawn turns into a white ellipse, and a seemingly grey circle appears below. So is there another way of resizing window, one that doesn't distort what is drawn ?
use
graphics::set_screen_coordinates(ctx,rect)
right after declaring changing size with graphics::set_mode(ctx,windowmode) turns the ellipse back into a circle. The gray shape vanishes after reducing the window (this is a pretty obscure thing).
I find myself in the situation of having to manually draw a rectangle with rounded edges as a background for a horizontal stack view. To create the classic ios "bubble" effect, such as whatsapp chats, where the text is surrounded by a green shape.
I am attaching the code:
var BackgroundStack = new UIView();
BackgroundStack.Frame = new CGRect(0, -20, TopSchedaStack.Bounds.Width,
TopSchedaStack.Layer.Bounds.Height+40);
BackgroundStack.BackgroundColor = UIColor.TertiarySystemGroupedBackgroundColor;
BackgroundStack.Layer.CornerRadius = 20;
TopSchedaStack.InsertSubview(BackgroundStack, 0);
the perplexity lies in "BackgroundStack.Frame ...", I need to wrap the generated element in the "TopSchedaStack" storyboard of the UIHorizontalStackView type, with a gray rectangle. So I create it with the CGRect function but when I have to position it precisely under the object it is horizontally and vertically constrained to the view and centered. I am struggling, I cannot get the width I expect from the stack. In the storyboard file it is positioned one way but when I go to recover its width with:
TopSchedaStack.Bounds.Width or TopSchedaStack.Frame.Width
The value obtained is not what I expect. I expect the stack to be long from the left edge to the right edge of the view, taking away the guidelines. therefore it is an object constrained to the right and left respectively at point 0.
I would like the gray rectangle to cover the portion of the blue rectangle depicted in the image containing the storyaboard project. I'm pretty much going randomly changing values until it comes back, I'm sure I'll succeed sooner or later but I'm convinced it's not the right way to do this. Can you help me?
I'm new to Unity and my question may sound stupid, but please tolerate. I have added four sprites (small tiles) of different colors added to an empty GameObject so that they could be moved and rotated as a group. However, I'm unable to rotate the GameObject on its axis. My code is this:
void Update () {
transform.Rotate (new Vector3 (90, 0, 0) * Time.deltaTime);
}
Please identify what I'm doing wrong here. Also, please give me an idea of how to detect which colored sprite was hit by the ball. If I attach separate colliders and rigidbodies to each of the colored sprites then they start behaving individually rather than as a group.
Thanks!
I'm actually developing a game in Swift SpriteKit.
I set the position of a SKSpriteNode:
skPart1.position = CGPointMake(0, 100)
So the node should start at the very left window-edge.
|-------------------------|
|-------------------------|
|-------------------------|
|-------------------------|
|==========|--------------|
|==========|--------------|
|==========|--------------|
But in reality half of my SKSpriteNode is outside of the screen:
|-------------------------|
|-------------------------|
|-------------------------|
|-------------------------|
==========|--------------------|
==========|--------------------|
==========|--------------------|
I've read the same problem on stackoverflow, but the only solution provided there was, to set the scaleMode to AspectFit.
I've figured out, that it works with SKShapeNode. But why not in SKSpriteNode?
And I've alreay tried that.
How can I fix that?
SKSpriteNode has an anchorPoint property that defaults to the center of the image, which is why half of the sprite is off the left side of the screen.
You can adjust the anchorPoint so that it behaves like your SKShapeNode with the anchor in the bottom left. Try this :
skPart1.anchorPoint = CGPointMake(0,0);
I know you have accepted an answer, however this is the ideal way to handle the situation and it's why the property exists.
I think this actually depends on what you're using as your SKShapeNode. If you're using a rectangle, then the point you give it will be the lower left corner of the rectangle. But if you use a SKShapeNode circle, it'll drop the circle centered on that point you give it, and you'll see very similar behavior to the SKSpriteNode.
The SKSpriteNode is using the center of the image as the point it places your sprite at, and so when you're placing your node at (0, 100), exactly half of it is being draw to the left of the screen.
If you want your sprite to be drawn as far left as possible, but completely on the screen, you should be able to accomplish this by offsetting for one half of the sprite's width.
skPart1.position = CGPoint(x: skPart1.size.width / 2, y: 100)
I have an image of size 480x800 pixels and there is a icon on one corner which I need to place. What I want is that to ignore all touches on the transparent areas and detect only the area where the icon is.
I found a solution in SO to this problem but it just tells the code to be used. I need to know exactly where to put that code since I am a beginner and don't know much about cocos2d so I expect a step by step solution.
Cocos2d 2.0 - Ignoring touches to transparent areas of layers/sprites
Do not use glReadPixels because it affected by bugs in android drivers. You can translate CCTouch to CCPoint in image coordinates using convertTouchToNodeSpace, and read image pixel at given point.
Create CCImage from file that contains semi-transparent picture, and read one pixel at tap point; it should be {0,0,0,0} for transparent area.
Don't forget to check that tap is not outside picture, and create pixel index in CCImage::getData() array with formulae unsigned index = x * imageWidth + y.