Module blitwizard

Blitwizard namespace containing the generic blitwizard game entity object and various sub namespaces for physics, graphics and more.

Please note 3d graphics are currently not supported.

Info:

  • Copyright: 2011-2013
  • License: zlib
  • Author: Jonas Thiem (jonas.thiem@gmail.com) et al

Functions

getAllObjects () Iterate through all existing objects, no matter if 2d or 3d.
setTimeout (function, delay) This function allows scheduling a function to be executed later.
loadResourceArchive (Path) Load a .zip file as a resource archive.
setStep (step_time) Set the stepping frequency of the game logic.
onClose () Specify this function if you want to get notified when your blitwizard game gets closed (close button, ALT+F4, ...).
onMouseMove (x_pos, y_pos) Specify this function if you want to get notified when the mouse is moved over the graphics output.
onMouseDown (x_pos, y_pos, button) Specify this function if you want to get notified when a mouse button is pressed down on the graphics output.
onMouseUp (x_pos, y_pos, button) Specify this function if you want to get notified when a mouse button (which was previously pressed down) is released on the graphics output.
onLog (msgtype, msg) Specify this function if you want to receive internal blitwizard log messages.

Class object

object:setInvisibleToMouse (invisible) Set an object to be invisible for mouse handling.
object:new (type, resource) Create a new blitwizard object which is represented as a 2d or 3d object in the game world.
object:destroy () Destroy the given object explicitely, to make it instantly disappear from the game world.
object:getPosition () Get the current position of the object.
object:setPosition (pos_x, pos_y, pos_z) Set the object to a new position.
object:setTransparency (transparency) Set the transparency of the visual representation of this object.
object:getTransparency () Get the transparency of the visual representation of this object.
object:getDimensions () Get the dimensions of an object in game units (with scaling taken into account).
object:getScale () Get the object's scale, which per default is 1,1 for 2d objects and 1,1,1 for 3d objects.
object:setScale (x_scale, y_scale, z_scale) Change an object's scale, also see blitwizard.object:getScale.
object:scaleToDimensions (width, height, z_size) Scale up an object to precise boundaries in game units.
object:setZIndex (z_index) Set the z-index of the object (only for 2d objects).
object:setRotationAngle (rotation) Set the rotation angle of a 2d object.
object:getRotationAngle () Get the rotation angle of a 2d object.
object:set2dTextureClipping (x, y, width, height) For 2d sprite objects, set a clipping window inside the original texture used for the sprite which allows you to specify a sub-rectangle of the texture to be used as image source.
object:pinToCamera (camera) Pin a sprite to a given game camera.
object:setVisible (visible) Change whether an object is shown at all, or whether it is hidden.
object:onGeometryLoaded () Set this event function to a custom function of yours to get notified when the geometry (size/dimension and animation data etc) of your object has been fully loaded.
object:doOften () Set this event function to a custom function of yours to have the object do something over and over again moderately fast (4 times a second).
object:doAlways () Set this event function to a custom function of yours to have the object do something over and over again (very rapidly).
object:onMouseClick () Set this event function to get notified when a mouse click is done on your object.
object:onMouseEnter () Set this event function to get notified when the mouse is moved onto your object.
object:onMouseLeave () Set this event function to get notified when the mouse was moved onto your object and has now moved away again.
object:disableCollision () Disable the physics simulation on an object.
object.shape_info This is how you should submit shape info to object:enableStaticCollision and object:enableMovableCollision (THIS TABLE DOESN'T EXIST, it is just a guide on how to construct it yourself)

All shape sizes, dimensions etc are specified in game units.

object:enableMovableCollision (shape_info) Enable the physics simulation on the given object and make it movable and collide with other movable and static objects.
object:enableStaticCollision (shape_info) Enable the physics simulation on the given object and allow other objects to collide with it.
object:impulse (force_x, force_y, force_z, source_x, source_y, source_z) Apply a physics impulse onto an object (which will make it move, for example as if someone had pushed it).
object:restrictRotation (total_or_axis_x, axis_y, axis_z, axis_point_x, axis_point_y, axis_point_z) Restrict the ability to rotate for a given object.
object:setAngularDamping (damping) Set the angular damping factor.
object:setFriction (friction) Set the surface friction on the given object.
object:setGravity (gravity_x, gravity_y, gravity_z) Set a gravity vector onto an object with movable collision enabled (see object:enableMovableCollision).
object:setLinearDamping (damping) Set the linear damping factor.
object:setMass (mass, mass_center_x, mass_center_y, mass_center_z) Set the mass and the center of an object.


Functions

getAllObjects ()
Iterate through all existing objects, no matter if 2d or 3d.

Returns:

    function returns an iterator function

Usage:

     for obj in blitwizard.getAllObjects() do
         local x, y = obj:getPosition()
         print("object at: " .. x .. ", " .. y)
     end
setTimeout (function, delay)
This function allows scheduling a function to be executed later. blitwizard.setTimeout will return instantly, and lateron when the specified amount of time has passed, the function will be run once.

If you know JavaScript, this function should be familiar to you.

The return value is a handle which you can use to cancel the scheduled function run with ???, as long as it hasn't been run yet.

Parameters:

  • function function the function which shall be executed later
  • delay number the delay in milliseconds before executing the function
loadResourceArchive (Path)
Load a .zip file as a resource archive.

All files inside the zip file will be mapped into the local folder as resource files, so that you can load them as sounds, graphics etc.

E.g. if the archive contains a folder "blubb", and inside "sound.ogg", you can just load "blubb/sound.ogg" as a sound after loading the archive with this function.

Parameters:

  • Path string to the .zip archive to be loaded
setStep (step_time)
Set the stepping frequency of the game logic. The default is 16ms. Physics are unaffected.

Please note changing this is a very invasive change - don't do this if you don't know what you're doing.

Also, do NOT use this to speed up/slow down your game while it runs. While it may work, it will lead to low frames per second and you should simply use a speed factor in all your logic functions instead.

Generally, bigger stepping times to 16ms can cause all sorts of problems (low frames per second, physics callbacks triggering oddly late, ...), so this function is only useful for some rare cases.

Parameters:

  • step_time number the amount of time between steps in milliseconds. 16 is minimum (and default). HIGH STEPPING TIME MAY CAUSE SLOPPY FRAMERATE AND OTHER PROBLEMS
onClose ()
Specify this function if you want to get notified when your blitwizard game gets closed (close button, ALT+F4, ...).

This function does not exist unless you specify/override it with blitwizard.onClose = ...

This event is useful if you want to save the game or do other things on shutdown.

Usage:

     -- specify our own close event function:
     function blitwizard.onClose()
         print("Shutting down!")
     end
onMouseMove (x_pos, y_pos)
Specify this function if you want to get notified when the mouse is moved over the graphics output.

This function does not exist unless you specify/override it.

Parameters:

  • x_pos number mouse X position
  • y_pos number mouse Y position

Usage:

     -- Listen for mouse evens:
     function blitwizard.onMouseMove(x, y)
         print("Mouse position: x: " .. x .. ", y: " .. y)
     end
onMouseDown (x_pos, y_pos, button)
Specify this function if you want to get notified when a mouse button is pressed down on the graphics output.

This function does not exist unless you specify/override it.

Parameters:

  • x_pos number mouse X position
  • y_pos number mouse Y position
  • button number mouse button (1 for left, 2 for right)

Usage:

     -- Listen for mouse evens:
     function blitwizard.onMouseDown(x, y, button)
         print("Mouse down: button: " .. button .. ", x: " .. x .. ", y: " .. y)
     end
onMouseUp (x_pos, y_pos, button)
Specify this function if you want to get notified when a mouse button (which was previously pressed down) is released on the graphics output.

This function does not exist unless you specify/override it.

Parameters:

  • x_pos number mouse X position
  • y_pos number mouse Y position
  • button number mouse button (1 for left, 2 for right)

Usage:

     -- Listen for mouse evens:
     function blitwizard.onMouseUp(x, y, button)
         print("Mouse up: button: " .. button .. ", x: " .. x .. ", y: " .. y)
     end
onLog (msgtype, msg)
Specify this function if you want to receive internal blitwizard log messages.

This function is defined with a default function that simply prints() all log messages, which sends them to the developer console.

Feel free to redefine it to do something more useful.

Parameters:

  • msgtype string the type of log message. Currently supported types: "info", "warning", "error"
  • msg string the actual log message

Usage:

     -- only show warnings and errors:
     function blitwizard.onLog(msgtype, msg)
         if type == "info" then
             return
         end
         print("[LOG:" .. msgtype .. "] " .. msg)
     end

Class object

Blitwizard object which represents an 'entity' in the game world with visual representation, behaviour code and collision shape.
object:setInvisibleToMouse (invisible)
Set an object to be invisible for mouse handling. Other objects below this particular object may therefore receive the according object:onMouseEnter, object:onMouseLeave and object:onMouseClick events instead.

This is useful e.g. for text that isn't supposed to "steal" the events from the button it is on, or a fade-in sprite that covers the whole camera which shouldn't block the mouse events.

Parameters:

  • invisible boolean Set to true to make it invisible to mouse events, or false to make it receive or block mouse events (default: false)
object:new (type, resource)
Create a new blitwizard object which is represented as a 2d or 3d object in the game world. 2d objects are on a separate 2d plane, and 3d objects are inside the 3d world. Objects can have behaviour and collision info attached and move around. They are what eventually makes the action in your game!

Parameters:

  • type number specify object type: blitwizard.object.o2d or blitwizard.object.o3d
  • resource string (optional) if you specify the file path to a resource here (optional), this resource will be loaded and used as a visual representation for the object. The resource must be a supported graphical object, e.g. an image (.png) or a 3d model (.mesh). You can also specify nil here if you don't want any resource to be used.

Returns:

    userdata Returns a blitwizard object

Usage:

     -- Create a new 2d sprite object from the image file myimage.png
     local obj = blitwizard.object:new(blitwizard.object.o2d, "myimage.png")
object:destroy ()
Destroy the given object explicitely, to make it instantly disappear from the game world.

If you still have references to this object, they will no longer work.

object:getPosition ()
Get the current position of the object. Returns two coordinates for a 2d object, and three coordinates for a 3d object.

Returns:

  1. number x coordinate
  2. number y coordinate
  3. number (if 3d object) z coordinate
object:setPosition (pos_x, pos_y, pos_z)
Set the object to a new position. Specify two coordinates for 2d objects (x, y) and three for 3d objects (x, y, z).

Please note this game position is in game units, not pixels.

To find out how much pixels 1 game unit is in the 2d world with a default zoom of 1, check blitwizard.graphics.camera:gameUnitToPixels.

For the 3d world, one game unit should roughly equal one meter if your game plays in a normal human-scale environment (this works best for the physics).

Parameters:

  • pos_x number x coordinate
  • pos_y number y coordinate
  • pos_z number (only for 3d objects) z coordinate
object:setTransparency (transparency)
Set the transparency of the visual representation of this object. Defaults to 0 (solid).

Parameters:

  • transparency number transparency from 0 (solid) to 1 (invisible)
object:getTransparency ()
Get the transparency of the visual representation of this object.

Returns:

    number transparency from 0 (solid) to 1 (invisible)
object:getDimensions ()
Get the dimensions of an object in game units (with scaling taken into account).

For a 2d sprite, this returns two components (x, y) which match the sprite's width and height, for a 3d object, this returns a 3d box which would encapsulate the 3d mesh in its first initial animation frame.

If you call this function before getting the geometry callback, an error will be thrown that the information is not available yet.

Note with use of blitwizard.object:set2dTextureClipping the dimensions change and they might no longer reflect the initial size of the texture.

Returns:

  1. number x_size X dimension value
  2. number y_size Y dimension value
  3. number z_size (only for 3d objects) Z dimension value
object:getScale ()
Get the object's scale, which per default is 1,1 for 2d objects and 1,1,1 for 3d objects. The scale is a factor applied to the dimensions of an object to stretch or shrink it.

Please note if you want to scale up a unit to precisely match a specific size in game units (instead of just making it twice the size, three times the size etc with setScale), you might want to use object:scaleToDimensions.

Returns 2 values for 2d objects, 3 values for 3d objects.

Returns:

  1. number x_scale X scale factor
  2. number y_scale Y scale factor
  3. number z_scale (optional) Z scale factor
object:setScale (x_scale, y_scale, z_scale)
Change an object's scale, also see blitwizard.object:getScale. This allows to stretch/shrink an object. If physics are enabled with object:enableMovableCollision or object:enableStaticCollision, the physics hull will be scaled accordingly aswell.

Please note if you want to scale up a unit to precisely match a specific size in game units (instead of just making it twice the size, three times the size etc with setScale), you might want to use object:scaleToDimensions.

Specify x, y scaling for 2d objects and x, y, z scaling for 3d objects.

Parameters:

  • x_scale number X scale factor
  • y_scale number Y scale factor
  • z_scale number (optional) Z scale factor

Usage:

     -- scale a 2d object to twice the original size
     obj3d:setScale(2, 2)
    
     -- scale 3d object to half its original size
     obj3d:setScale(0.5, 0.5, 0.5)
object:scaleToDimensions (width, height, z_size)
Scale up an object to precise boundaries in game units. An according scale factor will be picked to achieve this.

For 2d objects, a width and a height can be specified. For 3d objects, the size along all three axis (x, y, z) can be specified.

If you want the object to be scaled up but maintain its aspect ratio, specify just one parameter and pass nil for the others which will then be calculated accordingly.

Parameters:

  • width number width or x size in game units
  • height number height or y size
  • z_size number (only present for 3d objects) z size

Usage:

     -- Scale up a 3d object so its height matches 2 game units:
     -- (it's proportions will be kept)
     obj3d:scaleToDimensions(nil, nil, 2)
object:setZIndex (z_index)
Set the z-index of the object (only for 2d objects). An object with a higher z index will be drawn above others with a lower z index. If two objects have the same z index, the newer object will be drawn on top.

The z index will be internally set to an integer, so use numbers like -25, 0, 1, 2, 3, 99, ...

The default z index is 0.

Parameters:

  • z_index number New z index
object:setRotationAngle (rotation)
Set the rotation angle of a 2d object. (You need to use ???, ??? or ??? for 3d objects)

An angle of 0 is the default rotation, 90 will turn it on its side counter-clockwise by 90° degree, etc.

Parameters:

  • rotation number the rotation angle
object:getRotationAngle ()
Get the rotation angle of a 2d object. (Use ??? or ??? for 3d objects)

Also see object:setRotationAngle.

Returns:

    number the current 2d rotation of the object
object:set2dTextureClipping (x, y, width, height)
For 2d sprite objects, set a clipping window inside the original texture used for the sprite which allows you to specify a sub-rectangle of the texture to be used as image source.

This means you can make your sprite show just a part of the texture, not all of it.

The clipping window defaults to full texture size. Changing it will also affect the size reported by object:getDimensions.

You can omit all parameters which will reset the clipping window to the full texture dimensions.

Parameters:

  • x number the x offset in the texture, in pixels (default: 0)
  • y number the y offset in the texture, in pixels (default: 0)
  • width number the clipping window width in the texture in pixels (defaults to full texture width)
  • height number the clipping window height in the texture in pixels 8defaults to full texture height)
object:pinToCamera (camera)
Pin a sprite to a given game camera. It will only be visible on that given camera, it will ignore the camera's 2d position and zoom and will simply display with default zoom with 0,0 being the upper left corner.

It will also be above all unpinned sprites.

You might want to use this for on-top interface graphics that shouldn't move with the level but stick to the screen.

Parameters:

  • camera userdata the camera to pin to, or nil to unpin
object:setVisible (visible)
Change whether an object is shown at all, or whether it is hidden. If you know objects aren't going to be needed at some point or if you want to hide them until something specific happens, use this function to hide them temporarily.

Parameters:

  • visible boolean specify true if you want the object to be shown (default), or false if you want it to be hidden. Please note this has no effect on collision
object:onGeometryLoaded ()
Set this event function to a custom function of yours to get notified when the geometry (size/dimension and animation data etc) of your object has been fully loaded.

This function does not exist before you set it on a particular object.

See usage on how to define this function for an object of your choice.

Usage:

       -- create a 2d sprite and output its size:
       local obj = obj:new(blitwizard.object.o2d, "my_image.png")
       function obj:onGeometryLoaded()
         -- call self:getDimensions to get
         -- its dimensions
         print("My dimensions are: " .. self:getDimensions()[1],
         self:getDimensions()[2])
       end
object:doOften ()
Set this event function to a custom function of yours to have the object do something over and over again moderately fast (4 times a second).

You might want to use this function for things where a small reaction time is acceptable but which need to happen constantly, e.g. an enemy checking if it can see the player (to start an attack).

This function does not exist before you set it on a particular object.

This function is called with all objects with a frequency of 4 times a second.

object:doAlways ()
Set this event function to a custom function of yours to have the object do something over and over again (very rapidly).

This function is mainly useful for fluid movements, e.g. for an elevator, you might want to move the elevator one bit each time this function is called.

This function does not exist before you set it on a particular object.

This function is called with all objects with a frequency of 60 times a second (it can be changed globally with blitwizard.setStep if you know what you're doing).

For decisions and changes that don't need to be done so fast, use object:doOften which runs 4 times a second (which is still very often).

Usage:

     -- have a sprite move up the screen
     local obj = obj:new(blitwizard.object.o2d, "my_image.png")
     function obj:doAlways()
       -- get old position:
       local pos_x, pos_y = self:getPosition()
       -- move position up a bit:
       pos_y = pos_y - 0.01
       -- set position again:
       self:setPosition(pos_x, pos_y)
     end
object:onMouseClick ()
Set this event function to get notified when a mouse click is done on your object.

A double-click will be reported as two onMouseClick events in short succession.

Any object above this object (higher z-index) can cover this one and steal its mouse events, even if it doesn't have any handlers for mouse events itself. To prevent that, set such covering objects to ignore mouse events (object:setInvisibleToMouse).

object:onMouseEnter ()
Set this event function to get notified when the mouse is moved onto your object. (this will also be triggered if the object itself moves in a way so it ends up under the mouse cursor)

Please note with lots of objects, enabling this on objects with a low Z index (with many others above them) can have an impact on performance.

object:onMouseLeave ()
Set this event function to get notified when the mouse was moved onto your object and has now moved away again. (this will also be triggered if the object itself moves away from the mouse position)

Please note with lots of objects, enabling this on objects with a low Z index (with many others above them) can have an impact on performance.

object:disableCollision ()
Disable the physics simulation on an object. It will no longer collide with anything.
object.shape_info
This is how you should submit shape info to object:enableStaticCollision and object:enableMovableCollision (THIS TABLE DOESN'T EXIST, it is just a guide on how to construct it yourself)

All shape sizes, dimensions etc are specified in game units.

Note on object scaling:

When you enable collision, the collision shape will be exactly as large as specified on creation, no matter how large the current scaling is (that is, you can directly set any sizes from object:getDimensions if you want).

As soon as your object is scaled after collision was enabled, the physics collision shape will be scaled accordingly. (e.g. if your object scale goes from 2 to 4, the physics hull will double in size aswell)

Special notes on various shapes:

Please note the shapes "edge list" and "triangle mesh" may only be used for static collision. They don't work with movable collision objects.

Combining shapes:

You can combine shapes when enabling collision, by specifying multiple shapes (the final collision shape will be all those shapes merged into one).

Fields:

  • type string The shape type, for 2d shapes: "rectangle", "circle", "oval", "polygon" (needs to be convex!), "edge list" (simply a list of lines that don't need to be necessarily connected as it is for the polygon), for 3d shapes: "decal" (= 3d rectangle), "box", "ball", "elliptic ball" (deformed ball with possibly non-uniform radius, e.g. rather a capsule), "triangle mesh" (a list of 3d triangles)
  • width number required for "rectangle", "oval" and "decal"
  • height number required for "rectangle", "oval" and "decal"
  • diameter number required for "circle" and "ball"
  • x_size number required for "box" and "elliptic ball"
  • y_size number required for "box" and "elliptic ball"
  • z_size number required for "box" and "elliptic ball"
  • points table required for "polygon": a list of two pair coordinates which specify the corner points of the polygon, e.g. { { 0, 0 }, { 1, 0 }, { 0, 1 } } (keep in mind the polygon needs to be convex!)
  • edges table required for "edge list": a list of edges, whereas an edge is itself a 2-item list of two 2d points, each 2d point being a list of two coordinates. Both convex and concave shapes are supported. Example: { { { 0, 0 }, { 1, 0 } }, { { 0, 1 }, { 1, 1 } } }
  • triangles table required for "triangle mesh": a list of triangles, whereas a triangle is itself a 3-item list of three 3d points, each 3d point being a list of three coordinates.
  • x_offset number (optional) x coordinate offset for any 2d or 3d shape, defaults to 0
  • y_offset number (optional) y coordinate offset for any 2d or 3d shape, defaults to 0
  • z_offset number (optional) z coordinate offset for any 3d shape, defaults to 0
  • rotation number (optional) rotation of any 2d shape 0..360 degree (defaults to 0)
  • rotation_pan number (optional) rotation of any 3d shape 0..360 degree left and right (horizontally)
  • rotation_tilt number (optional) rotation of any 3d shape 0..360 degree up and down, applied after horizontal rotation
  • rotation_roll number (optional) rotation of any 3d shape 0..360 degree around itself while remaining faced forward (basically overturning/leaning on the side), applied after the horizontal and vertical rotations

Usage:

     -- Create a new 2d object from an image:
     local myobject = blitwizard.object:new(blitwizard.object.o2d, "someimage.png")
    
     -- Enable collision for our object as soon as its size is known:
     function myobject:onGeometryLoaded()
         -- set collision size exactly to the dimensions of the image:
         local w,h = myobject:getDimensions()
         myobject:enableMovableCollision({type='rectangle', width=w, height=h})
     end
object:enableMovableCollision (shape_info)
Enable the physics simulation on the given object and make it movable and collide with other movable and static objects. You will be required to provide shape information that specifies the desired collision shape of the object (not necessarily similar to its visual appearance).

Note: some complex shape types are unavailable for movable objects, and some shapes (very thin/long, very complex or very tiny or huge) can be unstable for movables. Create all your movable objects roughly of sizes between 0.1 and 10 to avoid instability.

Parameters:

  • shape_info table a shape_info table with info for a given physics shape. Note: you can add more shape info tables as additional parameters following this one - the final collision shape will consist of all overlapping shapes
object:enableStaticCollision (shape_info)
Enable the physics simulation on the given object and allow other objects to collide with it. The object itself will remain static - this is useful for immobile level geometry. You will be required to provide shape information that specifies the desired collision shape of the object (not necessarily similar to its visual appearance).

Parameters:

  • shape_info table a shape_info table with info for a given physics shape. Note: you can add more shape info tables as additional parameters following this one - the final collision shape will consist of all overlapping shapes
object:impulse (force_x, force_y, force_z, source_x, source_y, source_z)
Apply a physics impulse onto an object (which will make it move, for example as if someone had pushed it). This will only work if the object has movable collision enabled through object:enableMovableCollision. IMPORTANT: Some parameters are not present for 2d objects, see list below.

Parameters:

  • force_x number the x coordinate of the force vector applied through the impulse
  • force_y number the y coordinate of the force vector
  • force_z number (parameter only present for 3d objects) the z coordinate of the force vector
  • source_x number (optional, defaults to object's x position) the x source coordinate from where the push will be given
  • source_y number (optional, defaults to object's y position) the y source coordinate
  • source_z number (optional, defaults to object's z position) (parameter only present for 3d objects) the z source coordinate

Usage:

     -- apply an upward impulse to a 2d object with collsion enabled:
     obj:impulse(0, -1)
object:restrictRotation (total_or_axis_x, axis_y, axis_z, axis_point_x, axis_point_y, axis_point_z)
Restrict the ability to rotate for a given object. For 2d, the rotation can be totally restricted or not, for 3d it can be restricted around a specific axis (e.g. like a door), completely (object can not rotate at all), or not at all.

For 2d and complete 3d restriction, specify 'true'. For no restriction, 'false'.

For 3d restriction around a specific axis (only available for 3d objects obviously), specify 3 coordinates for an axis direction vector, then optionally an additional 3 coordinates for the point where the axis should go through (if not specified the object's center).

Parameters:

  • total_or_axis_x number/boolean Specify true or false for either full restriction or none, or the first coordinate of an axis
  • axis_y number If the first parameter was the first coordinate of an axis, specify the second here
  • axis_z number If the first parameter was the first coordinate of an axis, specify the third here
  • axis_point_x number (optional) If you want to specify a point the axis goes through, specify its x coordinate here
  • axis_point_y number (optional) y coordinate
  • axis_point_z number (optional) z coordinate
object:setAngularDamping (damping)
Set the angular damping factor. Angular damping is a 'slow down' which is constantly applied to rotation speed, so rotating objects with high angular damping will stop rotating after a while, even if not colliding with other objects. Angular damping is meaningless for objects without movable collision enabled.

Parameters:

  • damping number Angular damping factor from 0 (none) to 1 (full)
object:setFriction (friction)
Set the surface friction on the given object. Only useful on objects with collision enabled.

Parameters:

  • friction number Friction value from 0 to 1 (0 is no friction, 1 is full friction)
object:setGravity (gravity_x, gravity_y, gravity_z)
Set a gravity vector onto an object with movable collision enabled (see object:enableMovableCollision). If no parameters are provided, the object gravity will be removed again. Please note you would normally want to use blitwizard.physics.set2dGravity or blitwizard.physics.set3dGravity instead.

Parameters:

  • gravity_x number x coordinate of gravity vector
  • gravity_y number y coordinate of gravity vector
  • gravity_z number (only for 3d objects) z coordinate of gravity vector
object:setLinearDamping (damping)
Set the linear damping factor. Linear damping is a 'slow down' which is constantly applied to the movement speed so moving objects with high linear damping will eventually stop moving even if never colliding with any other objects (assuming there is no notable gravity). Linear damping is meaningless for objects without movable collision enabled.

Parameters:

  • damping number Linear damping factor from 0 (none) to 1 (full). Default: 0
object:setMass (mass, mass_center_x, mass_center_y, mass_center_z)
Set the mass and the center of an object. Only applicable for objects with movable collision enabled. (objects with static collision have infinite mass since they're not movable)

Parameters:

  • mass number Set the mass of the object in kilograms. You should experiment and pick mass here which works well for you (it shouldn't be very small or very large), rather than using the most truthful numbers.
  • mass_center_x number (optional) Set the x coordinate of the mass center (default: 0)
  • mass_center_y number (optional) Set the y coordinate of the mass center (default: 0)
  • mass_center_z number (optional) Set the z coordinate of the mass center (default: 0)
generated by LDoc 1.3.11