? Sprites 303 ("Advanced" Sprite Control) ● SmileBASIC Source

Sign In

Register
*Usernames are case-sensitive
Forgot my password
Contest results!

Sprites 303 ("Advanced" Sprite Control)

Welcome back, young spinny fish.

It is time I finish this tutorial series, so this one will be a lot longer than the other two. So let's get to it.

Sprite Collisions!

Learning how to detect when sprites collide is important for creating software. So here's how you do that!

SPCOL

So, to begin we'll need the SPCOL command, and all it does is tell SB to give you collision data for that specific sprite. You need to use this to use the other collision commands, so it's essential! To use it go into EDIT mode and type this: ACLS SPSET 0,17 SPCOL 0,TRUE Now I'll break down the code. SPCOL: The zero is the management number, TRUE means you want the collision area to grow or shrink depending on SPSCALE. Here's a visual of how the collision works. 1 is one sprite and 2 is another. |-----| 1 | 2 | |_____| The square is the collision area of 2 and it would be bigger or smaller if you used SPSCALE and said TRUE in SPCOL. I hope I explained that well, because we're moving on!

SPHITSP

Pros reading this are probably wondering, "Why didn't you include SPCOLVEC?" and the reason is that it's optional and this is a tutorial for people who don't know much about the commands. Also because I don't see the use of it. But I digress, SPHITSP is used to see if a certain sprite that has been "activated" using SPCOL is touching another activated sprite. Here's how you use it: ACLS SPSET 0,17 SPCOL 0,TRUE WHILE 1 SPRITEBEINGHITVARIABLE=SPHITSP(0) WEND SPRITEBEINGHITVARIABLE can be replaced by any variable, but the zero is the sprite that is touching something, or will be. SPRITEBEINGHITVARIABLE will be equal to the management number of the sprite it's touching. Pretty simple right? So you can have a sprite that you control, and if the hit variable is equal to a spriite that's an enemy, then your health would go down. And any other uses you can imagine! (that are also possible.)

Linking and Unlinking Sprites

Linking sprites is useful for some situations where you need two sprites to stick to one another, so here's how!

SPLINK

SPLINK is used to attach two sprites together, maybe two lovebird fish? yes. Let's do that. ACLS SPSET 0,17 SPSET 1,17 SPCOLOR 1,#MAGENTA SPOFS 1,32,0 SPLINK 0,1 SPOFS 0,100,100 Notice how they both move even though only the blue one was told to. They're inseparable! And also linked together... Let's tear them apart in the name of coding! But not before explaining SPLINK and SPCOLOR. SPLINK is pretty simple, it links one sprite (0), to another (1). That's it! SPCOLOR turns a sprite(1) to a specified color (#MAGENTA), although you can use RGB to get a VERY specific color.

SPUNLINK

SPUNLINK separates two linked sprites so they are independent of each other again. Just add these two commands to the end of the last group of commands. SPUNLINK 0 SPOFS 0,0,0 Now they're separated! You can reattach them if you want.

SPRITE ANIMATION

to be continued... (BTW you need a basic understanding of arrays to get this, so study up while I find a decent way to explain this.)
Author
UltraPhoenix4
Updated
Rating
6 votes
Categories
Keywords
  • sprites
  • tutorial
8 Comment(s) 12Me21 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS OSP Contest 2 Winner I won the second SmileBASIC Source OSP Contest! Programming Contest Second Year My account is over 2 years old Website I'd recommend using images instead of text art. randomous randomous Owner Robot Hidden Easter Eggs Second Year My account is over 2 years old Website Drawing I like to draw! Hobbies I only just now saw this because it got downvoted so much. Any particular reason? I haven't used sprites myself, but the tutorial looks good. Krondelo Krondelo Sorry if that wasn't clear, the hitbox itself is square yes, I just meant your example up above isn't. Why do you have like 8 wide on the top and then 5 wide on the bottom? UltraPhoenix4 UltraPhoenix4 First Year My account is over 1 year old Website Bees Hidden Easter Eggs Avatar Taboo I didn't change my avatar for 180 days Website I didn't mean for it to look like that... It looked square in the edit menu. I'll get it fixed. HumbleWario HumbleWario How does one save or use custom sprites? ElzoBro ElzoBro First Day Joined on the very first day of SmileBASIC Source Website Video Games I like to play video games! Hobbies Drawing I like to draw! Hobbies Well you have to use the SMILE button (assuming you haven't changed it) and press on the PAINT Tool. From there it's self explanatory you can edit over the existing sprites and press Save to make and name a GRP for it. To use them in your game make sure to LOAD the GRP Ex. LOAD"GRP4:GRP_NAME" Krondelo Krondelo Nice, but I think there is a problem with formatting where you show the collision box, it's not a box. Also I think you should try and explain how to use SPSCALE and how it effects the collision. UltraPhoenix4 UltraPhoenix4 First Year My account is over 1 year old Website Bees Hidden Easter Eggs Avatar Taboo I didn't change my avatar for 180 days Website Wow, really? How is it shaped?