This example shows how to move sprites by using the multitasking feature, assigning a movement routine to each sprite.
source
compile
sandbox
issues?
back to examples
BITMAP ENABLE (2) CONST spriteCount = 8 DEFINE TASK COUNT spriteCount DIM sprites AS SPRITE (spriteCount) DIM x AS POSITION (spriteCount) DIM y AS POSITION (spriteCount) spriteImage = LOAD IMAGE("drop.png") GLOBAL sprites,x,y,spriteImage PARALLEL PROCEDURE dropDown SPRITE [sprites] ENABLE DO [x] = RANDOM WIDTH FOR [y] = 0 TO SCREEN HEIGHT + IMAGE HEIGHT(spriteImage) SPRITE [sprites] AT [x], [y] COLOR BLUE NEXT LOOP END PROC drops = 0 dropskip = (BYTE) ( SPRITE HEIGHT * 2 ) FOR i=0 TO SPRITE COUNT -1 sprites(i) = SPRITE(spriteImage) NEXT SPAWN dropDown DO IF drops < (spriteCount-1) THEN DEC dropskip IF dropskip = 0 THEN SPAWN dropDown dropskip = SPRITE HEIGHT INC drops ENDIF ENDIF RUN PARALLEL LOOP
The instructions here refer to compiling the example from the command line. For Microsoft Windows
users we suggest using UGBASIC-IDE, which allows
you to download and compile each single example with just one click.
Are instructions for your specific home computer / console missing? First of all, check if your computer
is supported by clicking here. If so, since ugBASIC is a language which does not provide abstractions, it is possible
that this example will not work on your target. If you think this is an issue, please click here.
In order to compile the example, type this command on the command line:
Linux
ugbc.coleco -O rom -o sprites_example_02.rom sprites_example_02.bas
Windows
ugbc.coleco.exe -O rom -o sprites_example_02.rom sprites_example_02.bas
For Microsoft Windows users we suggest using UGBASIC-IDE, which allows
you to download and compile this example with just one click.
In order to compile the example, type this command on the command line:
Linux
ugbc.sc3000 -O rom -o sprites_example_02.rom sprites_example_02.bas
Windows
ugbc.sc3000.exe -O rom -o sprites_example_02.rom sprites_example_02.bas
For Microsoft Windows users we suggest using UGBASIC-IDE, which allows
you to download and compile this example with just one click.
In order to compile the example, type this command on the command line:
Linux
ugbc.sg1000 -O rom -o sprites_example_02.rom sprites_example_02.bas
Windows
ugbc.sg1000.exe -O rom -o sprites_example_02.rom sprites_example_02.bas
For Microsoft Windows users we suggest using UGBASIC-IDE, which allows
you to download and compile this example with just one click.
If you have found a problem trying to run this example, if you think there is a bug or, more
simply, you would like it to be improved, open an issue for this example on GitHub.
Thank you!
open an issue
BACK TO EXAMPLES