Jump to content

When sprite have width and height,how am i set border


fengFanYong
 Share

Recommended Posts

hello 

i create a sprite,and set it is width and height,the graphics is sprite children,How am i set the graphics border;

code : 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>text border</title>
    <script src="../pixi/pixi.min.js"></script>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
    </style>
</head>
<body>

<script>
    var renderer = PIXI.autoDetectRenderer(window.innerWidth, window.innerHeight, {antialias: true});
    document.body.appendChild(renderer.view);

    sp = new PIXI.Sprite();
    sp.x = 100;
    sp.y = 100;
    sp.width = 200;
    sp.height = 400;

    gt = new PIXI.Graphics();
    gt.beginFill(0x123123);
    gt.lineStyle(.01,0xFFFFFF,1);
    gt.drawRoundedRect(0,0,1,1,.1);
    gt.endFill();

    sp.addChild(gt);
    renderer.render(sp);

</script>
</body>
</html>

if i draw a width != height;the border height > border width.

Quote

 

Link to comment
Share on other sites

I am not sure that I understood what do you want to achieve but there are few things that I can see you did wrong in the above code.

You have created empty sprite and setting width and height on the empty sprite has no effect. Instead you should provide Texture argument to create Sprite. Texture you can get out of Graphics like so:

gt = new PIXI.Graphics();
gt.beginFill(0x123123);
gt.lineStyle(.01,0xFFFFFF,1);
gt.drawRoundedRect(0,0,1,1,.1);
gt.endFill();
var texture = gt.generateCanvasTexture();
// and then create sprite
sp = new PIXI.Sprite(texture);
sp.x = 100;
sp.y = 100;
sp.width = 200;
sp.height = 400;

HTH Vitalije

Link to comment
Share on other sites

Quote

but the top of border > left of border

That is because you drawRoundedRect that has same witdth and height, and later make sprite that has height twice as width. Try:

...
gt.drawRoundedRect(0,0,1,2,.1);
// or even
// gt.lineStyle(2, 0xFFFFFF, 1);
// gt.drawRoundedRect(0, 0, 200, 400, 0.1);
gt.endFill();
var texture = gt.generateCanvasTexture();
...

HTH Vitalije

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...