百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

slick-ui

> 编程语言
开源

轻量级 Phaser UI 插件

194 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

轻量级 Phaser UI 插件

Released as public domain - feel free to do anything to the library code you like. (this excludes the assets and the Phaser game engine)

SlickUI

SlickUI beats the challenge of creating user interfaces easily in an object oriented way.

Try out some previews

  • Sliding menu
  • Slider controller
  • Text input field

Getting started

Install using git:

bash
git clone https://github.com/Flaxis/slick-ui.git

Install using bower:

bash
bower install slick-ui

Make sure you have the [Default Kenney theme] in your project assets and ready to load.

Add the following to the bottom of your preload function:

javascript
// You can use your own methods of making the plugin publicly available. Setting it as a global variable is the easiest solution.
slickUI = game.plugins.add(Phaser.Plugin.SlickUI);
slickUI.load('assets/ui/kenney/kenney.json'); // Use the path to your kenney.json. This is the file that defines your theme.

That's it! You're ready to start UI-ing!

Usage

To start using the UI manager, find a nice spot in your create() function and get started:

Adding a panel

Assuming you're using the variable slickUI for the plugin object

javascript
var panel;
slickUI.add(panel = new SlickUI.Element.Panel(8, 8, 150, game.height - 16));

This tells the UI manager to add a new panel at X and Y = 8, width of 150 pixels and as high as the game minus 16 pixels.

We can now use the panel's container to add new elements to it.

Adding a button

Let's say we wanted to add a button to the panel we just created:

javascript
var button;
panel.add(button = new SlickUI.Element.Button(0,0, 140, 80));
button.events.onInputUp.add(function () {console.log('Clicked button');});
button.add(new SlickUI.Element.Text(0,0, "My button")).center();

We now added a button to the panel with the label 'My button'. When we click on it, the console will output 'Clicked Button'.

So what if we wanted to use SlickUI to be a bit more generic? We can also add DisplayObjects to the user interface in the same way.

Adding a DisplayObject

We'll assume we have a sprite cached as 'menu-button'

javascript
var menuButton;
slickUI.add(menuButton = new SlickUI.Element.DisplayObject(8, 8, game.make.sprite(0, 0, 'menu-button')));

That's it! You might be thinking, why would you add a DisplayObject using the UI manager if we can do that just by using phaser's built in tools?

The answer is, because UI elements are cascading and they take care of that themselves by using containers. When adding a Panel, Button or DisplayObject, the UI manager puts it in a container and adds a Phaser group to keep the descending elements organized so you can manipulate entire containers.

Adding a Checkbox

Checkboxes can be added using 3 sprites: checkbox, radio and cross. This is how you add a checkbox:

javascript
var cb;
panel.add(cb = new SlickUI.Element.Checkbox(0,10, SlickUI.Element.Checkbox.TYPE_RADIO));
cb.events.onInputDown.add(function () {
    console.log(cb.checked ? 'Checked' : 'Unchecked');
}, this);

If you don't provide a type using the last parameter, the default type will be used. You can choose between the following types:

  • SlickUI.Element.Checkbox.TYPE_CHECKBOX (default type, no need to specify)
  • SlickUI.Element.Checkbox.TYPE_RADIO
  • SlickUI.Element.Checkbox.TYPE_CROSS

Adding a Slider

Sliders are used to give the illusion of analog control over an object's property. For example, the game's music volume.

javascript
var slider;
panel.add(slider = new SlickUI.Element.Slider(16,100, panel.width - 32));
/*
 * To create a slider rendered vertically:
 * new SlickUI.Element.Slider(game.width - 64,130, game.height - 178, 0.5, true);

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScriptgame-libraryjavascriptlibraryphaser

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言