Token导航 LogoToken导航TokenDH.com
待分类操作浏览器github未标认证来源可访问许可证需确认审计通过

text-and-bitmaptext文本和位图文本

Agent Skill

text-and-bitmaptext 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

1,008

周安装

42

GitHub Stars

39,493

下载量

336
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:text-and-bitmaptext(文本和位图文本)
来源仓库:https://github.com/phaserjs/phaser
仓库路径:skills/text-and-bitmaptext
安装命令:
npx skills add https://github.com/phaserjs/phaser --skill text-and-bitmaptext
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/phaserjs/phaser --skill text-and-bitmaptext

简介

text-and-bitmaptext 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息。

  • 适合在需要围绕仓库状态、代码变更或协作事项进行整理时使用。
  • 可结合来源仓库、安装命令和原始 README 继续核验具体用法。
  • 安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。
  • 建议进一步查阅原始 README 了解实际功能和调用方式。

SKILL.md

Text and BitmapText

Displaying text in Phaser 4 -- the Canvas-based Text game object, TextStyle configuration, word wrap, BitmapText (static and dynamic), retro fonts, text alignment, text bounds, and padding.

Key source paths: src/gameobjects/text/, src/gameobjects/bitmaptext/static/, src/gameobjects/bitmaptext/dynamic/ Related skills:../loading-assets/SKILL.md,../sprites-and-images/SKILL.md,../game-object-components/SKILL.md

Quick Start

// Canvas-based Text (flexible styling, uses browser fonts)
const title = this.add.text(400, 50, 'Hello World', {
    fontFamily: 'Arial',
    fontSize: '32px',
    color: '#ffffff'
});

// BitmapText (pre-rendered font texture, faster rendering)
// Font must be loaded first: this.load.bitmapFont('myFont', 'font.png', 'font.xml')
const score = this.add.bitmapText(400, 100, 'myFont', 'Score: 0', 32);

// DynamicBitmapText (per-character manipulation via callback)
const fancy = this.add.dynamicBitmapText(400, 200, 'myFont', 'Wavy!', 32);
fancy.setDisplayCallback(function (data) {
    data.y += Math.sin(data.index * 0.5 + fancy.scene.time.now * 0.005) * 10;
    return data;
});

Core Concepts

Text vs BitmapText

FeatureTextBitmapTextDynamicBitmapText
Rendering methodCanvas 2D API, uploaded as texturePre-rendered font texturePre-rendered font texture
Web/CSS fontsYesNoNo
Shadows, gradients, strokesYes (Canvas API)Drop shadow only (WebGL)No
Word wrapBuilt-in (width, callback, advanced)setMaxWidthsetMaxWidth
Per-character effectsNosetCharacterTint, setWordTint (WebGL)setDisplayCallback
PerformanceSlower (re-creates canvas texture on change)Fast (batched rendering)Moderate (callback per char)
Alignmentleft, right, center, justifyALIGN_LEFT (0), ALIGN_CENTER (1), ALIGN_RIGHT (2)Same as BitmapText
RTL supportYes (rtl style option)NoNo

Rule of thumb: Use Text for UI elements that need flexible styling, web fonts, or infrequent updates. Use BitmapText for scores, timers, and anything that updates frequently or is rendered in large quantities. Use DynamicBitmapText only when you need per-character animation effects.

TextStyle

The Text game object delegates all styling to its TextStyle instance, accessible via text.style. You pass a style config object when creating the Text, or update it later with setter methods. The style object uses Canvas 2D properties internally.

The fontFamily default is 'Courier', fontSize default is '16px', and color default is '#fff'. The font shorthand property (e.g. 'bold 24px Arial') overrides fontFamily, fontSize, and fontStyle when provided.

Common Patterns

Basic Text Creation

// Simple text with inline style
const label = this.add.text(100, 100, 'Player 1', {
    fontFamily: 'Georgia',
    fontSize: '24px',
    color: '#00ff00'
});

// Using the font shorthand (sets fontStyle, fontSize, fontFamily)
const bold = this.add.text(100, 150, 'Bold Text', {
    font: 'bold 28px Arial'
});

// Array of strings creates multi-line text
const multi = this.add.text(100, 200, ['Line 1', 'Line 2', 'Line 3'], {
    fontFamily: 'Arial',
    fontSize: '18px',
    color: '#ffffff'
});

// Text origin defaults to (0, 0) -- top-left corner
label.setOrigin(0.5); // center the text on its position

Styling Text

const text = this.add.text(400, 300, 'Styled', {
    fontFamily: 'Verdana',
    fontSize: '48px',
    color: '#ff0000',
    stroke: '#000000',
    strokeThickness: 4,
    backgroundColor: '#333333',
    shadow: { offsetX: 2, offsetY: 2, color: '#000', blur: 4, stroke: false, fill: true }
});

// Modify style after creation (all return `this` for chaining)
text.setColor('#00ffff');
text.setFontSize(64);
text.setFontFamily('Courier');
text.setFontStyle('italic');
text.setStroke('#ff00ff', 6);
text.setShadow(3, 3, '#000', 5, false, true);
text.setBackgroundColor('#222');

// Replace entire style at once
text.setStyle({ fontSize: '64px', fontFamily: 'Arial', color: '#ffffff', align: 'center' });

// Canvas gradients and patterns work as fill/stroke
const gradient = text.context.createLinearGradient(0, 0, 0, text.height);
gradient.addColorStop(0, '#ff0000');
gradient.addColorStop(1, '#0000ff');
text.setFill(gradient);

Word Wrap

// Basic word wrap by pixel width
const wrapped = this.add.text(50, 50, 'Long text here...', {
    fontFamily: 'Arial',
    fontSize: '20px',
    color: '#fff',
    wordWrap: { width: 300 }
});

// Or set after creation
wrapped.setWordWrapWidth(300);

// Advanced wrap (collapses spaces, trims whitespace)
wrapped.setWordWrapWidth(300, true);

// Custom word wrap callback
wrapped.setWordWrapCallback(function (text, textObject) {
    // Return wrapped text as string with \n or array of lines
    return text.split(' ').join('\n');
});

// Get wrapped lines as array
const lines = wrapped.getWrappedText();

Text Alignment

// Alignment only affects multi-line text: 'left' (default), 'right', 'center', 'justify'
const aligned = this.add.text(400, 100, 'Line 1\nLonger Line 2\nLine 3', {
    fontFamily: 'Arial', fontSize: '24px', color: '#fff', align: 'center'
});

aligned.setAlign('right');

// For center alignment to look correct, combine with fixedWidth:
aligned.setFixedSize(300, 0);
aligned.setAlign('center');

Dynamic Text Updates

const scoreText = this.add.text(10, 10, 'Score: 0', {
    fontFamily: 'Arial',
    fontSize: '24px',
    color: '#fff'
});

// setText replaces content (accepts string or string[])
scoreText.setText('Score: 100');
scoreText.setText(['Score: 100', 'Lives: 3']); // joins with \n

// appendText adds to existing content
scoreText.appendText('Extra line');          // prepends \n by default
scoreText.appendText(' more', false);        // no carriage return

// Read current text
const current = scoreText.text;

Text Padding

// Padding adds space around text inside the canvas
const padded = this.add.text(100, 100, 'Padded', {
    fontFamily: 'Arial', fontSize: '24px', color: '#fff',
    backgroundColor: '#333',
    padding: { left: 10, right: 10, top: 5, bottom: 5 }
});

padded.setPadding({ x: 10, y: 5 });       // shorthand: x=left+right, y=top+bottom
padded.setPadding(10, 5, 10, 5);           // left, top, right, bottom
padded.setPadding(10);                     // single value = all sides

Fixed Size, Max Lines, and Spacing

// Fixed dimensions create a text canvas of exact size
const fixed = this.add.text(100, 100, 'Fixed box', {
    fontFamily: 'Arial', fontSize: '18px', color: '#fff',
    fixedWidth: 200, fixedHeight: 100,
    wordWrap: { width: 200 }, align: 'center'
});
fixed.setMaxLines(3); // limit displayed lines

// Line and letter spacing (in style config or via setters)
const spaced = this.add.text(100, 200, 'Spaced\nLines', {
    fontFamily: 'Arial', fontSize: '24px', color: '#fff',
    lineSpacing: 10, letterSpacing: 2
});
spaced.setLineSpacing(20);
spaced.setLetterSpacing(5);

BitmapText Creation

// Load in preload: this.load.bitmapFont('pixelFont', 'font.png', 'font.xml');

// Static BitmapText -- fast, batched rendering
const bmpText = this.add.bitmapText(100, 100, 'pixelFont', 'Hello', 32);

// With alignment (for multi-line)
const aligned = this.add.bitmapText(100, 200, 'pixelFont', 'Line 1\nLine 2', 24, 1);
// align: 0 = left, 1 = center, 2 = right

// Convenience alignment methods
bmpText.setLeftAlign();
bmpText.setCenterAlign();
bmpText.setRightAlign();

// Modify text
bmpText.setText('Updated!');
bmpText.text = 'Also works';

// Font size
bmpText.setFontSize(48);
bmpText.fontSize = 48;

// Spacing
bmpText.setLetterSpacing(2);
bmpText.setLineSpacing(5);

// Word wrap by max pixel width
bmpText.setMaxWidth(200);

BitmapText Drop Shadow and Tinting

// Drop shadow (WebGL only, static BitmapText only)
bmpText.setDropShadow(2, 2, 0x000000, 0.5);
// Clear shadow
bmpText.setDropShadow();

// Tint individual characters (WebGL only)
bmpText.setCharacterTint(0, 5, Phaser.TintModes.MULTIPLY, 0xff0000);
// start index, length (-1 for all from start), tintMode, color

// Tint by word (string match or word index)
bmpText.setWordTint('Score', -1, Phaser.TintModes.MULTIPLY, 0x00ff00);

DynamicBitmapText

const dynamic = this.add.dynamicBitmapText(100, 100, 'pixelFont', 'Dynamic!', 32);

// Per-character display callback -- invoked each render frame per character
dynamic.setDisplayCallback(function (data) {
    // data properties: parent, tint, index, charCode, x, y, scale, rotation, data
    data.x += Math.sin(data.index + dynamic.scene.time.now * 0.01) * 5;
    data.y += Math.cos(data.index + dynamic.scene.time.now * 0.01) * 5;
    return data;
});

// Scrolling text window
dynamic.setSize(200, 50);      // crop region in pixels
dynamic.setScrollX(10);
dynamic.setScrollY(0);

Retro Fonts

Retro fonts use a fixed-width character grid from a standard image (no XML/JSON font file needed).

// In preload -- load the image containing the font characters
this.load.image('retroFont', 'retroFont.png');

// In create -- parse the retro font configuration
const config = {
    image: 'retroFont',
    width: 8,           // character width in pixels
    height: 8,          // character height in pixels
    chars: Phaser.GameObjects.RetroFont.TEXT_SET1,
    charsPerRow: 16,
    offset: { x: 0, y: 0 },
    spacing: { x: 0, y: 0 },
    lineSpacing: 0
};

// Parse adds it to the BitmapFont cache
this.cache.bitmapFont.add('retroFont', { data: Phaser.GameObjects.RetroFont.Parse(this, config) });

// Now use it like any BitmapText
const retro = this.add.bitmapText(100, 100, 'retroFont', 'RETRO TEXT', 8);

Available Phaser.GameObjects.RetroFont TEXT_SET constants: TEXT_SET1 (full ASCII printable), TEXT_SET2 (space through Z), TEXT_SET3-TEXT_SET11 (various subsets of uppercase, digits, punctuation). TEXT_SET10 is uppercase letters only.

Text Bounds (BitmapText)

// getTextBounds returns local, global, line, word, and character data
const bounds = bmpText.getTextBounds();
// bounds.local       -- { x, y, width, height } at origin 0,0
// bounds.global      -- { x, y, width, height } with scale + world position
// bounds.lines       -- per-line { x, y, width, height }
// bounds.words       -- word objects with positions
// bounds.characters  -- character objects with positions

// width/height are read-only properties (computed from global bounds)
console.log(bmpText.width, bmpText.height);

// Get character at world position (useful for click detection)
const char = bmpText.getCharacterAt(pointer.worldX, pointer.worldY);

Resolution (High DPI)

// Higher resolution for crisp text on HiDPI displays (costs more memory)
const crisp = this.add.text(100, 100, 'Sharp!', {
    fontFamily: 'Arial', fontSize: '24px', color: '#fff', resolution: 2
});
crisp.setResolution(window.devicePixelRatio); // change after creation

Configuration Reference

TextStyle Properties

PropertyTypeDefaultDescription
fontFamilystring'Courier'CSS font family
fontSizestring/number'16px'Font size (number auto-appends 'px')
fontStylestring''CSS font style ('bold', 'italic', 'bold italic')
fontstring-Shorthand: 'bold 24px Arial' (overrides family/size/style)
colorstring/CanvasGradient/CanvasPattern'#fff'Fill color
strokestring/CanvasGradient/CanvasPattern'#fff'Stroke color
strokeThicknessnumber0Stroke width (0 = no stroke)
backgroundColorstringnullSolid background color
alignstring'left'Multi-line alignment: 'left', 'right', 'center', 'justify'
maxLinesnumber0Max lines to render (0 = unlimited)
fixedWidthnumber0Fixed canvas width (0 = auto)
fixedHeightnumber0Fixed canvas height (0 = auto)
resolutionnumber0Canvas resolution (0 = use game config)
rtlbooleanfalseRight-to-left rendering
baselineXnumber1.2Horizontal padding for font metrics
baselineYnumber1.4Vertical padding for font metrics
testStringstring`'\MEqgy'`String used for font height measurement
wordWrapobject-{width, callback, callbackScope, useAdvancedWrap}
shadowobject-{offsetX, offsetY, color, blur, stroke, fill}
paddingobject-{left, right, top, bottom} or {x, y}
lineSpacingnumber0Extra vertical spacing between lines
letterSpacingnumber0Extra horizontal spacing between characters
metricsobject-Pre-computed {ascent, descent, fontSize} to skip measurement

Factory Methods

// Text -- Canvas-based
this.add.text(x, y, text, style);
// x, y: number; text: string | string[]; style: TextStyle (optional)
// Returns: Phaser.GameObjects.Text

// BitmapText -- static, fast
this.add.bitmapText(x, y, font, text, size, align);
// x, y: number; font: string (cache key); text: string | string[] (optional)
// size: number (optional, defaults to font data size); align: number (optional, 0)
// Returns: Phaser.GameObjects.BitmapText

// DynamicBitmapText -- per-character callback
this.add.dynamicBitmapText(x, y, font, text, size);
// Same as bitmapText but returns DynamicBitmapText
// Returns: Phaser.GameObjects.DynamicBitmapText

API Quick Reference

Text Methods

setText(value), appendText(value, addCR?), setStyle(style), setFont(font), setFontFamily(family), setFontSize(size), setFontStyle(style), setColor(color), setFill(color), setStroke(color, thickness), setShadow(x, y, color, blur, stroke, fill), setBackgroundColor(color), setWordWrapWidth(width, useAdvanced?), setWordWrapCallback(callback, scope?), setAlign(align), setPadding(left, top?, right?, bottom?), setFixedSize(width, height), setMaxLines(max), setLineSpacing(value), setLetterSpacing(value), setResolution(value), setRTL(rtl?), getWrappedText(text?), updateText()

All setters return this for chaining. Properties: text (get/set), style (TextStyle instance), padding, lineSpacing, letterSpacing, autoRound, splitRegExp.

BitmapText Methods

setText(value), setFont(font, size?, align?), setFontSize(size), setLetterSpacing(spacing?), setLineSpacing(spacing?), setMaxWidth(value, wordWrapCharCode?), setLeftAlign(), setCenterAlign(), setRightAlign(), setDropShadow(x?, y?, color?, alpha?), setCharacterTint(start?, length?, tintMode?, tl?, tr?, bl?, br?), setWordTint(word, count?, tintMode?, tl?, tr?, bl?, br?), getTextBounds(round?), getCharacterAt(x, y, camera?)

Properties (get/set): text, fontSize, letterSpacing, lineSpacing, align (number), maxWidth. Read-only: width, height, font, fontData.

Alignment constants: BitmapText.ALIGN_LEFT (0), BitmapText.ALIGN_CENTER (1), BitmapText.ALIGN_RIGHT (2).

DynamicBitmapText Methods (additional)

setDisplayCallback(callback), setSize(width, height), setScrollX(value), setScrollY(value)

Properties: scrollX, scrollY, cropWidth, cropHeight, displayCallback, callbackData.

Gotchas

  1. Text re-renders on every change. Each call to setText, setStyle, setColor, etc. re-creates the internal canvas and (in WebGL) re-uploads the texture. Batch your style changes and call updateText() once, or set the style object properties directly and call updateText() at the end.
  2. Font must be loaded before use. The Text object uses the Canvas fillText API, so fonts must be available in the browser (loaded via CSS, a web font loader, or already installed). Phaser does not load web fonts -- use a third-party loader or CSS @font-face.
  3. Font names with special characters need quotes. Font names containing digits or special characters must be double-quoted inside the string: fontFamily: '"Press Start 2P"'.
  4. Text origin defaults to (0, 0). Unlike Sprites which default to (0.5, 0.5), Text objects default to top-left origin. Call setOrigin(0.5) to center.
  5. Alignment only affects multi-line text. align: 'center' does nothing on single-line text. For centering a single line, use setOrigin(0.5) or position it manually.
  6. BitmapText font must be in cache. The font key passed to this.add.bitmapText() must match a key loaded via this.load.bitmapFont(). If missing, you get a console warning and undefined behavior.
  7. BitmapText setMaxWidth only wraps on whitespace. If no whitespace character is found (default char code 32 = space), no wrapping occurs. Change the wrap character with the second argument to setMaxWidth.
  8. DynamicBitmapText is more expensive. The display callback runs for every character every frame. Only use it when you need per-character manipulation.
  9. setCharacterTint and setWordTint are WebGL only. These have no effect in Canvas renderer.
  10. setDropShadow is WebGL only and static BitmapText only. It does not work with DynamicBitmapText or the Canvas renderer.
  11. letterSpacing on Text is expensive. When non-zero, Phaser renders each character individually with fillText instead of the whole line at once. Use BitmapText for large amounts of text with custom letter spacing.
  12. setFill and setColor are equivalent. Both set the color property on the TextStyle. The style config also accepts fill as an alias for color.
  13. setRTL must be called BEFORE setText. Right-to-left mode changes how the internal canvas is constructed. If you call setRTL(true) after setting text, the text may not render correctly. Set RTL in the style config or call setRTL() before any setText() call.
  14. BitmapText is much faster for frequently updating content. Text re-renders its entire Canvas and re-uploads the GPU texture on every change. BitmapText just updates vertex data in an existing texture atlas. For scores, timers, damage numbers, or any text that changes every frame, always prefer BitmapText.

Source File Map

FileDescription
src/gameobjects/text/Text.jsText class (Canvas-based rendering)
src/gameobjects/text/TextFactory.jsthis.add.text() factory
src/gameobjects/text/TextStyle.jsTextStyle class (all style properties + setters)
src/gameobjects/text/GetTextSize.jsInternal text measurement
src/gameobjects/text/MeasureText.jsFont metrics measurement
src/gameobjects/text/typedefs/TextStyle, TextWordWrap, TextPadding, TextShadow typedefs
src/gameobjects/bitmaptext/static/BitmapText.jsStatic BitmapText class
src/gameobjects/bitmaptext/static/BitmapTextFactory.jsthis.add.bitmapText() factory
src/gameobjects/bitmaptext/dynamic/DynamicBitmapText.jsDynamicBitmapText (extends BitmapText)
src/gameobjects/bitmaptext/dynamic/DynamicBitmapTextFactory.jsthis.add.dynamicBitmapText() factory
src/gameobjects/bitmaptext/ParseRetroFont.jsRetro font parser (RetroFont.Parse)
src/gameobjects/bitmaptext/RetroFont.jsRetroFont namespace (Parse + TEXT_SET constants)
src/gameobjects/bitmaptext/const.jsTEXT_SET1 through TEXT_SET11 constants
src/gameobjects/bitmaptext/GetBitmapTextSize.jsBitmapText bounds calculation
src/gameobjects/bitmaptext/typedefs/RetroFontConfig, DisplayCallbackConfig, BitmapTextSize typedefs

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

37.44%
按下载量换算126

Claude

29.29%
按下载量换算98

Cursor

18.66%
按下载量换算63

Gemini CLI

10.55%
按下载量换算35

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

操作浏览器

该 Skill 可能涉及浏览器控制能力,使用时可能读取或操作网页内容,需要在受控环境中确认权限边界。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills