Adam's Lair Forum

game development and casual madness
It is currently 2017/04/29, 23:25

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: 2016/12/10, 22:46 
Newbie
Newbie

Joined: 2016/12/04, 21:13
Posts: 6
Role: Hobbyist
Hi there,
I'm trying to scale an image procedurally to fullscreen while using a flat camera.
I've written the following code in a plugin to do this:
Code:
                Rect rct = GameObj.GetComponent<SpriteRenderer>().Rect;
                Vector2 res = DualityApp.TargetResolution;
                if (rct.W / rct.H > res.X / res.Y)
                {
                    GameObj.Transform.Scale = res.Y * 2 / rct.H;
                }
                else
                {
                    GameObj.Transform.Scale = res.X * 2 / rct.W;
                }

The problem is, that this code will only work correctly, if i debug the game in Visual Studio. If i start the game in the Dualitor with navigating to Run -> Run Game, the image won't be displayed correctly.
Has anyone experiences with this problem, so that he can help me?
That would be very nice.


Top
 Profile  
 
PostPosted: 2016/12/10, 23:52 
Site Admin
Site Admin
User avatar

Joined: 2013/05/11, 22:30
Posts: 1949
Location: Germany
Role: Professional
Scaling an image to fit a rectangular area while maintaining aspect ratio is one of those problems that I end up googling every single time I do it, and get it wrong a few times until it works. So I'm not exactly in the best position to help you by looking at that code and spotting something xD

However, I can provide some questions that you can check to find out what's wrong and help us get an idea of the situation:

  • Did you debug-step through the code? Does it behave as expected?
  • Did you print out the target resolution? Is it different in editor and launcher?
  • What exactly does "is not displayed correctly" mean?
  • When you instead of the target resolution use a Vector2 that you can specify via property (default to non-zero, so you don't divide by zero), how does it behave?

Note: Moved this to the programming subforum.

_________________
Blog | GitHub | Twitter (@Adams_Lair)


Top
 Profile  
 
PostPosted: 2016/12/11, 16:18 
Newbie
Newbie

Joined: 2016/12/04, 21:13
Posts: 6
Role: Hobbyist
I've solved my problem by myself:
It's about the given
Code:
DualityApp.TargetResolution

My screen has the resolution of 1920 x 1080.
In VS the TargetResolution is half as big as the real resolution: 960 x 540.
To make sure my calculation is correct, i have to get the real resolution. Thats why I wrote
Code:
res.Y * 2
and
Code:
res.X * 2

While running the game in VS, it works, but the TargetResolution will be the real resolution, if I run this in the Dualitor. In consequence of that the scaling of the image is twice as big as it should be.
I've fixed the code for the duality launcher (without * 2), because I won't play my game in VS, if it's finished. ;)
I hope you can ignore my bad grammar and understand my solution nevertheless xD


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group