Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / [SOLVED] Keep background same size regardless of virtual resolution

Author
Message
TomToad
6
Years of Service
User Offline
Joined: 6th Jan 2018
Location:
Posted: 24th Jul 2018 14:01
I have a background that fills the screen. I change the virtual resolution on each level depending on the size and layout of the level. The background, unfortunately will change size based on the virtual resolution. If bars are added, the background will be offset by the size of the bar.

I know of FixSpriteToScreen() command, but that only affects changes in the viewport position. Is there a command that will render a sprite the same size regardless of virtual resolution?

The author of this post has marked a post as an answer.

Go to answer

Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 24th Jul 2018 14:08 Edited at: 24th Jul 2018 14:09
I think you would have to call

SetSpriteSize(spr,GetVirtualWidth(),GetVirtualHeight())

each time you change the virtual resolution. or make all your levels with the percentage based system.
TomToad
6
Years of Service
User Offline
Joined: 6th Jan 2018
Location:
Posted: 24th Jul 2018 14:55
That will not work. The aspect of each level is different. I can resize the image ok to compensate for the aspect change, but the offset of the virtual screen changes, so my background ends up offset by the same amount. For example, if the screen is 800x600 and my virtual screen is also 800x600, then coordinates 0,0 will be in the upper left. But if the virtual resolution is 600x600, then 0,0 is now 100 screen pixels right. FixSpriteToScreen() seems to be not affected by the shift in the viewport caused by changing virtual aspect. So basically, I need something that will ignore virtual size and position the same way it ignores viewport size and position.
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 24th Jul 2018 15:04 Edited at: 24th Jul 2018 15:31
This post has been marked by the post author as the answer.
Have you tried

SetDisplayAspect(-1)

after setting the virtual resolution so you dont get any areas that arent inside your screen resolution. This just forces the current virtual resolution to fill the available area by stretching. That will affect ALL your sprites though. Not just the one background one.

Another option is to look up the screen bounds and set the sprite at those. Set position to top left then width and height to fill the screen



Personally, I stick to one resolution or the percentage system (aspect-less) to avoid having to do things like this.
TomToad
6
Years of Service
User Offline
Joined: 6th Jan 2018
Location:
Posted: 24th Jul 2018 16:13
GetScreenBoundsLeft/Right/Top/Bottom() did the trick. Scaled the background to those values and now everything looks great. Thanks for the help

Login to post a reply

Server time is: 2024-04-20 01:18:16
Your offset time is: 2024-04-20 01:18:16