Hi guys. I think I may have found a bug, or at the very least an inconsistency, in the GetSpriteHitTest command when used with fixed sprites and a view offset. I was getting very confused working on my current project and so I ran the following test; the results of which I've added in a comment block at the bottom. The test goes through the various permutations of text and sprite hits tests, using screen and world coordinates, with fixed and not-fixed sprites, with and without a view offset. The test was run in Tier 1 beta 12.
SetVirtualResolution(800, 600)
sprite = CreateSprite(0)
SetSpriteColor(sprite, 255, 0, 0, 255)
SetSpriteSize(sprite, 200, 100)
SetSpritePosition(sprite, 400, 100)
text = CreateText("Hello World")
SetTextSize(text, 30)
SetTextPosition(text, 400, 100)
// comment out for not fixed
//FixSpriteToScreen(sprite, 1)
//FixTextToScreen(text, 1)
// comment out for not offset
//SetViewOffset(100, 100)
do
// comment out for screen coords
x# = ScreenToWorldX(GetPointerX())
y# = ScreenToWorldY(GetPointerY())
// comment out for world coords
//x# = GetPointerX()
//y# = GetPointerY()
print("Sprite Hit: " + Str(GetSpriteHitTest(sprite, x#, y#)))
print("Text Hit: " + Str(GetTextHitTest(text, x#, y#)))
Sync()
loop
remstart
FIXED
SCREEN COORDS
OFFSET
TEXT
Expected Result: Accurate
Actual Result: Accurate
SPRITE
Expected Result: Accurate
Actual Result: Inaccurate
NOT OFFSET
TEXT
Expected Result: Accurate
Actual Result: Accurate
SPRITE
Expected Result: Accurate
Actual Result: Accurate
WORLD COORDS
OFFSET
TEXT
Expected Result: Inaccurate
Actual Result: Inaccurate
SPRITE
Expected Result: Inaccurate
Actual Result: Accurate
NOT OFFSET
TEXT
Expected Result: Accurate
Actual Result: Accurate
SPRITE
Expected Result: Accurate
Actual Result: Accurate
NOT FIXED
SCREEN COORDS
OFFSET
TEXT
Expected Result: Inaccurate
Actual Result: Inaccurate
SPRITE
Expected Result: Inaccurate
Actual Result: Inaccurate
NOT OFFSET
TEXT
Expected Result: Accurate
Actual Result: Accurate
SPRITE
Expected Result: Accurate
Actual Result: Accurate
WORLD COORDS
OFFSET
TEXT
Expected Result: Accurate
Actual Result: Accurate
SPRITE
Expected Result: Accurate
Actual Result: Accurate
NOT OFFSET
TEXT
Expected Result: Accurate
Actual Result: Accurate
SPRITE
Expected Result: Accurate
Actual Result: Accurate
remend
As you can see from my results, the anomaly is that fixed sprites seem to require world coordinates for the hit test to work, whilst fixed text requires screen coordinates. I'm not sure if this is a bug or just an inconsistency but either way, it sure as hell confused me
. I don't remember coming across this issue before, but then I don't often do text hit tests. As I recall, I noticed this change when I upgraded my project from v106 to v10811, but that's quite a wide spectrum in which it could have occurred. In some ways, I prefer fixed sprites using world coords, as it allows me to convert the pointer coords once and use them both for in game objects (not fixed) and the HUD (fixed), but either way, I think it would be better if text and sprites were consistent. Can anyone else check my results though, just to make sure I've not messed something up? All that commenting lines in and out did leave some margin for error I guess. Thanks.