onScreenWidthChange function

Game development with Board Game Arena Studio
User avatar
hersh
Posts: 76
Joined: 12 December 2013, 23:49

onScreenWidthChange function

Post by hersh »

I noticed an empty function called onScreenWidthChange() in gameui. Can we use it or is reserved for other reasons? I can't find any documentation regarding it.

It appears better to use than onresize since it triggers when the playing area size changes even though the window has not. For example switching between log_mode = normal to 2cols

thanks
User avatar
Een
Posts: 3861
Joined: 16 June 2010, 19:52

Re: onScreenWidthChange function

Post by Een »

Well, then it's something missing in the documentation :)
You can use it, it's meant to be the way to react to a resizing of the game area.
User avatar
Brainchild
Posts: 71
Joined: 31 January 2014, 19:42

Re: onScreenWidthChange function

Post by Brainchild »

This is a nice callback. I have a couple of questions:

1. Is it safe to assume this will always be called before setup()?
2. Is it possible to add the width as a callback parameter?

If not, what is the recommended way to get the width? I am using

Code: Select all

let topbarCoords = dojo.position("topbar");
as I've seen you mention this technique in another thread.
User avatar
tchobello
Posts: 694
Joined: 18 March 2012, 13:19

Re: onScreenWidthChange function

Post by tchobello »

Brainchild wrote: 29 June 2020, 21:54

Code: Select all

let topbarCoords = dojo.position("topbar");
you can get width with topbarCoords.w

for instance, Dungeon Twister board adapts its size to window's width.
User avatar
Brainchild
Posts: 71
Joined: 31 January 2014, 19:42

Re: onScreenWidthChange function

Post by Brainchild »

tchobello wrote: 30 June 2020, 08:03you can get width with topbarCoords.w

for instance, Dungeon Twister board adapts its size to window's width.
I know, I'm wondering if this is the best way, and ideally if onScreenWidthChange can include the width value in the callback.

e.g. onScreenWidthChange(newWidth)
User avatar
JumpMaybe
Posts: 41
Joined: 20 June 2019, 14:25

Re: onScreenWidthChange function

Post by JumpMaybe »

The problem with using the topbar's width is there are 1 or 2 columns of player info + logs on the right (in desktop mode anyway) whose width you would have to subtract.

If you use

Code: Select all

dojo.position('page-title')
you get the actual width of the playing area. I'm using it since last week, so there might still be some trickyness with it I haven't run into.
User avatar
Brainchild
Posts: 71
Joined: 31 January 2014, 19:42

Re: onScreenWidthChange function

Post by Brainchild »

JumpMaybe wrote: 30 June 2020, 09:50 The problem with using the topbar's width is there are 1 or 2 columns of player info + logs on the right (in desktop mode anyway) whose width you would have to subtract.

If you use

Code: Select all

dojo.position('page-title')
you get the actual width of the playing area. I'm using it since last week, so there might still be some trickyness with it I haven't run into.
I switched to page-title but I'm unfortunately getting the same width value regardless of whether the player has "game log in second column" enabled. I'm pretty sure it's because that option hasn't been applied yet at the moment I check the width of page-title (in setup()).

It would be nice to have a BGA Studio official way of getting the width of the play area, accounting for any player layout options.
User avatar
Tisaac
Posts: 2743
Joined: 26 August 2014, 21:28

Re: onScreenWidthChange function

Post by Tisaac »

What about

Code: Select all

dojo.position('game_play_area')
?
User avatar
Brainchild
Posts: 71
Joined: 31 January 2014, 19:42

Re: onScreenWidthChange function

Post by Brainchild »

Tisaac wrote: 07 July 2020, 00:06 What about

Code: Select all

dojo.position('game_play_area')
?
I tried that but it doesn't exist yet in setup().
User avatar
Tisaac
Posts: 2743
Joined: 26 August 2014, 21:28

Re: onScreenWidthChange function

Post by Tisaac »

Then just use a conditional and call the function again in the onScreenWidthChange :

Code: Select all

updateSize: function(){
if($('game_play_area')){
  var w = dojo.position('game_play_area')['w'];
  ...
},


onScreenWidthChange: function(){
 this.updateSize();
 }
Post Reply

Return to “Developers”