Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a `solid` to render over a `sprite` in DragonRuby Game Toolkit?

The following code renders a sprite and a solid with an alpha. But the solid renders below the sprite. How do I get the solid to render above the sprite?

def tick args
  args.outputs.sprites << { 
    x: 100,
    y: 100,
    w: 50,
    h: 60,
    path: 'sprites/square-red.png'
  }

  args.outputs.solids << {
    x: 0,
    y: 0,
    w: 1280,
    h: 720,
    r: 80,
    g: 80,
    b: 80,
    a: 128
  }
end
like image 261
Amir Avatar asked Oct 15 '25 14:10

Amir


1 Answers

The default render order (bottommost to topmost) for primitives is:

  • solids
  • sprites
  • primitives
  • labels
  • lines
  • borders

To have a solid render over a sprite, you must use args.outputs.primitives which will render in the order that you add to the collection (regardless of primitive type):

def tick args
  # step 1: use .primitives instead of .sprites
  args.outputs.primitives << { 
    x: 100, 
    y: 100, 
    w: 50, 
    h: 60, 
    path: 'sprites/square-red.png' 
  }.sprite # step 2: invoke the .sprite function on the primitive

  # step 3: use .primitives instead of .solids
  args.outputs.primitives << { 
    x: 0,
    y: 0,
    w: 1280,
    h: 720,
    r: 80,
    g: 80,
    b: 80,
    a: 128
  }.solids # step 4: mark the primitive as a solid
end

This begs the question:

Should I use .primitives for everything?

That is totally fine to do frankly.

like image 173
Amir Avatar answered Oct 19 '25 03:10

Amir