1.5.2 • Published 6 years ago

phaser-list-view v1.5.2

Weekly downloads
6
License
ISC
Repository
github
Last release
6 years ago

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

  • Scroller : A pure logic scroller. Includes iOS-like behaviour such as momentum, bounce-back and snapping. Most likely you would use DirectionalScroller or WheelScroller over this base Scroller. But if you have custom needs you can use it.
  • DirectionalScroller : A pure logic scroller built for scrolling on the x and y axis. Extends the base Scroller class.
  • WheelScroller : A pure logic scroller built for scrolling around a circle. Extends the base Scroller class.
  • ListView : An iOS-like ListView class. Uses DirectionalScroller for the input and outputs a ListView. Performance is good because we cull off-screen items. Perfect for high scoreboards.
  • SwipeCarousel : An iOS-like SwipeCarousel. Uses DirectionalScroller for the input and outputs a SwipeCarousel. Perfect for instructions screens, or a photo gallery.

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)

npm.io

Options

  • direction direction of scroll 'x' | 'y' // default 'y'
  • autocull auto hidden elements outside of the viewport for performance boolean // default true
  • momentum boolean // default true
  • bouncing when you extend beyond the bounds and release, it bounces back boolean // default true
  • snapping snaps to snapStep boolean // default false
  • snapStep number // default undefined
  • overflow: Amount in pixels you can pull past the bounds. Bouncing occurs when you release inside the overflow number // default 100
  • padding: Padding between the children number // default 10
  • searchForClicks: onInputDown and onInputUp events on ListView children will become active when set to true boolean // default false

API

MembersTypeDescription
itemsArrayA 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)

npm.io

Options

  • direction direction of scroll 'x' | 'y' // default 'x'
  • autocull auto hidden elements outside of the viewport for performance boolean // default true
  • momentum boolean // default false
  • bouncing when you extend beyond the bounds and release, it bounces back boolean // default true
  • snapping snaps to bounds.width + padding boolean // default true
  • overflow: Amount in pixels you can pull past the bounds. Bouncing occurs when you release inside the overflow number // default 100
  • padding: Padding between the children number // default 10
  • searchForClicks: onInputDown and onInputUp events on ListView children will become active when set to true boolean // default false

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

  • Mouse wheel support

Maintainers

Matt Colman

1.5.2

6 years ago

1.5.1

6 years ago

1.4.1

6 years ago

1.4.0

6 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.2.3

8 years ago

1.2.2

8 years ago

1.2.0

8 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.10

8 years ago

1.0.9

8 years ago

1.0.8

8 years ago

1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago