mariamdh Posted July 28, 2020 Share Posted July 28, 2020 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(0xDE3249, 1); this.drawCircle(360, 100, 20); this.endFill(); } Please help me understand why does a graphic and sprite with the same coordinates show at different positions when rendered. Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted July 28, 2020 Share Posted July 28, 2020 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. Quote Link to comment Share on other sites More sharing options...
mariamdh Posted July 28, 2020 Author Share Posted July 28, 2020 Thanks, it works. I let the initial local coordinates now be 0, and then change the position of the graphic once it is drawn. ivan.popelyshev 1 Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted July 28, 2020 Share Posted July 28, 2020 > I let the initial local coordinates now be 0, and then change the position of the graphic once it is drawn. Yep, that's how its usually done in all Flash-2d engines Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.