【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;


})();
相关推荐
保持当下5 天前
分享一些程序员很棘手但是却又简单的工具
程序员·免费·js·工具
LONGZETECH6 天前
无人机仿真教学软件选型实战:5 个硬核技术维度,避开实训建设踩坑
3d·无人机·交互·cocos2d
鼎艺创新科技6 天前
三维电子沙盘中OSGB倾斜摄影数据的加载与渲染
游戏引擎·cocos2d
笑虾9 天前
Frida Hook Cocos2dx lua 3.15 的 lua 脚本
lua·cocos2d
玖玥拾10 天前
Cocos学习笔记:项目框架搭建与异步加载进度
游戏引擎·cocos2d
玖玥拾11 天前
Cocos学习笔记:序列化、配置文件与数据驱动
游戏引擎·cocos2d
Xzh042311 天前
Web 前端开发 — 期末复习指南(Html、Css、Js)
css·html5·web·js·期末
流浪法师解剖鱼11 天前
CocosCreator制作推箱子游戏
python·cocos2d
玖玥拾11 天前
Cocos学习笔记:瓦片地图与坐标转换
游戏引擎·cocos2d
玖玥拾12 天前
Cocos学习笔记:粒子系统与对象层批量处理
游戏引擎·cocos2d