Introduction and table of contents - The init file - The Main object - Importing new textures - Importing 3D meshes - New data types - List of instantiable objects - List of static objects
Note: static methods are shown in grey.
Method | Description | Limitations |
Sprite new(string filepath[, Int2 topLeft, Int2 bottomRight]) | Static constructor. Create a new 2D sprite. If the 2nd and 3rd argument are specified, create a sprite from a portion of the file image. | |
Number2 scale([Number2 scale]) | Set or get the relative scale of the sprite, (1,1) being its original size. | |
number angle([number angle]) | Set or get the angle of the sprite in degrees. The rotation is made around the hot spot point. | |
Int2 hotSpotPoint([Int2 pos]) | Set or get the hot spot point of the sprite (which is the reference point while positioning or rotating the sprite), in pixel units relatively to the left-top corner of the image. By default, it is set to (0,0), which means that the setPosition() function setups the left-top corner position of the sprite. | |
void setHotSpotPointCenter() | Set the hot spot point of the sprite to the center of the sprite i.e. (width()/2,height()/2). | |
Int2 position([Int2 pos]) | Set or get the position of the sprite. | |
int positionX([int x]) | Set or get the X position of the sprite. | |
int positionY([int y]) | Set or get the Y position of the sprite. | |
void setPositionCenter() | Set the position of the sprite to the center of the window. | |
void draw([number opacity = 1]) | Draw the sprite. opacity is between 0 and 1 | |
void drawFragment(Int2 topLeftInSprite, Int2 bottomRightInSprite[, Int2 sizeOnTarget, [number opacity = 1]]) | Draw a part of the sprite. Current scale and rotation are ignored. opacity is between 0 and 1 |
|
bool isIn(Int2 pos) | Return true if pos coordinates are over the sprite. | |
Int2 size() | Get the sprite (width and height) size in pixel units (relative scale is taken into consideration). | |
int width() | Get the sprite width in pixel units (relative scale is taken into consideration). | Must be called in Main::draw2D |
int height() | Get the sprite height in pixel units (relative scale is taken into consideration). | Must be called in Main::draw2D |
void drawFullscreen() | Clear the screen with black color and draw the sprite in the center of the window | |
void drawFullscreenStretched() | Clear the screen with black color and draw the sprite in the center of the window, resizing to fit the window as much as possible. | |
void drop() | Destroy the sprite |
Method | Description | Limitations |
Button new(string filepath, string description_text[, Int2 topLeft, Int2 bottomRight]) | Static constructor. Create a new 2D button with a mousehover description text. If the 2nd and 3rd argument are specified, create a button from a portion of the file image. | |
void setBorder(Color color, number border_width) | Set up the button border. | |
Int2 position() | Get the button position. | |
Number2 scale([Number2 scale]) | Set or get the relative scale of the sprite, (1,1) being its original size. | |
void draw(Int2 pos[, number opacity = 1.0]) | Draw the button on the given pixel coordinates. | Must be called in Main::draw2D |
bool isIn(Int2 pos[, bool use_color_mouse_pressed = false]) | Return true if pos coordinates are over the button (Usually used in Main::onPointerPressed to create a mouse event).
If use_color_mouse_pressed is true, andpos coordinates are actually over the button, color it it for a while, in order to show that it has been pressed. | |
void checkIsOver(Int2 pos) | ||
Color colorMousePressed([Color c]) | Set or get the color (used if use_color_mouse_pressed is true when calling isIn()). Default is black. Alpha channel is ignored. | |
Color colorMouseOver([Color c]) | Set or get the color (used if calling checkIsOver()). Default is black. Alpha channel is ignored. | |
int fadeDurationOver([int duration]) | Set or get the duration in milliseconds of the fading effect when the mouse is over. | |
int fadeDurationPressed([int duration]) | Set or get the duration in milliseconds of the fading effect when the mouse is pressed. | |
Int2 size() | Get the button size in pixel units. | |
int width() | Get button width in pixel units | |
int height() | Get button height in pixel units | |
void drop() | Destroy the button |
Method | Description | Limitations |
CountBar new(string image_filepath, int initial_value, Int2 pos[, int horizontal_spacing[, int vertical_spacing = 0]) | Static constructor. Create a new bar for counting elements, with a given initial value, and picture loaded from image_filepath, which will be drawn at position pos in pixel coordinates. (horizontal_spacing,vertical_spacing) indicate the spacing between pictures when drawing, it can also be negative. If the spacing is not specified, the spacing is (image width, 0) i.e. each picture is drawn to make an horizontal line. | |
void draw() | Draw the bar. Each picture will be repeated each bar value times. | Must be called in Main::draw2D |
int getValue() | Get the bar value. | |
void setValue() | Set a new bar value | |
void drop() | Destroy the bar |
Method | Description | Limitations |
Model3D new(string filepath_mesh1[, string filepath_mesh2[, ...]) | Static constructor. Create a new 3D model from one or several meshes (several is if you want some animation, each mesh will correspond to a frame) | |
Number3 scale([Number3 size]) | Set or get the rescale ratio of the the model (all frames of it), 1 being its original mesh size. | |
Number3 scaleKeepProportions(number value) | Same but avoid changing proportions (equivalent to scale(Number3.new(value,value,value))). | |
Number3 position([Number pos]) | Set or get the Model3D position. | |
Number3 angle([Number angle]) | Set or get the Model3D angle. | |
void enableLighting(bool yesNo) | Enable/disable lighting for rendering of this object (default is enabled). | |
void draw() | Draw the current frame in the 3D world. | Must be called in Main::draw3D |
void setAnimationFrame(int index) | Select the current animation frame | |
void setAnimationFrameDuration(int index) | Set the duration for a frame in millisecond, before switching to the next frame | |
void setAnimationMinAndMaxIds(int index_min, int index_max) | Set the first frame and the last frame in the animation. The frames are animated in loop from index_min to index_max then back to index_min. | |
void runAnimation(bool yes_or_no) | If true, enable the animation. If false, animation is disabled (and you have then to use setAnimationFrame() if you want to change the frame to display). | |
void drop() | Destroy the model |
Method | Description | Limitations |
Sphere3D new(string filepath_texture[, int verticesDetailLevel = 10]) | Static constructor. Create a new 3D sphere with a given texture. | TODO Not sure the texture coordinates work well. |
number radius([number value]) | Set or get the sphere radius. | TODO check param is radius or diameter? |
Number3 angle([Number3 angle]) | Set or get the sphere angle. | |
Number3 position([Number3 pos]) | Set or get the sphere position. | |
void enableLighting(bool yesNo) | Enable/disable lighting for rendering of this object (default is enabled). | |
void draw() | Draw the sphere in the 3D world | Must be called in Main::draw3D |
void drop() | Destroy the sphere |
Method | Description | Limitations |
Cuboid3D new(string filepath_texture) | Static constructor. Create a new 3D cuboid with a given texture (the same texture for all faces). | TODO Allow different textures, per face. |
Number3 size(Number3 size) | Set or get the cuboid size | |
(number,number,number) angle([number angle_x, number angle_y, number angle_y]) | Set or get the cuboid angle. | |
(number,number,number) position([number x, number y, number y]) | Set or get the cuboid position. | |
void enableLighting(bool yesNo) | Enable/disable lighting for rendering of this object (default is enabled). | |
void draw() | Draw the cuboid in the 3D world | Must be called in Main::draw3D |
void drop() | Destroy the cuboid |
Method | Description | Limitations |
Sound new(string filepath_sound) | Static constructor. Create a new sound object. | TODO: check supported formats. |
void play() | Play the sound | |
int volume(int volume) | Set up the sound volume | Value must be between 0 and 255 included. |
bool isPlaying() | Return true if the sound is being played | |
void stop() | Stop the sound if it is being played | |
void drop() | Destroy the sound object |
Method | Description | Limitations |
Ocean new(string water_top_texture_file, string water_sub_texture_file[, Color color_overwater]) | Static constructor. Create an ocean object, using first texture for top layer and second texture for sub-water layers. Use the color color_overwater for color over the screen when the camera is underwater (default is transparent blue (0,104,255,128)). | |
void waterHeight(number y) | Get or set the absolute Y water coordinate. Default is: -5.0 | |
void manage() | Must be called regularly in Main::manage | |
void draw2D() | Draw the 2D part (actually paint the screen in blue if the camera is under water, else do nothing) | Must be called in Main::draw3D |
void draw3D() | Draw the infinite ocean | Must be called in Main::draw3D |
void drop() | Destroy the ocean object |
Method | Description |
BufferOfCubesAndActiveObjects newFromCopyOrCutCuboid(Int3 pos1, Int3 pos2, bool cut_instead_of_copy) | Static constructor. Create a new "buffer" object storing cubes and active objects in the cuboid coordinates pos1 to pos2. If cut_instead_of_copy is true, remove all in this cuboid before storing it in the buffer (it's like a "Ctrl+X"), else it's like a "Ctrl+C". |
BufferOfCubesAndActiveObjects newFromCopyOrCutSphere(Int3 pos, int radius, bool cut_instead_of_copy) | Same but selects only what's in a sphere of center pos. |
void paste(Int3 min[, Int3 max]) | Like a "Ctrl+V". Paste the buffer contents at the coordinates min. If max is defined, paste the buffer within these cuboid coordinates between min and max, "stretching" the contents of the buffer if necessary (which may lead to strange results). Note that one buffer may be pasted several times. |
Int3size() | Get the size in cube units of the buffer |
void drop() | Destroy the buffer object. |
Method | Description | |
EditText new(bool isUrl,int parNbMaxChars, Int2 pos,bool parIsCrypted, bool parIsDigitOnly[, string parAllowedCharacters]) | Static constructor. Create a new EditText object. | TODO: code: put Font.o in private and fix DirectX version |
void draw(int font_size) | Draw the EditText object | |
void onKeyPressed(string key) | Must be called in Main.onKeyPressed() in order to update the EditText with the key. | |
string getText() | Get the text written so far. | |
void setText(string text) | Replace the text in the EditText by something else. | |
void clearText() | Erase the text. | |
void drop() | Destroy the EditText object |
Method | Description | Limitations |
CubesEngine get() | Get the default CubesEngine instance | |
CubesEngine new([int size_one_region = 64, [ number size_one_cube = 10.0]]) | Create a new CubesEngine instance, independent from the default one | TODO: CHECK PERFS+ADD POS |
void clear() | Clear every cube in the CubesEngine instance. | |
void drop() | Clear every cube and destroy the instance. You shall not drop() the default CubesEngine get() instance, but only the ones created with new(). | TODO: CHECK PERFS+ADD POS |
void manage([Number3 pos]) | Update the CubesEngine, and possibly set a new reference position, by default (0.0,0.0,0.0). Must be called in Main.manage(). | |
Int3 fromRealPosToCubePos(Number3 pos) | ||
Number3 fromCubePosToRealPos(Int3 pos) | ||
void draw3D() | Draw the CubesEngine. Must be called in Main.draw3D(). | |
int getCubeTypeAt(int x,int y, int z) | Get the cube type at a given position, in cubes coordinates | |
int makeCube(Int3 pos, int cube_type) | Add a cube at a given position, in cubes coordinates. Set cube_type=-1 for removal. | |
void makeCuboid(Int3 min, Int3 max, int cube_type) | Add a cuboid of cubes at a given position, in cubes coordinates. Set cube_type=-1 for removal. | |
void moveCube(Int3 min, Int3 max[, int duration_in_miliseconds = 1000]) | TODO: not compatible with repeat_each_8_cube | |
void makeSphere(Int3 pos, number radius, int cube_type) | Add a sphere of cubes at a given position, in cubes coordinates (except radius which is in world units). Set cube_type=-1 for removal. | |
void makeRandomFloatingIslands(Int3 pos, int cube_type, int nb_cuboid_per_region[, int nb_regions_side = 3, [bool bigger_cubes]) | Create random floating islands of cubes. nb_cuboid_per_region defines the density of cube aggregates. If bigger_cubes is defined and true, make considerably bigger cubes. | |
void makeFullWorld(Int3 pos, int cube_type[, int nb_random_cuboid_per_region[, int nb_regions_side[, number heightmap_factor]]]) | Create full world from files "%AppData%/LovingCubeEngine/world_heightmap.png" and "%AppData%/LovingCubeEngine/world_groundmap.png" . A heightmap_factor less than 1 is advised. | |
string texturesDirectory(string path) | Set or get the directory where the textures can be found when calling addCubeType(). Default is "data/cubes_textures" | Note: the same textures directory is used for all CubesEngine instances. + TEST |
void clearCubeTypes() | Clear the list of cube types | |
int addCubeType( string texture_front, string texture_back, string texture_top, string texture_bottom, string texture_left, string texture_right, bool repeat_each_8_cube, bool is_collidable[, int cube_type_corresponding_bottom]) |
Add a new cube type, with texture basename specified for each of the 6 faces of the cube. Return the corresponding new cube type identifier.
If repeat_each_8_cube is true, the texture coordinates are configured to repeat each eight cubes instead of one; this helps avoiding ugly pattern repetitions. If is_collidable is true, the player character (see Player) cannot get through these cubes. If cube_type_corresponding_bottom is set and not -1, this other cube type will be used when creating cuboids or spheres of several cubes of height, to make a grass/earth effet (this other cube type being used for earth). |
|
int addCubeType(string texture, bool repeat_each_8_cube, bool is_collidable[, int cube_type_corresponding_bottom]) | Same but the same texture is used for all faces of the cubes. | |
int getNbCubeTypes() | Return the number of loaded cube types | |
(string,string,string,string,string,string,bool) getCubeTypeInfos() | Return informations about a loaded cube type: its 6 textures and whether it is collidable or not | |
bool isPositionColliding(Number3 pos[, bool even_if_not_collidable = false]) | Input must be in world coordinates. Return true if the position is within a cube and this cube is collidable. If even_if_not_collidable is true, return true even if the cube is not collidable. | |
number getSizeOneCube() | Get the size of a cube in real world coordinates. | |
(bool,int) detailedMode([bool enable_detailed_mode, int subdivisions_per_cube]) |
Set or get details configuration. The detailed mode (default) replaces the "raw" cube rendering by a rendering with "slopes". The detailed mode can be quite more beautiful, but it takes a little bit more computer ressources.
(Note: This only concerns cubes which are quite near to the camera, the cubes being really far from the camera are always rendered "undetailed") subdivisions_per_cube indicates the number of subdivisions within a cube when detailed mode is active. It is advised to set 2 or 4 or 8 (the bigger the number, the more computer ressources it takes). |
|
Number3 get3DPosFrom2D(Int2 pos2d) | Same than Scene3D.get3DPosFrom2D(pos2d) but do only picking on the cubes, not the rest. | WORKS ONLY ON DIRECTX PLATFORMS |
Method | Description | Limitations |
ActiveObjects get() | Get the ActiveObjects instance | |
void manage() | Update the active objects. Must be called in Main.manage(). | |
void draw3D([bool for_editor]) | Draw the active objects. Must be called in Main.draw3D(). If for_editor is defined and true, displays boxes instead of the objects. | |
void addType(string lua_class_name, string filepath_insight_picture) | Add a new type of active object, which will be available in the 3D editor with the picture filepath_insight_picture.
This requires having a lua table named lua_class_name and implementing its methods load(), manage(pos), draw3D(pos) and unload(). | |
int getNbTypes() | ||
string getTypeClassName(int typeId) | ||
void clearTypes() | Remove all active objects types. | TODO: check what happens to orphan active object instances. |
void resetActiveObjects() | For all active object instances, call their "unload" method, undefine their variables (see This.setVariable below), and then call their "load" method. | |
void add(string lua_class_name, Number3 pos) | Create a new instance of active object lua_class_name at position pos. | |
void removeSphere(Number3 pos, number radius) | Remove any active object instance within a radius of the world-coordinates position pos. |