LoginLogin
Might make SBS readonly: thread

Sprites 101 (for Beginners)

Root / Submissions / [.]

UltraPhoenix4Created:
So, you want to create programs and games! Well an essential part of those are little (sometimes big) things called sprites, and I'm going to teach you everything you need to know to start controlling sprites. (WARNING: THINGS STATED HERE ARE IN LAYMAN'S TERMS, A LOT) THERE IS A TL;DR AT THE END YOU LAZY PERSON

PART 1: WHAT THE HECK IS A SPRITE?!

I'm glad you asked title, a sprite is a 2-D image that is used in coding. Sprites can be used for many different purposes not covered in this tutorial. But mostly, sprites are used for things like players, enemies and objects that can interact with other things (Ex: player pushing a boulder or pressing a button).

PART 2: HOW DO I SPRITE!?

It's actually very simple in SmileBASIC, just go into EDIT mode and type this EXACTLY how you see it:
ACLS
SPSET 0,17
Wow, your very first sprite! Now let's break down the code. ACLS is used to clear EVERYTHING (Sprites, text, background tiles, etc.) and it is optional, but I reccomend that you put it at the start of all your programs to clear everything left by other programs. SPSET Is the command that "summons" the sprite the zero is the management number, that number is used to control that sprite and it is decided here it can be anywhere from 0 all the way to 511! You should remember the management number of your player, because it is used to control that sprite in all the other sprite commands. Now, the 17 is the sprite displayed. To find all the sprites and their corresponding sprite number open the Smile tool and go to the SPDEF tab.

PART 3: HOW DO I MOVE FISHY?!

This is kind-of complicated and I won't be able to break down ALL of the code, but open EDIT mode and type this in:
ACLS
SPSET 0,17
WHILE 1
STICK OUT SX, SY
X=X+SX
Y=Y-SY
SPOFS 0,X,Y
VSYNC 1
WEND
Use the circle pad to move the fish, wow you're on your way to understanding sprites! Now I'm going to try to break down the code and simplify it. WHILE 1 AND WEND are very similar to @LOOP and GOTO @LOOP, but I'm not going to explain it in this tutorial because this tutorial is about sprites you diploid. Okay, now to the juicy bits. STICK OUT just gets data from the circle pad's horizontal (left and right) and vertical (up and down) positions. Now, I'll explain the rest a bit faster to save time, the vertical position of the sprite is represented by Y and the horizontal X. The circle pad's are SY and SX, so when you move the Circle pad right, SX becomes greater and it adds to X and moves the sprite right with SPOFS. SPOFS is used for instantly moving a sprite to the x and y positions specified. 0 is the management number stated earlier in the tutorial, change it to another number to move other sprites. You HAVE to have previously "summoned" the sprite using SPSET before using any other command or else you'll get an error. X and Y are the X and Y coordinates that the sprite moves to. VSYNC 1 just creates some delay so everything doesn't happen instantly and your fish doesn't go flying offscreen.

TL;DR

Creating sprite:
ACLS
SPSET 0,17
Moving sprite:
ACLS
SPSET 0,17
WHILE 1
STICK OUT SX, SY
X=X+SX
Y=Y-SY
SPOFS 0,X,Y
VSYNC 1
WEND
Thank you for reading this tutorial, if you want to know more about sprites leave a suggestion in the comments and I'll try to reply!

Replying to:Defaultio
Make a BG 101... or an MML 127 *get it* *cough*
nah don't get it