【pixijs】关于pixijs画圆

pixijs中画布原点在左上角,向右是x的正方向,向下是y的正方向(这点和数学坐标系相反)。

用到arc函数时突然短路,忘记0度是从9点方向还是3点方向了,各种坐标系搞晕了,写个文章记录下。

演练场:https://pixijs.com/8.x/playground

demo如下:

javascript 复制代码
import { Application, Assets, Container, Sprite, Graphics } from 'pixi.js';

(async () => {
  // Create a new application
  const app = new Application();

  // Initialize the application
  await app.init({ background: '#1099bb', resizeTo: window });

  // Append the application canvas to the document body
  document.body.appendChild(app.canvas);

  // Create and add a container to the stage
  const container = new Container();

  app.stage.addChild(container);

  const graphics = new Graphics();
  graphics
    .arc(0, 0, 50, 0, Math.PI / 5)
    .stroke({ width: 2, color: 'pink' });

  // Draw a full circle using an arc
  graphics
    .arc(100, 0, 30, 0, Math.PI * 2)
    .stroke({ color: 'red' });

  // Draw a counterclockwise arc
  graphics
    .arc(200, 0, 40, 0, Math.PI / 5, true)
    .stroke({ width: 2, color: 'green' });
  container.addChild(graphics);
  // Move the container to the center
  container.x = app.screen.width / 2;
  container.y = app.screen.height / 2;

  // Center the bunny sprites in local container coordinates
  container.pivot.x = container.width / 2;
  container.pivot.y = container.height / 2;


})();
相关推荐
怣疯knight2 天前
Cocos creator避坑指南(一些比较容易错的地方)
cocos2d
程序媛小鱼4 天前
openlayers撤销与恢复
前端·js
Han.miracle4 天前
JQuery 基础与综合案例实践
jquery·js
FE阿祖4 天前
koa学习
koa·js·ndoe
东方不败之鸭梨的测试笔记5 天前
lodash-cloneDeep
js
道法自然|~7 天前
【建站】网站使用天地图
html·web·js
小阿宁的猫猫9 天前
XSS的原理、使用、防御方法及练习题
web安全·网络攻击模型·xss·js
jumu2029 天前
COMSOL凝固模拟:从溶质偏析到枝晶生长实战
cocos2d
z2014z9 天前
Cocos Creator Playable 广告项目文件夹结构与命名规范
cocos2d