INFO
|
|
Sprite Candy comes with many additional commands to assist the creation of 2D games or -animations. These commands can be used to simplify your work and to keep your own code as clean as possible. New commands will be added on demand, so please feel free to send us your feedback and suggestions.
Hint: when using distance checks and collision commands with many objects at once or within a loop, you should do a simple x / y coordinate check before and use collision or distance checks if the objects are close enough only. This will avoid slowdowns and keep your game's performance as high as possible. Another good practice is to perform collision checks every second frame only, which can save up to 50% performance.
|
|
USEFUL COMMANDS
|
|
|
MISCELLANEOUS |
HUD_GetStats$
|
|
|
stats$ =
HUD_GetStats$ (
)
|
This command returns a text string containing useful realtime information like the current FPS count, as well as the number of surfaces, vertices, objects and effects used by Sprite Candy. Use this information to keep an eye on your game's performance.
|
|
HUD_GetObjectType$
|
|
|
object_type$ =
HUD_GetObjectType$ (
Object_Handle%
)
|
This command returns a string that describes the type of an object (text, image, shape etc.). It can be used with a button check, for example, to find out wether a text or an image button has been clicked.
Returns:
"TEXT"
"IMAGE"
"TILED IMAGE"
"SHAPE"
Object_Handle%
Handle of an object (text, image, shape etc.)
|
|
|
HUD_GetObjectLayer
|
|
|
layerID% =
HUD_GetObjectLayer (
Object_Handle%
)
|
This command returns the Sprite Candy handle of the object's parent layer.
Object_Handle%
Handle of a Sprite Candy object (text, image, shape etc.)
|
|
HUD_CreateCopy
|
|
|
Object_Handle% =
HUD_CreateCopy (
Object_Handle%
[offset_x%],
[offset_y%]
)
|
This command creates an exact copy of the specified object and can be used to duplicate objects easily. If no offset is specified, the copy will be placed at the source object's position.
Object_Handle%
Handle of an object (text, image, shape etc.) to be duplicated.
offset_x% , offset_y%
By default, the duplicate will be placed at the source object's position. You can specify an x- and y-offset that the duplicate will be moved by.
|
|
HUD_AlignToScreen
|
|
|
HUD_AlignToScreen (
Object_Handle%,
xAlign$,
[yAlign$]
|
Using this command, you can position an object at a specified screen position, regardless of the current screen resolution.
Object_Handle%
Handle of an object (text, image, shape etc.)
xAlign$
" " (empty) - The object's current x-position will not be changed.
"LEFT" - Object will be placed at the left screen border, regardless to the current screen resolution.
"CENTER" - Object will be centered on screen horizontally, regardless to the current screen resolution.
"RIGHT" - Object will be placed at the right screen border, regardless to the current screen resolution.
Hint: You can also use offsets: "CENTER+50" or "RIGHT-25", for example!
yAlign$
" " (empty) - The object's current y-position will not be changed.
"TOP" - Object will be placed at the top screen border, regardless to the current screen resolution.
"CENTER" - Object will be centered on screen vertically, regardless to the current screen resolution.
"BOTTOM" - Object will be placed at the bottom screen border, regardless to the current screen resolution.
Hint: You can also use offsets: "CENTER+50" or "BOTTOM-50", for example!
|
|
HUD_FaceObject
|
|
|
HUD_FaceObject (
SourceObject%,
TargetObject%
)
|
This command will turn the source object so that if faces the target object with it's negative y-axis (top). You can also use the similar FX-command to turn an object smoothly to another.
SourceObject% , TargetObject%
Object handles (text, image, shape, etc.) of a source and a target object. The source object will be turned to face the target object.
|
|
HUD_ObjectExists
|
|
|
flag% =
HUD_ObjectExists (
Object_Handle%
)
|
This command can be used to check wether an object still exists or not. Use it if you applied the FX_AutoRemove effect to an object and need to know if this object has been deleted already or not, for example.
Returns TRUE if the specified object exists, otherwise FALSE.
Object_Handle%
Handle of an object (text, image, shape etc.)
|
|
HUD_RippleObject
|
|
|
HUD_RippleObject (
Object_Handle%,
width#,
height#,
[offset#],
)
|
This command 'ripples' an object underwater-like and can be used to create rippled sine texts, for example. You can specify the horizontal size of the wave as well as its height. This effect looks as better as more vertices an objects owns (texts objects, for example). This command produces a static effect (not animated). You can also apply an animated ripple effect by using HUD_FX_Ripple (see 'Effects').
You can remove a ripple effect by using HUD_RippleObject ( Object_Handle, 0 )
Object_Handle%
Handle of an object (text, image, shape etc.)
width#
Setting this parameter to 0 deactivates the ripple effect.
The 'width' or frequency of the wave. Higher values will produce narrow waves that are repeated more often, where lower frequencies produce big and long waves. For good results, use a value between 1 and 5, for example.
height#
The 'height' of the wave. Good results will be achieved with a value of 10, for example.
offset#
Using this parameter you can set an offset to 'shift' the wave to the left or right.
|
|
COLLISION CHECK |
HUD_GetDistance
|
|
|
distance% =
HUD_GetDistance (
x1%,
y1%,
x2%,
y2%
)
|
Returns the distance, in pixels, between to specified points.
x1% , y1% , x2% , y2%
Coordinates of two points to check.
|
|
HUD_GetPointLineDistance
|
|
|
distance% =
HUD_GetPointLineDistance (
px%,
py%,
x1%,
y1%,
x2%,
y2%
)
|
Returns the distance, in pixels, between a point and a line. Can be used to check if a laser hits an object, for example.
px%, py%
Coordinates of a point.
x1% , y1% , x2% , y2%
Coordinates to define a line.
|
|
HUD_GetObjectDistance
|
|
|
distance% =
HUD_GetObjectDistance (
Object_Handle1%,
Object_Handle2%
)
|
Returns the distance, in pixels, between two objects' center points. If the objects are placed on different layers that are scaled or rotated differently, the objects' coordinates are transformed automatically from one layer's coordinate system to the other.
Object_Handle1% , Object_Handle2%
Handles of two objects to check.
|
|
HUD_ObjectHitsPoint
|
|
|
flag% =
HUD_ObjectHitsPoint (
Object_Handle%,
x%,
y%,
[SourceLayer%]
)
|
Returns TRUE or FALSE. Indicates if a specified x / y coordinate is inside an object's boundaries, also if the object has been rotated. Can be used with MouseX() and MouseY(), for example, to check if the mouse is placed over an object. This command uses the coordinate system of the object's parent layer (which can differ from absolute screen coordinates when the layer is rotated or scaled).
Object_Handle%
Handle of an object (text, image, shape etc.)
x% , y%
Any x / y coordinate within the object's parent layer, another layer or absolute screen coordinates.
SourceLayer%
If not specified, Sprite Candy assumes that the given x / y coordinate is on the same layer as the object.
Use 0 if x / y are absolute screen coordinates and should be converted to the object's layer.
If the specified x / y coordinate is placed on another layer, specify the layer's handle here to convert it to the object's layer.
Note: the coordinate systems of layers and absolute screen coordinates are all the same as long as HUDs and layers are not rotated or scaled. In this case you won't need this parameter. If a layer has been scaled or rotated, however, the coordinate systems of two layers may be different, or differ from absolut screen coordinates then. In this case, the x / y - coordinate must be converted to the object layer's coordinate system.
|
|
HUD_ObjectHitsObject
|
|
|
flag% =
HUD_ObjectHitsObject (
Object_Handle1%,
Object_Handle2%
)
|
Returns TRUE or FALSE. Indicates if the boundaries of two objects (texts, images, shapes etc.) intersect each other. This command also works with rotated objects, but is faster when used with non-rotated objects, of course.
Object_Handle1% , Object_Handle2%
Handles of two objects to check.
|
|
HUD_LinesIntersect
|
|
|
flag% =
HUD_LinesIntersect (
x1%, y1%, x2%, y2%, x3%, y3%, x4%, y4%
)
|
Returns TRUE or FALSE. Indicates if two lines intersect each other. The exact point of intersection will be stored within two globals named SC_IntersectedX and SC_IntersectedY.
x1% , y1% , x2% , y2%
Coordinates of the first line.
x3% , y3% , x4% , y4%
Coordinates of the second line.
|
|
COLLISION SHAPES |
To give the possibility for more precise collision checks with irregular shaped objects, Sprite Candy supports collision shapes. A collision shape is a virtual polygon shape around an object. Such a shape is built by single points that you can define. Collision shapes can be added to any object (and also be removed again) at any time - either point by point or loaded from a point data file. After attaching a collision shape to an object, you can test if a certain point is inside this shape, or if two shapes overlap, for example. Once you created a collision shape for an object, Sprite Candy will move, scale and rotate it automatically to always fit the object that it has been attached to.
Sprite Candy includes a comfortable shape editor to easily create collision shapes for your images. You can load and attach collision shapes to objects at any time.
To avoid slow downs, you should not use too many points per object.
You don't need to rebuild the exact shape of an image. In most cases, a rough shape built with a few points only is enough.
Do not perform too many collision shape checks at the same time. It's a good practice to check the x/y coordinates of two objects first and only perform a shape collision check if these objects are close to each other.
Because of coordinate conversion, shape collision checks performed on two different layers are slower as performed with objects on the same layer.
|
|
HUD_AddCollisionPoint
|
|
|
HUD_AddCollisionPoint (
Object_Handle%,
x%,
y%
)
|
This command adds a point to an object's collision shape, where 0,0 is always the upper-left corner of the object. All points of the collision shape are connected in the order they have been created. Collision shapes are invisible by default. You can display the collision shape of an object using HUD_DrawCollisionShapes( ).
x% , y%
The coordinates (within the object itself) where you want to place a shape point. All shape points of an object are connected in the order they have been created. The last point created will be automatically 'connected' with the first one.
|
|
HUD_CopyCollisionShape
|
|
|
HUD_CopyCollisionShape (
Target_Object%,
Source_Object%
)
|
Using this command you can copy the entire collision shape of an object to another one.
Target_Object%
The object handle of a target object that you want to attach this shape to. If you already created a collision shape for the target object, it will be replaced by the new one.
Source_Object%
The object handle of a source object (which must already have a collision shape attached).
|
|
HUD_LoadCollisionShape
|
|
|
HUD_LoadCollisionShape (
Object_Handle%,
filename$
)
|
This command loads a shape data file (as created with the Sprite Candy Shape Editor, for example) and attaches this shape to the specified object. After loading a collision shape to an object, you can still add points manually using HUD_AddCollisionPoint( ), for example.
Object_Handle%
The handle of an object where you want to attach the loaded collision shape to.
filename$
The file name of a collision points data file, usually created with the included Sprite Candy Shape Editor.
|
|
HUD_ClearCollisionShape
|
|
|
HUD_ClearCollisionShape (
Object_Handle%
)
|
This command clears (removes) all collision shape points of an object. Use it to free unused collision shapes (saves performance) or to clear an existing one if you want to build a new shape for this object.
Object_Handle%
The handle of an object that has a collision shape attached.
|
|
HUD_ShiftCollisionShape
|
|
|
HUD_ShiftCollisionShape (
Object_Handle%,
stepx%,
stepy%
)
|
This command moves (shifts) all points of an object's collision shape at a specified amount of pixels. Use it to adjust a shape if you notice that a created or loaded shape does not fit exactly to an object.
Object_Handle%
The handle of an object that has a collision shape attached.
stepx% , stepy%
The amount of pixels that the object's collision shape should be moved by.
|
|
HUD_DrawCollisionShapes
|
|
|
HUD_DrawCollisionShapes (
[Object_Handle%],
[R%],
[G%],
[B%],
)
|
Use this command to display the collision shape of a certain object (or all objects).
Since this function uses common 2D drawing commands, it must be placed after RenderWorld and before Flip. Otherwise you won't see it's results. Use it for test purposes only.
Object_Handle%
The handle of an object that has a collision shape attached.
R% , G% , B%
Specifies the color of the shapes to draw.
|
|
HUD_CollisionShapeHitsPoint
|
|
|
HUD_CollisionShapeHitsPoint (
Object_Handle%,
x%,
y%,
[Layer_Handle%]
)
|
Use this command to check if a certain x/y coordinate is inside an object's collision shape or not.
Returns:
TRUE, if the specified x/y coordinate is inside the object's collision shape, otherwise FALSE.
Object_Handle%
The handle of an object that has a collision shape attached.
x% , y%
The x and y coordinate of a point on screen.
Layer_Handle%
You can optionally specify a layer handle, if the x/y coordinate you want to check is placed on another layer (that has been rotated, for example). Sprite Candy will then convert this coordinate to the coordinate system of the target layer. If no layer handle is specified, Sprite Candy assumes that the given x/y coordinate is placed in the same layer as the specified object.
Use '0' if the specified coordinate is an absolute point on the screen.
|
|
HUD_CollisionShapesOverlap
|
|
|
HUD_CollisionShapesOverlap (
Object1_Handle%,
Object2_Handle%
)
|
Use this command to check if the collision shapes of two objects intersect or not.
This command detects if the lines between the collision points are intersected by the lines of another shape, so it will only detect a collision when at least two collision shape lines cross each other - it will not detect a collision when one object is placed completely inside the other one, for example.
Returns:
TRUE, if the collision shapes of the specified objects overlap each other, otherwise FALSE.
Object1_Handle% , Object2_Handle%
The handle of two objects that have collision shapes attached.
|
|
©2004,2005 Mike Dogan / X-PRESSIVE.COM
X-PRESSIVE.COM is a label and working title of Mike Dogan, est. 1999
All artwork, including graphics, text, images and sounds are property of Mike Dogan, X-PRESSIVE.COM. Trademarks belong to their respective owners. All rights reserved.
|