Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
Can CopperCube detect the resolution of a game's window internally? I tried with JavaScript and an error appears.

wild-master
Registered User
Quote
2018-04-22 18:30:10

I found this page:
https://stackoverflow.com/questi...


That page says this:
In vanilla JavaScript, this will give you the AVAILABLE width/height:

window.screen.availHeight
window.screen.availWidth


For the absolute width/height, use:

window.screen.height
window.screen.width


I tried this in CopperCube's scripting window:
var test = window.screen.height;
print(window.screen.height);


Using that code causes this error:
script:3:TypeError: window is undefined


Does CopperCube not support those functions?

Being able to detect the resolution of the game's window is not super important. I won't become depressed if it cannot be done.

My game uses mouse movement and knowing the resolution of the window would allow me to create a script that would automatically adjust the functionality of the X and Y positions of the mouse depending on the resolution of the game.

Example:
I hard-coded the numbers based on the assumption that I will always test my game with a resolution of 800 x 600. The top and bottom vertical halves have different effects, and the left and right horizontal halves also have different effects. I detect the exact position of the mouse to change the turning speed of the character, and I slightly alter it based on a setting that allows players to change the intensity of the turning speed. Some people want to turn faster, and some people want to turn slower.

I thought that automating the detection of the halfway points and writing one big script that accommodates all possibles levels of granularity would avoid the long-term stress of having to hard-code new numbers again every time I decide to change the resolution of my game. Haha.


tim12345
Guest
Quote
2018-04-22 21:02:21

i think you can do something like that using:

ccbGetScreenWidth();

ccbGetScreenHeight();



wild-master
Registered User
Quote
2018-04-22 21:08:29

I am so stupid!

I previously pressed "CTRL + F" to check the JavaScript Reference page for the word "resolution" instead of "width" and "height" and missed those functions.

They solve my problem!

I'm foolish like a toddler!

Thanks Tim.


wild-master
Registered User
Quote
2018-04-22 22:49:47

I implemented resolution-independent mouse movement in my game!

I feel rejuvenated!


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Inte?national" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact