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> */
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.
|