SPRITEXY

From Liberty BASIC Family
Jump to navigation Jump to search
Supported in Just BASIC Supported in Liberty BASIC Not supported in Liberty BASIC 5 Not supported in Run BASIC

Description

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:
  • Is the sprite out of view?
  • How to know its position?
  • It is behind the mouse pointer?
Then this is your sprite command.

Syntax

SPRITEXY

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

SPRITEXY?

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

The examples use the image from above. Save it to a folder of your choice and run these codes from the same folder.

Position the Sprite using SPRITEXY

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

Get the Sprites Position using SPRITEXY?

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

Useful Procedures

' Place a useful function or sub using this keyword here