OSRS Plugin API
    Preparing search index...

    Class Shape

    This section is for 2D images and text shapes that can appear on the screen. These methods and properties will allow you to draw customized shapes and text onto the old school runescape client window for people using your plugin to see.

    Lets say you wanted to put a red circle on the screen. You can create a new shape using the shape constructor. You specify that it is a circle by naming its type, a PrimitiveType, and set the colour to red. Once this is done, you can use the Graphics namespace to add your newly made shape to the screen.

    Now lets say you added your red circle to the screen, but you now want to add a blue rectangle that would be under it. This is something that you can easily do using the sortAbove function. To make the rectangle, follow the steps we did above to make our circle, and then use the sortAbove method with both shapes.

    There are multiple properties that you can play around with and use to customize a shape in any way, such as changing its width, height, and position. If you are creating a text shape for the screen you can even change the font it uses.

    Using the shape class with all its properties and functions will let you create expressive 2D art that will show up right on the OSRS game screen.

    Index

    Constructors

    Properties

    colour: osrs.Colour

    The fill colour of the Shape. Used for all shapes.

    -- Create a new shape
    local Shape = osrs.Shape.new(osrs.Shape.PrimitiveType.RECTANGLE)
    -- Change the colour and position of the shape
    Shape.position = osrs.Vector2.new(600,600)
    Shape.colour = osrs.Colour.new(255,0,0,255)
    -- Create another new shape
    local Shape2 = osrs.Shape.new(osrs.Shape.PrimitiveType.CIRCLE)
    -- Change the colour and position of the shape
    Shape2.position:set(400, 400)
    Shape2.colour:set(0,255,0,255)
    dimensions: Vector2

    Used for Rectangles, Sprites, and Text. Represents the dimensions in screen space of the primitive. For TEXT, represents the box in which the text is drawn (text size can be controlled by selecting the font).

    -- Create a new shape
    local Shape = osrs.Shape.new(osrs.Shape.PrimitiveType.RECTANGLE)
    -- Change the dimensions and position of the shape
    Shape.position = osrs.Vector2.new(600,600)
    Shape.dimensions = osrs.Vector2.new(50,50)
    -- Create another new shape
    local Shape2 = osrs.Shape.new(osrs.Shape.PrimitiveType.CIRCLE)
    -- Change the dimensions and position of the shape
    Shape2.position:set(400, 400)
    Shape2.dimensions:set(100, 20)
    endpoint: Vector2

    Endpoint in screen coordinates, for line shape.

    -- Create a new shape
    local Shape = osrs.Shape.new(osrs.Shape.PrimitiveType.RECTANGLE)
    -- Change the endpoint of the shape
    Shape.endpoint:set(250, 250)
    -- Create another shape of a diffrent color
    local Shape2 = osrs.Shape.new(osrs.Shape.PrimitiveType.CIRCLE)
    Shape2.colour:set(0,255,0,255)
    -- Change the endpoint of the shape
    Shape2.endpoint:set(100, 100)
    font: Font

    For text shapes, specifies the font to use.

    -- Create a new text shape with a set position
    local Shape = osrs.Shape.new(osrs.Shape.PrimitiveType.TEXT)
    Shape.position:set(500, 500)
    -- Add text to the shape
    Shape.text = "Test"
    -- Change the font of the text
    Shape.font = osrs.Shape.Font.BOLD12
    halign: TextHAlign

    Horizontal alignment for text shapes.

    halign = Shape.TextHAlign.RIGHT
    -----------------------------------------
    | |
    | Text that is right-positioned|
    | |
    | |
    ------------------------------------------
    id: number

    The Shape's ID in the draw list. This also controls the shape's draw order. You can manipulate this value with the "sort" family of functions. Ids are assigned out with a stride of 1024, leaving space to sort Shapes between other shapes.

    -- Create two new shapes with a set position
    local Shape = osrs.Shape.new(osrs.Shape.PrimitiveType.RECTANGLE)
    Shape.position:set(500, 500)
    local Shape2 = osrs.Shape.new(osrs.Shape.PrimitiveType.CIRCLE)
    Shape.position:set(600, 500)
    -- Check the shapes ID's
    osrs.print("Rectangle Shape ID: " .. tostring(Shape.id) .. "\nCircle Shape ID: " .. tostring(Shape2.id))
    origin: Vector2

    Alias for "Position" when using a CIRCLE shape.

    -- Create a new circle shape
    local Shape = osrs.Shape.new(osrs.Shape.PrimitiveType.CIRCLE)
    -- Change the origin of the shape
    Shape.origin:set(300,300)
    position: Vector2

    The position of the Shape. For Circles, this is the center-point. For lines, it represents the start-point. For all other shapes it is the upper-left corner in screen space.

    -- Create a new shape
    local Shape = osrs.Shape.new(osrs.Shape.PrimitiveType.RECTANGLE)
    -- Change the position of the shape
    Shape.position = osrs.Vector2.new(100,100)
    -- Create another new shape
    local Shape2 = osrs.Shape.new(osrs.Shape.PrimitiveType.CIRCLE)
    -- Change the position of the shape
    Shape2.position:set(300, 300)
    radius: number

    Radius in pixels for CIRCLE shapes.

    -- Create a new circle shape
    local Shape = osrs.Shape.new(osrs.Shape.PrimitiveType.CIRCLE)
    -- Change the radius and position of the circle
    Shape.radius = 200
    Shape.position:set(200, 200)
    shading: ShadingType

    See ShadingType primitive for more information. Not all shadings are supported by all Shapes. For instance only CIRCLE and RECTANGLE support the "Empty" shading.

    -- Create two new shapes with diffrent positions
    local Shape1 = osrs.Shape.new(osrs.Shape.PrimitiveType.RECTANGLE)
    Shape1.position:set(100, 100)
    local Shape2 = osrs.Shape.new(osrs.Shape.PrimitiveType.CIRCLE)
    Shape2.position:set(200, 200)
    -- Change one of the shapes shading types
    Shape1.shading = osrs.Shape.ShadingType.EMPTY

    Indicates which Shape this object represents. Changing a Shape type dynamically is possible, but you should fill in any missing parameters for the new shape in the same call-stack. For example, if changing to CIRCLE, be sure to set the "radius" property.

    -- Create a new shape
    local Shape = osrs.Shape.new(osrs.Shape.PrimitiveType.RECTANGLE)
    -- Change the shape of the new shape (change it from rectangle to circle)
    Shape.shape = osrs.Shape.PrimitiveType.CIRCLE
    spriteId: number

    For SPRITE shapes, this sets or gets the sprite that will be rendered. Sprite Ids must be retrieved by other API calls. However, the range begins at 0, which allows a simple demonstration:

    local shape = osrs.Shape.new(osrs.Shape.PrimitiveType.SPRITE)
    shape.position=osrs.Vector2.new(725, 300)
    shape.spriteId = 0 -- renders first sprite in range.
    strokewidth: number

    Stroke width, in pixels, for a circle shape.

    -- Create a new circle shape
    local Shape = osrs.Shape.new(osrs.Shape.PrimitiveType.CIRCLE)
    -- Change the shading of the circle to empty and update the position
    Shape.shading = osrs.Shape.ShadingType.EMPTY
    Shape.position:set(300, 300)
    -- Change the radius of the circle
    Shape.radius = 200
    -- Change the stroke width of the circle
    -- Should be less than the radius
    Shape.strokewidth = 100
    text: string

    For text shapes, specifies the text that will render. Text is word-wrapped within its bounding box, and positioned according to halign and valign params.

    -- Create a new text shape with a set position
    local Shape = osrs.Shape.new(osrs.Shape.PrimitiveType.TEXT)
    Shape.position:set(500, 500)
    -- Add text to the shape
    Shape.text = "Test"
    valign: TextVAlign

    Vertical alignment for text shapes.

    valign = Shape.TextHAlign.BOTTOM
    -----------------------------------------
    | |
    | |
    | |
    |Text that is bottom-positioned |
    ------------------------------------------
    vspacing: number

    For text shapes, this is the vertical spacing in pixels between individual lines of text.

    -- Create a new text shape with a set position
    local Shape = osrs.Shape.new(osrs.Shape.PrimitiveType.TEXT)
    Shape.position:set(500, 500)
    -- Add text to the shape
    Shape.text = "Test"
    -- Change the vspacing of the shape
    Shape.vspacing = 100

    Methods

    • Clones this Shape, returning a copy.

      Returns osrs.Shape

      new Shape. By default this will sort directly above the original shape.

      -- copies a rect into a new rect, shifts it, and changes its color.
      local original = osrs.Shape.new(osrs.Shape.PrimitiveType.RECTANGLE)
      original.position:set(500,500)
      original.colour:set(255,0,0,255)

      local copy = original:clone()
      copy.position:set(600,600)
      copy.colour:set(0,255,0,255)
    • Sorts this shape above the submitted shape.

      Parameters

      • shape: osrs.Shape

        The shape to sort above.

      • Optionalstep: number

        [optional] How many sort ids to step over as we walk upwards looking for an empty slot. Defaults to half the id stride (512). must be positive!

      Returns void

      local first = osrs.Shape.new(osrs.Shape.PrimitiveType.RECTANGLE)
      first.position:set(500,500)
      first.colour:set(255,0,0,255)

      local second = osrs.Shape.new(osrs.Shape.PrimitiveType.RECTANGLE)
      second.position:set(520,520)
      second.colour:set(0,255,0,255)

      --normally first draws behind second, but this causes it to sort in front.
      first:sortAbove(second)
    • Sort the shape as closely as possible to the submitted Id.

      Parameters

      • id: number

        The id to set. Will walk upwards by 1 until a free id slot is found.

      Returns void

      -- bring a shape to the top of the sort order, and then return it to it's staring position.
      -- assume "rect" and "top_shape" are shapes, and top_shape is the highest-positioned shape.

      --save off rect's position in the sort order.
      local starting_id = rect.id

      --bring rect to top.
      rect_id.sortAbove(top_shape)

      --return shape to starting position. If something has claimed its id, will sort as closely as possible
      --to the requested id.
      rect.sortAt(starting_id)
    • Sorts this shape below the submitted shape

      Parameters

      • shape: osrs.Shape

        The shape to sort below.

      • Optionalstep: number

        [optional] How many sort ids to step over as we walk downwards looking for an empty slot. Defaults to half the id stride (-512). must be negative!

      Returns void

      local first = osrs.Shape.new(osrs.Shape.PrimitiveType.RECTANGLE)
      first.position:set(500,500)
      first.colour:set(255,0,0,255)

      local second = osrs.Shape.new(osrs.Shape.PrimitiveType.RECTANGLE)
      second.position:set(530,530)
      second.colour:set(0,255,0,255)

      --normally second draws in front of first, but this causes it to sort below.
      second:sortBelow(first)
    • Constructor

      Parameters

      • type: PrimitiveType

        The PrimitiveType this Shape represents

      • OptionalshouldRender: boolean

        Should the shape be added to the draw list? Defaults to true.

      Returns osrs.Shape

      -- Create a new shape that will render 
      local renderShape = osrs.Shape.new(osrs.Shape.PrimitiveType.RECTANGLE)
      -- Create a new shape that will not render
      local notRenderedShape = osrs.Shape.new(osrs.Shape.PrimitiveType.CIRCLE, false)