LB Booster
« spritescale and collision »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 03:53am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: spritescale and collision  (Read 552 times)
tsh73
Guest
xx 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 

User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx 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.
« Last Edit: Feb 11th, 2012, 8:33pm by Richard Russell » User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls