Ambiera Forum

Discussions, Help and Support.

Create a new account, Search, or Login:
Name: Password:
Ambiera Forum > CopperCube > Programming and Scripting
2D overlay placement correction script (for absolute position)
Author Text

Registered User
2022-03-22 13:48:16

After trying to use relative position for HUD in my main project, I found that the hud elements were stretching (or squeezing). This especially can be seen if someone will play with 4:3 monitor, since I am testing on 16:9. With absolute position I had a normally sized HUD, but if I would set this, for example, on 1400, then the poeple with monitor of lower resolution (I have 1920 by 1080) will see... Mostly nothing. So I tried to make a simple action that is, when executed, will correct placement of an overlay according to window size.

The script:
<action jsname = "action_CorrectHUD" description = "Correct HUD elements placement">

<property name = "Element" type = "scenenode"/>
<property name = "CorrectX" type = "bool">
<property name = "PosX" type = "int"/>
<property name = "CorrectY" type = "bool">
<property name = "PosY" type = "int"/>


action_CorrectHUD = function()

action_CorrectHUD.prototype.execute = function()
if (this.CorrectX == true)
var X = ccbGetScreenWidth();
var Width = ccbGetSceneNodeProperty (this.Element, "Width (pixels)");
ccbSetSceneNodeProperty (this.Element, "Pos X (pixels)", X - Width - this.PosX);
if (this.CorrectY == true)
var Y = ccbGetScreenHeight();
var Height = ccbGetSceneNodeProperty (this.Element, "Height (pixels)");
ccbSetSceneNodeProperty (this.Element, "Pos Y (pixels)", Y - Height - this.PosY);

Note: "PosX" and "PosY" means the position from left and bottom sides of window.

2022-03-26 23:14:31

looks good 'vdekon_17'.
If its the picture on the 2D overlay that you are concerned with being stretched then you can still keep '(percent)' placement to adjust for different monitors better but select 'Keep Aspect Ratio' to stop any streching that way also.

Create reply:

Posted by: (you are not logged in)

Enter the missing letter in: "I?ternational" (you are not logged in)




Possible Codes

Feature Code
Link [url] [/url]
Bold [b]bold text[/b]
Image [img][/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]



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