BB___SPRITEXY

=SPRITEXY and SPRITEXY?= toc

Description
> These are two Just BASIC sprite commands.

SPRITEXY
> This command changes the x,y position of a sprite. The sprite will appear at its new coordinates after executing the DRAWSPRITES command. > It is a direct form of placing a sprite on an specific x,y coordinate. > If you want the sprite to move automatically on each DRAWSPRITES execution you should use SPRITEMOVEXY instead.

SPRITEXY?
> This command gets the current position of a sprite, and stores the values, x and y coordinates, in two variables.

> If your questions are: > Then this is your JB sprite command.
 * 1) Is the sprite out of view?
 * 2) How to know its position?
 * 3) It is behind the mouse pointer?



GraphicBox Control

 * 1) Print #Handle.Extension, "spritexy spritename 100 100"
 * 2) #Handle.Extension, "spritexy spritename 100 100"
 * 3) #Handle.Extension, "spritexy spritename ";var1;" ";var2

Graphics Type Window

 * 1) Print #Handle, "spritexy spritename 100 100"
 * 2) #Handle, "spritexy spritename 100 100"
 * 3) #Handle, "spritexy spritename ";var1;" ";var2

GraphicBox Control

 * 1) Print #Handle.Extension, "spritexy? spritename var1 var2"
 * 2) #Handle.Extension, "spritexy? spritename var1 var2"

Graphics Type Window

 * 1) Print #Handle.Extension, "spritexy? spritename var1 var2"
 * 2) #Handle.Extension, "spritexy? spritename var1 var2"

Hints
> Place useful hints about this keyword here

Example
//This example uses the image from this article. Save it to a folder of your choice and run these codes from the same folder.//

code format="lb" NOMAINWIN LOADBMP "BMP","sprite_jb_guy_1.bmp" Open "Just BASIC - Sprite Demo - SpriteXY" For Graphics_nsb_nf as #main #main "Trapclose [quit]" #main "AddSprite player BMP" Timer 256, [redraw] Wait

[redraw] #main "SpriteXY player ";INT(rnd(0)*100);" ";INT(rnd(0)*100) #main "Drawsprites" Wait

[quit] Timer 0 Close #main UNLOADBMP "BMP" End code

code format="lb" NOMAINWIN LOADBMP "BMP","sprite_jb_guy_1.bmp" Open "Just BASIC - Sprite Demo - SpriteXY?" For Graphics_nsb_nf as #main #main "Trapclose [quit]" #main "AddSprite player BMP" #main "SpriteXY player ";INT(rnd(0)*100);" ";INT(rnd(0)*100) #main "Drawsprites"

[knowPosition] #main "SpriteXY? player getX getY" notice "playerX: ";getX;" playerY: ";getY Wait

[quit] Timer 0 Close #main UNLOADBMP "BMP" End

code

Useful Functions
code format="lb" Place a useful function using this keyword here code