Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Digital Mosaic Games on Sun 10/03/2019 19:04:49

Title: Transparent areas for buttons
Post by: Digital Mosaic Games on Sun 10/03/2019 19:04:49
Hey guys,

I'd like to have a specific transparent area for a button which shouldn't be clickable(pink area)...
(https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/5c79d022-dfa5-49da-8ca4-8296b65565d4/dd1s1lj-adcbc1ac-609e-4ea9-8896-edfed6684f34.png?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7InBhdGgiOiJcL2ZcLzVjNzlkMDIyLWRmYTUtNDlkYS04Y2E0LTgyOTZiNjU1NjVkNFwvZGQxczFsai1hZGNiYzFhYy02MDllLTRlYTktODg5Ni1lZGZlZDY2ODRmMzQucG5nIn1dXSwiYXVkIjpbInVybjpzZXJ2aWNlOmZpbGUuZG93bmxvYWQiXX0.6G8XPZIOiRkpE_ukoqlvalAlcpfQ005BCJ5RGsMGm5k)

But at the moment I can only have a rectangle as clickable area for the button.
(https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/5c79d022-dfa5-49da-8ca4-8296b65565d4/dd1s1xt-455b25cd-be79-4d03-b3b6-d611c4558f67.png?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7InBhdGgiOiJcL2ZcLzVjNzlkMDIyLWRmYTUtNDlkYS04Y2E0LTgyOTZiNjU1NjVkNFwvZGQxczF4dC00NTViMjVjZC1iZTc5LTRkMDMtYjNiNi1kNjExYzQ1NThmNjcucG5nIn1dXSwiYXVkIjpbInVybjpzZXJ2aWNlOmZpbGUuZG93bmxvYWQiXX0.TFFi_S6ws9UJ-Bbx1tovm06njL6jCivMLOgT5OF5PG4)

Is there a way to make the pink/transparent area not clickable?

Thanks!
Title: Re: Transparent areas for buttons
Post by: Khris on Sun 10/03/2019 19:20:24
You can make that area not react to a click by doing a coordinate check.

Code (ags) Select
  int x = mouse.x - (control.OwningGUI.X + control.X);
  int y = mouse.y - (control.OwningGUI.Y + control.Y);


This gives you click coordinates inside the button rectangle. You can now either

a) use  if (x + y < 20) return;  for a basic check against the 45° edge

b) grab the pixel's color from the sprite using a DrawingSurface and GetPixel() and compare it to COLOR_TRANSPARENT
Title: Re: Transparent areas for buttons
Post by: Digital Mosaic Games on Sun 10/03/2019 20:28:06
Hi Khris, thank you very much for answering!
I tried the method (a) as you suggest and it is working fine. However how can I code the same thing regarding a button top right, down left and down right?
I mean these buttons...
(https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/5c79d022-dfa5-49da-8ca4-8296b65565d4/dd1sbgz-0a9fcd69-ba9d-412a-9e55-63fe6d4983c7.png?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7InBhdGgiOiJcL2ZcLzVjNzlkMDIyLWRmYTUtNDlkYS04Y2E0LTgyOTZiNjU1NjVkNFwvZGQxc2Jnei0wYTlmY2Q2OS1iYTlkLTQxMmEtOWU1NS02M2ZlNmQ0OTgzYzcucG5nIn1dXSwiYXVkIjpbInVybjpzZXJ2aWNlOmZpbGUuZG93bmxvYWQiXX0.uTmi7HtPm5WaRDL2zZ3n5VOTH4QPRgbF1bsVeG4hp2s)
Title: Re: Transparent areas for buttons
Post by: Khris on Sun 10/03/2019 20:57:59
Sure, all that changes is the expression in the check.

The top right one: y > x - 4
Bottom left: y < x + 6
Bottom right: y < 32 - x
Title: Re: Transparent areas for buttons
Post by: Digital Mosaic Games on Sun 10/03/2019 21:08:42
Thank you very much for your help it was greatly appreciated!