[Tutorial] Using LD_SPAC:white to create selectable, pixel perfect rectangles.
#1

Hi all,

I've been a lurker for a fair few years now, but I think it's time I contributed a little myself.

I've noticed a couple of others have found this trick, but couldn't find any formal explanation of why it works so I thought I'd be the first to document it.

I'll try to keep this as concise as people.


What is LD_SPAC:white and why is it useful?
LD_SPAC:white is a plain, square, white texture. These four attributes have the following implications:
  • Texture: Normal text-based textdraws (and rectangles drawn using usebox=1) measure their height in letterheight; which is a fairly arbitrary scale that is near impossible to get perfect and more frequently than not is displayed differently on different screens. Because LD_SPAC:white is a texture, it uses the normal canvas system and therefore measures its height in pixels** as you would expect - meaning a LD_SPAC:white texture with a width and height of 128 pixels will be exactly 128x128.
  • White: The fact that it is white means that it can be coloured using TextDrawColor without any unintended consequences.
  • Plain, Square: Finally, the fact that it is plain (has no detail) and square means that it scales and stretches perfectly regardless of size - it looks the same at 1x1 as it does at 640x480.
Another useful implication of this is that because textures use the forecolor to paint themselves, and because the hovercolor in SelectTextDraw also uses forecolor, this means that the entire box will be highlighted in hovercolor rather than just the text (assuming anything in the foreground is not selectable).



Notice the highlighted grey box in the centre: although you can't see it in this screenshot, it being hovered over with the mouse.


Code example
Draws a red rectangle 50% the size of the screen starting at (25%, 25%). When player 0 hovers over with the mouse, the entire box will turn green.
Code:
TextDraw:td = TextDrawCreate(640.0 * 0.25, 480.0 * 0.25, "_");
TextDrawTextSize(td, 640.0 * 0.5, 480 * 0.5);
TextDrawColor(td, 0xFF0000FF);
TextDrawFont(td, 4);
TextDrawSetSelectable(td, true);
SelectTextdraw(0, 0x00FF00FF);
** SA-MP uses a 640x480 canvas for textdraws irrespective of screen resolution, so when I say pixel I mean 1 pixel respective to the canvas.
Reply
#2

Damn this is dope as fuck. Thanks for the tutorial!
+rep
Reply
#3

Great tutorial! +Rep.
Reply
#4

Its much better to use LD_PLAN:tvbase than this, because tvbase also support transparency. Plus the texture on it makes it look more cooler.
Reply
#5

Quote:
Originally Posted by Gammix
View Post
Its much better to use LD_PLAN:tvbase than this, because tvbase also support transparency. Plus the texture on it makes it look more cooler.
"More cooler" that is some horrible English
Reply
#6

Quote:
Originally Posted by Pottus
View Post
"More cooler" that is some horrible English
Thanks Pottus. REP+
Reply
#7

Quote:
Originally Posted by Gammix
View Post
Its much better to use LD_PLAN:tvbase than this, because tvbase also support transparency. Plus the texture on it makes it look more cooler.
Hi Gammix,

Thanks for the suggestion.

LD_SPAC:white can have alpha/transparency as well!:



Additionally - and please do correct me if I'm wrong as I haven't played around this in months and months now - but given that tvbase is black (I think?), doesn't that mean it can't be properly colourised, ie. 0xFF0000FF would set it to a dark red at best?
Reply
#8

Nice tutorial!
Reply
#9

Quote:
Originally Posted by Alcatrik
View Post
Hi Gammix,

Thanks for the suggestion.

LD_SPAC:white can have alpha/transparency as well!:



Additionally - and please do correct me if I'm wrong as I haven't played around this in months and months now - but given that tvbase is black (I think?), doesn't that mean it can't be properly colourised, ie. 0xFF0000FF would set it to a dark red at best?
Hi there. I noticed the issue with one of the LD_SPAC where you can only have transparency of their original color (so black can have a range of alpha only).

No i used tvbase here and was able to set good color combinations, i guess you can have most color but they would be a little dark. I don't recommend it but i find the tvbase texture a bit better than a plain sprite; as you mostly use them as background bars.
Reply
#10

That's a pretty cool fact to know - and that's a good looking gamemode that you've got there!
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)