Home

Awesome

List View classes for Phaser

Install via npm

npm install phaser-list-view --save https://www.npmjs.com/package/phaser-list-view

Install via script tag

Copy dist/phaser-list-view.js into your project and include via script tag

Build

npm run build

Run demo

npm i

npm start

API

ListView

Usage

import {ListView} from 'phaser-list-view'

const parent = this.world
const bounds = new Phaser.Rectangle(0, 0, 300, 400)
const options = {
  direction: 'y',
  overflow: 100,
  padding: 10
}

const listView = new ListView(this.game, parent, bounds, options)
const items = this.createSomeDisplayObjectsAndReturnAnArray() // [Graphics, Image, Sprite, Group]
listView.addMultiple(...items)
const newItem = this.createGroup();
newItem.nominalHeight = 120; // listView calculates items width and height. You can set your own width or height to save calculating it using nominalWidth or nominalHeight (note this is mainly useful for Phaser.Groups)
listView.add(newItem)

Options

API

MembersTypeDescription
itemsArray<DisplayObject>A list of all the listView items
grpPhaser.GroupThe parent of all list view items
positionnumber (READONLY)position in pixels (x or y axis depends on the direction you specify)
scrollerScrolleraccess the Scroller for advanced tuning (Scroller API below)
MethodsParamsDescription
add(child: DisplayObject): voidadd a child to the list view
addMultiple(...children: DisplayObjects): voidadd multiple children to the list view. Pass through multiple arguments, not an array of children
remove(child: DisplayObject): voidremove a child
removeAll(): voidremove all children from the list view
moveToPosition(position: number): voidset position of the list view in pixels
moveToItem(index: number): voidmove to the item index in the list view.
tweenToPosition(position: number, duration = 1: number): voidtween to position in pixels. Duration in seconds.
tweenToItem(index: number, duration = 1: number): voidtween to the item index in the list view. Duration in seconds.
reset(): voidresets the position and scroller
destroy(): voiddestroy the list view and clean up all event listeners

SwipeCarousel (extends ListView)

Usage

import {SwipeCarousel} from 'phaser-list-view'

const parent = this.world
const bounds = new Phaser.Rectangle(0, 0, 300, 400)
const options = {
  direction: 'x',
  overflow: 100,
  padding: 10
}

const swipeCarousel = new SwipeCarousel(this.game, parent, bounds, options)
const photos = this.getAnArrayOfImages() // [Image, Image, Image, Image]
swipeCarousel.addMultiple(...photos)

Options

API

The same as ListView above.

Scroller API (access via listView.scroller)

MembersTypeDescription
grpPhaser.GroupThe parent of all list view items
positionnumber (READONLY)position in pixels (x or y axis depends on the direction you specify)
scrollerScrolleraccess the Scroller for advanced tuning
MethodsParams: ReturnDescription
enable(): voidEnables the scroller
disable(): voidDisables the scroller
isTweening(): booleanIs the scroller tweening?
Events (Phaser.Signals)
onUpdate
onInputUp
onInputDown
onInputMove
onComplete
onSwipe

DirectionalScroller Usage

// TODO

WheelScroller Usage

// TODO

Build

npm run compile

Example

http://mattcolman.com/labs/phaser-list-view/index.html

TODO

Maintainers

Matt Colman