惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

IT之家
IT之家
博客园 - 聂微东
雷峰网
雷峰网
Microsoft Azure Blog
Microsoft Azure Blog
WordPress大学
WordPress大学
Hugging Face - Blog
Hugging Face - Blog
S
SegmentFault 最新的问题
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog
博客园 - 三生石上(FineUI控件)
V
Visual Studio Blog
博客园 - 司徒正美
爱范儿
爱范儿
月光博客
月光博客
阮一峰的网络日志
阮一峰的网络日志
博客园_首页
博客园 - 【当耐特】
Jina AI
Jina AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
酷 壳 – CoolShell
酷 壳 – CoolShell
大猫的无限游戏
大猫的无限游戏
小众软件
小众软件
人人都是产品经理
人人都是产品经理
V
V2EX

博客园 - 华安

C#中Microsoft.Extensions.Caching.Memory 与 System.Runtime.Caching.MemoryCache区别 自适应网格系统:CSS Grid中repeat()、auto-fill与auto-fit的深度解析 CSS3中响应式布局两大神器display:flex和display:grid springBoot中的 pom.xml文件 bulid学习 CSS中元素的display显示方式有多种,隐藏、块级、内联、内联-块级 SQl Server 中的 go 是什么作用 CSS中 display:flex的align-items: stretch; 移动端浏览器(尤其是 iOS Safari)的橡皮筋回弹效果(Overscroll / Bounce Effect) 手机端浏览器上ES6中的Fetch回调执行 window.open没效果 用Flex实现兼容性好的全屏布局 在 VS Code 中使用 C# Dev Kit 和 Unity Tools 调试 Unity 2022 Unity 可编程物件(ScriptableObject) 微信小程序中的 联系客服 最基本的使用方法 wx.requestSubscribeMessage(Object object) 和 wx.requestSubscribeDeviceMessage(Object object) 这两个有什么区别 微信小程序中 wx.hideLoading() 后调用 wx.showToast()的问题 Windows 中启动 Nginx的常用命令 CSS进阶技巧:字体渐变、描边、倒影与渐变色描边全解析 netCore 中各DLL引用了 SkiaSharp.dll的问题 unity中预制体解包 在 Unity 中,Time.timeScale实现游戏暂停加速等 微信小程序中关联微信支付 unity中的 Navigation AI使用 C#中TaskCompletionSource(简称 TCS)学习 Unity 编辑器 中,快捷键 Ctrl + Shift + F 的功能 unity中按下 F键,让物体聚焦 微信中进入定页面的,判断时通过扫二维码进入的,还是点小程序名称进入的 MYSQL中从JSON字符串中提取指定的值 Unity2022中创建动画 Animation(旧方法) Unity 中区别,public 和 [SerializeField] Unity中 onCollisionEnter2D与OnTriggerEnter2D 区别
PixiJS中的 SplitBitmapText.chars中的每个 BitmapText的x值分析
华安 · 2026-01-09 · via 博客园 - 华安

最近在学习 pixijs,看到官网上的demo.

import {
  Application,
  Assets,
  BitmapText,
  Container,
  SplitBitmapText,
} from 'pixi.js';
import { gsap } from 'gsap';

(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.getElementById("pixi-container")!.appendChild(app.canvas);

  await Assets.load('https://pixijs.com/assets/bitmap-font/desyrel.xml');

  const scene = new Container();
  scene.position.set(app.screen.width / 2, app.screen.height / 2);
  app.stage.addChild(scene);

  const _text=`Break apart text into characters, words, and/or lines for easy111111111111111111 animation.`;

  const bitmapFontText = new BitmapText({
    text: _text,
    style: {
      fontFamily: 'Desyrel',
      fontSize: 60,
      fill: 'white',
      wordWrap: true,
      wordWrapWidth: app.screen.width - 100,
    },
    alpha: 0.5,
  });
  const splitText = new SplitBitmapText({
    text: _text,
    style: {
      fontFamily: 'Desyrel',
      fontSize: 60,
      fill: 0x0,
      wordWrap: true,
      wordWrapWidth: app.screen.width - 100,
    },
    alpha: 1,
  });
  bitmapFontText.on('mousedown',(event)=>{
    console.log(event,'111');
  });
  bitmapFontText.interactive=true;

  bitmapFontText.x = splitText.x = -bitmapFontText.width / 2;
  bitmapFontText.y = splitText.y = -bitmapFontText.height / 2;
  scene.addChild(bitmapFontText, splitText);

  console.log(splitText.chars,splitText,bitmapFontText);
   gsap.from(splitText.chars, {
    x: 50,
    alpha: 0,
    duration: 2.7,
    ease: 'power4',
    stagger: 0.04,
    repeat: -1,
    yoyo: true,
  }); 
})();

运行效果:

image

image

 仔细观察发现:

gsap.from(splitText.chars, {
    x: 50,
    alpha: 0,
    duration: 2.7,
    ease: 'power4',
    stagger: 0.04,
    repeat: -1,
    yoyo: true,
  }); 中的 x:50 是以空格为分隔符分割出来的一个大对象为container的位置,而不是整个 canvas 的位置。

image

image

image