[Resolved] Changing background images must include g_gamethemeurl? Apparently a cache issue
Posted: 25 January 2021, 16:55
[edit]Apparently I had a browser cache issue where ctrl-F5 was not sufficient. Disabling caching in the dev tools, network section helped. You shouldn't need g_gamethemeurl after all. - Brian[/edit]
I had a challenge debugging this problem. I wanted to change the background image of a div, but when I tried it, the background image became blank.
I was trying make an animation of a dice cup shaking. I had two images: an animated gif and a png of the dice cup upright. I tried a number of ways to change the background image before finally hitting on something that worked.
Even changing classes to one with a different background-image doesn't work. After trying multiple ways to change the background image, I finally saw that it was related to the relative image url. "img/xxx" works fine in css to initialize divs during startup, but during play, "img/xxx" is interpreted as relative to the url during play, which doesn't include the entire img subdirectory.
Key point: the dev url and the play url are different. In other words:
Does not resolve during play:
https://studio.boardgamearena.com/1/xxx/img/yyy.png
Real path to image:
https://en.1.studio.boardgamearena.com: ... mg/yyy.png
g_gamethemeurl has a value like this:
https://en.1.studio.boardgamearena.com: ... 9999-9999/
It seem to find the real url of the img directory, I need to add the special variable g_gamethemeurl.
It seems that unless the background-image url was accessed during initialization before switching to the (I presume) temporary game play url, the image resources are not available.
Eventually I decided to use two divs with different background images and make one of them visible and the other invisible as needed.
I wanted to get this in the forum so others searching for change changing background-image backgroundImage can find this information. I didn't find it in the wiki - maybe I should post this in the wiki?
Where would it go?
If you do this, how are you changing background images on your divs during the game? Is there an easier way?
Thanks, Brian
I had a challenge debugging this problem. I wanted to change the background image of a div, but when I tried it, the background image became blank.
Code: Select all
// dojo.style blanks out the background image
dojo.style( 'dice_cup', 'backgroundImage', 'url(img/dice-cup.gif)' );
// jQuery style.backgroundImage blanks out the background image
$('dice_cup').style.backgroundImage = "url(img/dice-cup.gif)";
// Changing classes to one with a different background image blanks out the background image
dojo.removeClass( 'dice_cup', 'upright' );
dojo.addClass( 'dice_cup', 'shaking' );
// This works: you must use the variable g_gamethemeurl to get to the images
$('dice_cup').style.backgroundImage = "url(" + g_gamethemeurl + "img/dice-cup.gif)";
Does not resolve during play:
https://studio.boardgamearena.com/1/xxx/img/yyy.png
Real path to image:
https://en.1.studio.boardgamearena.com: ... mg/yyy.png
g_gamethemeurl has a value like this:
https://en.1.studio.boardgamearena.com: ... 9999-9999/
It seem to find the real url of the img directory, I need to add the special variable g_gamethemeurl.
Eventually I decided to use two divs with different background images and make one of them visible and the other invisible as needed.
I wanted to get this in the forum so others searching for change changing background-image backgroundImage can find this information. I didn't find it in the wiki - maybe I should post this in the wiki?
If you do this, how are you changing background images on your divs during the game? Is there an easier way?
Thanks, Brian