showing image in tooltip?
Posted: 01 September 2024, 19:08
Hi, I'm having trouble learning how to show an image in a tooltip within my game.
The game I'm working on is "dragonchess", and is a pretty close copy of the "chess" game on bga. So for most purposes we can reference the chess game - it'll answer my questions all the same
I have been able to add a very basic tooltip, text only, showing the piece name. I did this by adding the "title" property to the definition in the .tpl file:
-- Before
-- After
and in the .js file, this is "populated" via loop/substitution using this:
-- Before
-- After
And that works great ... nice, simple, basic.
However, I would like to add an image. That is, an image showing how that piece moves. However, for now . just an image , ANY image .. I've been unable to get working.
I've tried looking at how other games do it, but can't quite figure out how to get it working.
I've tried adding a div/img element within the .tpl line:
or
(gathered from looking at this site:
https://www.geeksforgeeks.org/how-to-ma ... -an-image/
)
I tried to mimic what Burgle Bros does ...
-- Burgle Bros
But no matter how much I try, I can't quite get that nesting to work.
What am I missing? I am kind of new to this, so learning as I go, but I can't seem to figure out the basics of this.
What's the "simplest" way to display an image as a tooltip in BGA games ? (or specifically, looking at the "Chess" game?)
The game I'm working on is "dragonchess", and is a pretty close copy of the "chess" game on bga. So for most purposes we can reference the chess game - it'll answer my questions all the same
I have been able to add a very basic tooltip, text only, showing the piece name. I did this by adding the "title" property to the definition in the .tpl file:
-- Before
Code: Select all
var jstpl_piece = '<div id="piece_${piece_id}" class="clickable dragonchess_piece ${piece_color}_piece ${piece_type}_symbol"></div>';
Code: Select all
var jstpl_piece = '<div id="piece_${piece_id}" class="clickable dragonchess_piece ${piece_color}_piece ${piece_type}_symbol" title="${piece_name}"></div>';-- Before
Code: Select all
dojo.place( this.format_block('jstpl_piece', {
piece_id:piece.piece_id,
piece_color:piece.piece_color,
piece_type:piece.piece_type
} ), $ ( $board ) );Code: Select all
// capitalize the name of the piece
var piece_name = piece.piece_type.charAt(0).toUpperCase() + piece.piece_type.substring(1).toLowerCase();
dojo.place( this.format_block('jstpl_piece', {
piece_id:piece.piece_id,
piece_color:piece.piece_color,
piece_type:piece.piece_type,
piece_name:piece_name
} ), $ ( $board ) );However, I would like to add an image. That is, an image showing how that piece moves. However, for now . just an image , ANY image .. I've been unable to get working.
I've tried looking at how other games do it, but can't quite figure out how to get it working.
I've tried adding a div/img element within the .tpl line:
Code: Select all
var jstpl_piece = '<div id="piece_${piece_id}" class="${piece_color}_${piece_type}_piece" style="background-image: url('img/game_icon.png');"></div>';Code: Select all
var jstpl_piece = '<div id="piece_${piece_id}" class="${piece_color}_${piece_type}_piece"><span class="tooltip"><img src=url('img/game_icon.png')></span></div>';https://www.geeksforgeeks.org/how-to-ma ... -an-image/
)
I tried to mimic what Burgle Bros does ...
-- Burgle Bros
Code: Select all
var jstpl_patrol_tooltip = '<div id="patrol_tooltip_${patrol_floor}" class="card tooltip" style="background-image: url(${bg_image}); background-position: ${bg_position}; background-size: 1440px;">${patrol_discards}</div>';
var jstpl_patrol_tooltip_discard = '<div class="patrol-discard" style="left: ${discard_left}px; top: ${discard_top}px; background-image: url(${bg_image});"></div>';
patrolCardHtml: function(card, bg_id, discards) {
...
discardHtml = '<div class="patrol-discard-container">';
for(var discardId in discards) {
if (discardId != card.id) {
var discard = discards[discardId];
var discardIndex = parseInt(discard.type_arg, 10) - 1;
var discard_top = Math.floor(discardIndex / 4) * 62;
var discard_left = (discardIndex % 4) * 62;
discardHtml += this.format_block('jstpl_patrol_tooltip_discard', {
discard_left: discard_left,
discard_top: discard_top,
bg_image: g_gamethemeurl + 'img/patrol.jpg',
});
}
}
discardHtml += '</div>';
return this.format_block('jstpl_patrol_tooltip', {
patrol_floor: card['location'][5],
patrol_discards: discardHtml,
bg_image: g_gamethemeurl + 'img/patrol.jpg',
bg_position: bg_col.toString() + '% ' + bg_row.toString() + '%'
});
What am I missing? I am kind of new to this, so learning as I go, but I can't seem to figure out the basics of this.
What's the "simplest" way to display an image as a tooltip in BGA games ? (or specifically, looking at the "Chess" game?)


