|
|
|
|
Reply From: |
jgodfrey |
You can use something like this to check if a given bit is set (or not) in a given value:
func is_bit_set(value, bit):
return value & (1 << bit) != 0
In your case, the FLAG_REPEAT
is documented to have a value of 2
. So, that’d be bit position 2. So, to test for that, you can do:
var flags = tex.get_flags()
var is_set = is_bit_set(flags, 2)
Note, you need to pass the bit POSITION as the second argument, not the bit VALUE. So, for example, FLAG_FILTER
is value4
, so that’d be bit position 3
.
And, to Wakatta’s point, it doesn’t really matter if complex bit combinations are set. The above will correctly check if any given bit is set in a specified value.
Dang forgot about bitwise operations.
Fantastic answer.
Wakatta | 2023-01-03 03:44
Yeah, I didn’t even think about using them. Anyway thanks for the answers, they really helped me!
VitusVeit | 2023-01-03 12:57
A few things here after waking up today with a working brain…
First, it seems my bit positions are off by one in the above explanation. So, rather than the value of “1” being bit position “1”, it’s bit position “0” (and so on) - at least the way the provided method works.
Also, I realize that you’re really working with a bit VALUE (in the FLAG_*
enums) rather than a bit POSITION. With that in mind, this can be simplified to this:
func is_bit_val_set(value, bit_value):
return value & bit_value != 0
With that, you can simply pass the bit VALUE (rather than manually converting it to a bit POSITION - and running the chance of getting that wrong as I did above):
var flags = tex.get_flags()
var is_set = is_bit_val_set(flags, TEXTURE.FLAG_REPEAT)
jgodfrey | 2023-01-03 21:11