Jump to content

Draw frame over a child


dann
 Share

Recommended Posts

Hi!

I would like to draw a node that hold its children in the way shown on the gif.

The problem in the border: it would be great if the border shell draw over the child. How can i get it?

My code:

function createRectWithText( w, h, t, c ) {
  const graphics = new PIXI.Graphics()
    .beginFill( c )
    .drawRoundedRect( 0, 0, w, h )
    .endFill()
  
  const sprite = new PIXI.Sprite( graphics.generateCanvasTexture() );
  
  graphics.destroy();

  const graphics_border = new PIXI.Graphics()
    .lineStyle( 10, 0x000000, 1, 0 )
    .beginFill( 0xffffff, 0 )
    .drawRoundedRect( 0, 0, w, h )
    .endFill()
  const sprite_border = new PIXI.Sprite( graphics_border.generateCanvasTexture() );
  graphics_border.destroy();

  let textStyle = new PIXI.TextStyle( {
    fontSize: h / 3,// * ( dpi_x + dpi_y ) / 2 / 96,
    wordWrap : true,
    wordWrapWidth : w
  } );
  var text = new PIXI.Text( t, textStyle );

  const container = new PIXI.Container()
  container.text = t

  const mask = new PIXI.Graphics()
    .beginFill( 0xff0000 )
    .drawRoundedRect( 0, 0, w, h )
    .endFill()
  container.mask = mask

  container.addChild( sprite );
  container.addChild( sprite sprite_border );
  container.addChild( text );
  container.addChild( mask );

  .......................................
  
  return container
}

let a = createRectWithText( 300, 100, "Qwe asdfghjlk zxc rty vbn qwe asd zxc bnm", 0x888888 )
a.x = 30
a.y = 20
let b = createRectWithText( 300, 100, "B", 0xaaaaaa )
b.x = 70
b.y = 50
a.addChild( b )
app.stage.addChild( a )
app.stage.sortableChildren = true

dann

Запись экрана 2021-11-18 в 11.34.19.gif

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...