Author |
Topic: spritescale and collision (Read 553 times) |
|
tsh73
Guest
|
|
spritescale and collision
« Thread started on: Feb 11th, 2012, 7:38pm » |
|
I wonder if SPRITESCALE should affect results of SPRITECOLLIDES? It is known that in LB it has a bug: Quote:What happens if you make the sprite smaller, is that the rectangle in which collision is detected becomes smaller faster.
Also, if you make the sprite larger, the collision box becomes larger than the sprite. (Try clicking some distance below or right from the rectangle.)
If the rectangle is reduced to 25%, only a 2*2 pixel area in the upper-left corner of the 8*8 sprite image detects collisions (original size 32*32).
The calculations are definetely off. |
| but in LBB it seems that collision box does not changes with SPRITESCALE at all:
Illustration: drawn sprite rectangle 25x25 at 50, 50 this starts with scale 100, spritecollides works ok, within sprite. Increasing scale (left mouse click), decreasing to 50% (right mouse click) - collision box does not change (original size) Code: nomainwin
global scale
scale = 100
UpperLeftX=1
UpperLeftY=1
WindowWidth= DisplayWidth
WindowHeight= DisplayHeight
open "Test - move your mouse, look for sprite hit, click left mouse for scale+, right for scale-" for graphics as #main
#main, "trapclose quit"
#main, "down; fill black; color red; backcolor green"
#main, "place 0 25; boxfilled 25 50"
#main, "getbmp sprite 0 0 25 50"
#main, "getbmp tester 0 0 1 1"
#main, "addsprite sprite sprite"
#main, "addsprite tester tester"
#main, "spritescale sprite ";scale
#main, "spritevisible tester off"
#main, "spritexy sprite 50 50"
#main, "cls; flush"
#main, "drawsprites"
#main, "when mouseMove test"
#main, "when leftButtonDown scalePlus"
#main, "when rightButtonDown scaleMinus"
wait
sub quit h$
unloadbmp "sprite"
unloadbmp "tester"
close #h$
end
end sub
sub test h$, x, y
#h$, "spritexy tester "; x; " "; y
#h$, "spritecollides tester s$"
#h$, "place 10 10"
#h$, "\SpriteScale "; using("####",scale); " Size ";25*scale/100;" "
#h$, "\pos "; using("####",x);using("####",y);" "
if s$ <> "" then #h$, "\sprite hit" else #h$, "\ "
end sub
sub redraw h$, a$
#h$, "drawsprites"
end sub
sub scalePlus h$, x, y
scale=scale*2
#h$, "spritescale sprite ";scale
call redraw h$, a$
call test h$, x, y
end sub
sub scaleMinus h$, x, y
scale=int(scale/2)
#h$, "spritescale sprite ";scale
call redraw h$, a$
call test h$, x, y
end sub
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: spritescale and collision
« Reply #1 on: Feb 11th, 2012, 8:30pm » |
|
on Feb 11th, 2012, 7:38pm, Guest-tsh73 wrote:I wonder if SPRITESCALE should affect results of SPRITECOLLIDES? |
|
In LBB it is supposed to. There's definitely code present to do that, but maybe it isn't working correctly.
Later Yes, looking at the code I think I can see what the bug is. I will fix it in the next release. Thanks for alerting me to it.
The reason I didn't spot it before is that if you scale both sprites by the same amount, the collision detection works properly! It's only when you scale the sprites differently (as you are) that it fails.
Richard.
|
|
|
|
|