[SOLVED]round gui for a minimap

Started by lafouine88, Wed 12/06/2024 22:24:19

Previous topic - Next topic

lafouine88

Hi guys

I'm currently working on a minimap for my RPG game. It was much easier than, I expected. Though, I'm having a display issue.

Basically, I created a gui, in it I put a button with the map picture as background image and another button on top, in the middle with an arrow skin (in 8 directions).
And it goes :

Code: ags
function room_RepExec()
{
 Btnfondminimap.X=64-(player.x/10);   ///map size in 10 times smaller than the original one
 Btnfondminimap.Y=40-(player.y/10);
 Btnarrowminimap.NormalGraphic=3220+player.Loop;  ///3220 is the arrow facing down, then the 7 others follow the standard directions
}

Everything is very promising. Still, I wanted my minimap to be round :s, like in Titan quest or WOW. And I don't know how to "crop" the map button so that it would be a round shape instead of a square one. I'm pretty sure that is not possible like this, but I thought maybe there was a clever way to limit the size of my button to a round 50px radius image.

Any ideas or shall I just go with a square standard minimap?^^

Thanks :)

FortressCaulfield

Could you disguise it with an image overtop with a round hole in the middle? So the map itself would be round but it would have to be on a square background
"I can hear you! My ears do more than excrete toxic mucus, you know!"

-Hall of Heroes Docent, Accrual Twist of Fate

Khris

#2
It can be done using DynamicSprite.CopyTransparencyMask(int fromSpriteSlot)

Create and import a sprite that contains a filled circle (i.e. has the transparency mask you need)
Each game loop
1. create a DynamicSprite from the map sprite and use the player coordinates to crop it
2. use the above command to copy the transparency mask from the circle sprite to your dynamic map sprite
3. assign the GUI-sized and rounded sprite as your GUI's background image

Note that the DynamicSprite pointer has to be declared above your room_RepExec function as opposed to inside it.

Something like this:

Code: ags
DynamicSprite* map;

function room_RepExec()
{
 map = DynamicSprite.CreateFromExistingSprite(MAP_SLOT);
 map.Crop(player.x / 10 - 64, player.y / 10 - 40, gMinimap.Width, gMinimap.Height);
 map.CopyTransparencyMask(CIRCLE_SLOT);
 gMinimap.BackgroundGraphic = map.Graphic;
 Btnarrowminimap.NormalGraphic = 3220 + player.Loop;
}

(You can also get rid of the arrow button, too, and draw the arrow onto the map sprite if you want)

lafouine88

@FortressCaulfield , This would work, it was my last resort solution. But that would mean the covering image would need to be a square as well, to be able to cover the whole thing. I would have prefered a lighter interface.

@Khris This is exactly it!! I really need to understand how dynamic sprites work, this is so powerfull 8-0 .

Thanks a million <3

SMF spam blocked by CleanTalk