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!

Management numbers are from 0 to 511, not 0 to 999! Otherwise, it seems to be a pretty good tutorial :) Maybe add SPANIM, SPDEF?

Replying to:Minxrod
Management numbers are from 0 to 511, not 0 to 999! Otherwise, it seems to be a pretty good tutorial :) Maybe add SPANIM, SPDEF?
Thanks! I fixed the error. I'm going to wait a bit and maybe make a part 2 out of all the questions.

Replying to:Minxrod
Management numbers are from 0 to 511, not 0 to 999! Otherwise, it seems to be a pretty good tutorial :) Maybe add SPANIM, SPDEF?
0 to 511, not 512. :) There are 512 entries for sprites, but since 0 counts as the first entry, management numbers end at 511.

Replying to:Minxrod
Management numbers are from 0 to 511, not 0 to 999! Otherwise, it seems to be a pretty good tutorial :) Maybe add SPANIM, SPDEF?
*Facepalm*

More of these, please!

this tutorial is about sprites you diploid
why call people "having two complete sets of chromosomes"

Replying to:Lacks
More of these, please!
What should it be about? (Advanced sprites, simple BG, or something else?)

Replying to:joelable
this tutorial is about sprites you diploid
why call people "having two complete sets of chromosomes"
Because it sounds like an insult but isn't really.

Replying to:joelable
this tutorial is about sprites you diploid
why call people "having two complete sets of chromosomes"
you diploid

Replying to:joelable
this tutorial is about sprites you diploid
why call people "having two complete sets of chromosomes"
might as well use clod

Replying to:joelable
this tutorial is about sprites you diploid
why call people "having two complete sets of chromosomes"

Replying to:joelable
this tutorial is about sprites you diploid
why call people "having two complete sets of chromosomes"
Also clod IS an insult

Replying to:Minxrod
Management numbers are from 0 to 511, not 0 to 999! Otherwise, it seems to be a pretty good tutorial :) Maybe add SPANIM, SPDEF?
it's not ALWAYS 0-511 in XSCREEN modes that use the top and bottom screen (except 4), you can have 512 TOTAL. for example, XSCREEN 3 gives the top screen 512 sprites (0-511), but the bottom screen can't use ANY! you can do XSCREEN 3,75 (for example), to give the top screen 75 sprites (0-74) , and the bottom screen 512 minus 75 (437) sprites (0-436).

Replying to:Minxrod
Management numbers are from 0 to 511, not 0 to 999! Otherwise, it seems to be a pretty good tutorial :) Maybe add SPANIM, SPDEF?
Well if somebody needs this tutorial they probably don't need to use XSCREEN yet. But good point.

Replying to:Lacks
More of these, please!
Advanced sprite usage, like linking, collision, animation etc. Actually you could do damn near any function in layman's terms and I would find it very useful. I wish there was more tutorials on this program. It would cut down (theoretically) on all the "how do I save?" "How do I link the sword to my sprite" threads I see every so often.

Replying to:Lacks
More of these, please!
They could be cut down by just linking them to the resource and then having an admin delete the thread.

Replying to:Lacks
More of these, please!
Yeah, but the resource list isn't designed for someone with no clue about code. And that attitude doesn't breed a strong community.

Replying to:Lacks
More of these, please!
I need Simple BG, and then Sprite Collision please.

Replying to:Lacks
More of these, please!
Then I guess I'll write Sprite 303 later

Make a BG 101... or an MML 127 *get it* *cough*