? Showing sprite hitboxes ● SmileBASIC Source

Sign In

Register
*Usernames are case-sensitive
Forgot my password

Showing sprite hitboxes

SmileBASIC does not provide a native method of drawing sprite hitboxes, but this is really easy to implement. DEF SHOW_HITBOX ID%, COL% VAR X%,Y%,W%,H%,XX%,YY%,S%,SX%=1,SY%=1 SPOFS ID% OUT XX%,YY% SPCOL ID% OUT X%,Y%,W%,H%,S% IF S% THEN SPSCALE ID% OUT SX%,SY% GBOX XX%+X%*SX%,YY%+Y%*SY%,XX%+(X%*SX%+W%*SX%-1),YY%+(Y%*SY%+H%*SY%-1) END Usage: SHOW_HITBOX Management number, drawing color Example: SPSET 0,0 SPCOL 0,1 SHOW_HITBOX 0,#GREEN SPOFS 0,200,120 SHOW_HITBOX 0,#RED You should see a small green box at the top-left corner, and a big red box somewhat at the center of the screen. If you are going to run this in a loop, I suggest clearing the graphics screen every frame.
Author
Perska
Updated
Rating
2 votes
Categories
Keywords
  • sprite
  • hitbox
6 Comment(s) CyberYoshi64 CyberYoshi64 Night Person I like the quiet night and sleep late. Express Yourself Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength You missed the COL% in GBOX instructions. It will use GCOLOR(), which is the default if the color argument is omitted. seggiepants seggiepants If you put a $ at the end of a variable it is a string (example: VAR s$ = "Hello World") If you put a # at the end of a variable it is a floating point number (example: VAR s# = 3.14159) If you put a % at the end of a variable it is an integer (example: VAR s% = 3) If you put OPTION STRICT at the top of your code SmileBasic will require that variables are declared before being used. Using the type specifiers might make the code somewhat ugly, but they can really save you when it comes time to debug things. You can spend hours tracing down something only to find that you misspelled something, or used the wrong data type. Then when you fix it you won't even feel triumphant, just dumb for not having done things right in the first place. In the absence of a better option I use them in my own code. On topic, it looks like a nice and useful code snippet, nice work. ran4erep ran4erep Pokemon Is Awesome! I love Pokemon! Express Yourself Video Games I like to play video games! Hobbies Zelda Is Awesome! I love The Legend Of Zelda! Express Yourself Personally I writing only dollar sign to string variables. And don's using percent sign to indicate integers, integers and floating points in my code are without any signs. ran4erep ran4erep Pokemon Is Awesome! I love Pokemon! Express Yourself Video Games I like to play video games! Hobbies Zelda Is Awesome! I love The Legend Of Zelda! Express Yourself Nice function, but why you writing % after variable name? Smile Basic does'nt need it. You can type just variable name. And there are no need in VAR function either, you can just write SX=1:SY=1 in that line. Every variable creating when u use it, even if it not declared spaceturtles spaceturtles Video Games I like to play video games! Hobbies Avatar Block I didn't change my avatar for 30 days. Website Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength some people like type restrictions Y_ack Y_ack VAR explicitly declares variables in the local scope. This will prevent conflict with any globals sharing the same name. Using the % variable suffix is notation for explicit integer type. It's a little more efficient to use integers for integer operations rather than convert between them and the default (real number) type. For function parameters it also provides a hint as to what arguments are expected. If COL were a string (COL$) you might guess that it takes a color name instead of a packed RGB value. What SmileBASIC "does'nt need" [sic] and what it is good practice to do are different things. % suffix is usually messy and should be omitted in examples, yes, but this resource is 2 years old and that was the convention back then.