Page 1 of 1

Sprite background image shifts on select, please help!

Posted: 13 February 2021, 18:35
by SardaukarWI
I'm working on Here Kitty Kitty and the player's hand of cards displays correctly, but when you select a card the background image shifts. The cards are in a single image of 13x4 images (52 card images) at 260px by 185px. How much it shifts and the direction of the shift is variable depending on its location in the overall image file available here. Note that these are images I scanned in myself as I haven't received the official images from Fireside Games yet, so they are grainy and some are a little crooked.

Before you select a card, the hand looks like this:
Image

After you select the first card in the row, the hand looks like this:
Image

These are stock items created using this function:

Code: Select all

createCardStockObject: function( element, selectable )
{
	console.log("createCardStockObject()");

	var stock = new ebg.stock();
	stock.create (this, element, this.CARDWIDTH, this.CARDHEIGHT);
	stock.image_items_per_row = 13;
	for (var x=0; x <= 51; x++) {
		stock.addItemType(x, x, g_gamethemeurl + 'img/Cards185x260.jpg', x );
	}
	if (selectable) {
		stock.setSelectionMode(2);
		dojo.connect( stock, 'onChangeSelection', this, 'onCardSelected' );
	}
	else {
		stock.setSelectionMode(0);
	}
	stock.onItemCreate = dojo.hitch( this, 'setupNewCard' ); 
	stock.extraClasses = 'cardStockItem';

	return stock;
},	
The setupNewCard() function is used to add the HTML ToolTip (which works fine) and the cardStockItem class in the CSS file is as follows:

Code: Select all

.cardStockItem {
	cursor: pointer;
	margin-right: 8px;
	height: 260px;
	width: 185px;
	box-sizing: border-box;
	border-radius: 10px;
}
I've looked at Just Desserts as an example of a working game that has this functionality but I'm at a loss of what is different here. Anyone have any ideas? I have to be missing something obvious here.

Thanks.

Re: Sprite background image shifts on select, please help!

Posted: 13 February 2021, 19:46
by Victoria_La
Play with your css in the browser debug tool by disabling one parameter at time to see if this has affect
Also try to rename cardStockItem - it may be actually collision with class defined already because it seems super generic.

Re: Sprite background image shifts on select, please help!

Posted: 13 February 2021, 21:06
by SardaukarWI
I found what appeared to be the offending CSS line coming from a parent element "element.style". It was "border-width". When it is not selected, the border-width is 0px. When it is selected, this changes to 1px. If I remove this in the browser, the card returns to normal. But then there is no longer a red border indicating the card has been selected.

I loaded a Just Desserts game and inspected the CSS on its cards between selected and unselected. It has the same border-width changing from 0px to 1px on selection. Though I did notice that I had "box-sizing" set to "border-box" and Just Desserts did not. So I removed this and now it is working fine.

You pointed me in the right direction. Thanks.

Re: Sprite background image shifts on select, please help!

Posted: 13 February 2021, 22:10
by Victoria_La
Yes I should have spotted it, border changes the size of the element, and normally size calculation are not affected, but with border-box sizing they are!
so cannot use it here (and why would you?)

Re: Sprite background image shifts on select, please help!

Posted: 13 February 2021, 22:35
by SardaukarWI
and why would you?
It was copied from the CSS class for an unrelated item where it was needed and wouldn't work without it. I'm not familiar with all the layout/CSS stuff. I only know enough to be dangerous and I steal shamelessly from other games. :)