Jump to content

Issue with positioning graphics and image sprites


mariamdh
 Share

Recommended Posts

I am facing an issue understanding how graphics are positioned within the renderer. I've done the position comparison using a sprite and a graphic circle.

const canvas = document.getElementById('gameCanvas');
const app = new PIXI.Application({
    antialias: true,
    view:canvas,
    width:768,
    height:1024
});
 
function loadgame(){
    var img = new PIXI.Sprite(loader.resources.img.texture);
    app.stage.addChild(img);
    
    img.anchor.set(0.5);
    img.position.set(360,100);
}
The above code positions the image sprite roughly at the center of the X location of the rendering screen.
Now when I create a graphic (circle) and set the X to 360, it gets drawn at the width end of the rendering screen (the x location when set to 0 is correctly positioned at the starting edge of the screen).
 
DrawCircle(){
//This code is part of a class
        this.lineStyle(0);
        this.beginFill(0xDE32491);
        this.drawCircle(36010020);
        this.endFill();
    }
 
Please help me understand why does a graphic and sprite with the same coordinates show at different positions when rendered.
Link to comment
Share on other sites

Position !== shape local coors

You probably set both "position" and offset for circle. Position is part of transform, you can change it any time. Coords that you use in drawCircle are "baked" to a shape. Position=360, drawCircle(360) means that the center will be shown at 720. You can change position later, but not shape local coords, you have to use clear() for that.

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