Why doesn't it appear at the x,y I type in?
The reason why your sprite is always appearing at 0, 0 is because that is the default sprite position. Your x, y coordinates are telling the sprite scan command where on the screen to scan. That scan is put into the sprite that is located (by deafult) at 0, 0. You need to move the sprite after creating it if you want it to appear elsewhere.
Here I've added a line of code that moves the sprite to the same x, y it was scanned from:
Code: Select all
x=20 ! y=500 ! w=800 ! h=300
n$="sprite1"
sprite n$ scan x,y, w,h
sprite n$ at x, y
sprite n$ show
How do I change the color?
What is happening in your program (assuming no other lines of code before or after what you shared) is that you are scanning the graphics screen (which by default is solid black) to the sprite and then showing the sprite while the program is in TEXT mode (the default mode programs start in, which is solid white).
To better see this, switch to GRAPHICS mode and change the screen color in between scanning and showing the sprite:
Code: Select all
graphics
graphics clear 1, 0.5, 0.5 ' make the entire screen red (this will end up being scanned to the sprite)
x=20 ! y=500 ! w=800 ! h=300
n$="sprite1"
sprite n$ scan x,y, w,h
graphics clear 0.5, 0.5, 1 ' make the entire screen blue (allows the scanned sprite to be distinguishable when shown)
sprite n$ at x, y
sprite n$ show
Can I draw rectangles, buttons etc on it?
You can either draw to the main graphics screen with DRAW and FILL commands, and then scan that part of the screen to a sprite, or (more conveniently) you can draw directly to the sprite, which smart Basic treats as its own graphics layer.
In this example, I removed the SPRITE SCAN and replaced it with SPRITE BEGIN and SPRITE END, which is how you draw to a sprite:
Code: Select all
graphics
graphics clear 0.5, 0.5, 1 ' screen background (blue)
x=20 ! y=500 ! w=800 ! h=300
n$="sprite1"
sprite n$ begin w,h
graphics clear 1, 0.5, 0.5 ' sprite background (red)
/*
Put any draw/fill commands you want here, but recognize that coordinates
are relative to the sprite (regardless of where the sprite is located on the
screen). So anything drawn past the sprite's width and height will not be
visible, just like trying to draw outside your screen's width and height on
the main graphics window. Also, note that what you draw here will not be
visible on screen until the sprite is visible.
*/
sprite end
sprite n$ at x, y
sprite n$ show