Giter Club home page Giter Club logo

phaser-list-view's Introduction

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)

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

Members Type Description
items Array A list of all the listView items
grp Phaser.Group The parent of all list view items
position number (READONLY) position in pixels (x or y axis depends on the direction you specify)
scroller Scroller access the Scroller for advanced tuning (Scroller API below)
Methods Params Description
add (child: DisplayObject): void add a child to the list view
addMultiple (...children: DisplayObjects): void add multiple children to the list view. Pass through multiple arguments, not an array of children
remove (child: DisplayObject): void remove a child
removeAll (): void remove all children from the list view
moveToPosition (position: number): void set position of the list view in pixels
moveToItem (index: number): void move to the item index in the list view.
tweenToPosition (position: number, duration = 1: number): void tween to position in pixels. Duration in seconds.
tweenToItem (index: number, duration = 1: number): void tween to the item index in the list view. Duration in seconds.
reset (): void resets the position and scroller
destroy (): void destroy 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

  • 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)

Members Type Description
grp Phaser.Group The parent of all list view items
position number (READONLY) position in pixels (x or y axis depends on the direction you specify)
scroller Scroller access the Scroller for advanced tuning
Methods Params: Return Description
enable (): void Enables the scroller
disable (): void Disables the scroller
isTweening (): boolean Is 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

phaser-list-view's People

Contributors

lukz avatar mattcolman avatar xtforgame avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

phaser-list-view's Issues

Is lodash required?

Phaser list view on its own weights ~59KB.

There are two additional things that make it huge:
Lodash - 550KB
TweenMax (GSAP) - 356KB - I saw it's used for tweening. Maybe it can be replaced with native phaser tweens.

Is Lodash used in the plugin? scroller_event_patcher 'lodash/forIn' is used, but few files require whole lodash (which is huge) and doesn't seem to use it. When I removed it my app kept working and bundle was a lot smaller. Is it necessary for anything?

Phaser List View does not work on IE10, android stock browser

I implemented the list view for my game scoreboard, tested it with chrome in redmi 1s and desktop works perfectly, but it wont even start the specific scene that use list view when it being tested on stock browser. Is it an unresolved issue or you can please give me some guide? btw, i using the script tag to implement

Add Scrollbar

Hi all,

nice project @mattcolman . I'd like to use this list view component with scroll (horizontal/vertical). Of course this would be optional and could be render at any place, up to developer.

Example of usage:

import { ListView, ScrollBar } from 'phaser-list-view';

const listView = new ListView(this.game, parent, bounds, options);
const scrollBar = new ScrollBar(listView, {
  height: 100px,
  width: 8px,
  type: 'horizontal'
});

I'm happy to work on some proposal PR. Please let me know what do you think.

Add TypeScript bindings

Would it be possible to add TypeScript bindings so this library is usable with TypeScript Phaser projects?

Please support Phaser 3

Hi @mattcolman !
Your plugin is awesome when we need a scroll view for leaderboard
Could you please add support for Phaser 3? For now, it is very hard to find any List view example or plugin for Phaser3.
Thank so much!

Publish a list of sprites

Hi,

I cannot seem to get it to run.
I have a list of sprites which I want to be displayed vertical and the user should be able to scroll through vertically.

var startX = this.fHeader.x;
	var startY = this.fHeader.y + this.fHeader.height;

	var sprites = [];
	this.highscores.forEach(function(highscore) {
		var sprite = game.add.sprite(startX, startY, 'spriteKey');
		startY += sprite.height;
		sprites.push(sprite);
	}, this);

	var bounds = new Phaser.Rectangle(0, 0, 1000, 2000);
	var options = {
		direction : 'y',
		overflow : 100,
		padding : 10
	};

	var listView = new PhaserListView.ListView(game, this, bounds, options);

	var newItem = game.add.group(this);
	listView.addMultiple(sprites);
	newItem.nominalHeight = 120;

	listView.add(newItem);

This is actually taken from the example, but the line
listView.addMultiple(sprites);

causes issues: updateTransform of children[i] is not a function. When I add the sprites directly to the group "newItem", then I won't get any error, but therefore I see nothing (I mean, the listview nowhere).

So I ask myself, how to actually do it?

Cant create more the one `listView`

Failing in creating more then one listView

one is running over the other even though im assigning the instances to different
vars and even using different parents on listView constructor

    this.right = {};
    this.left = {};

    renderScroller (x, y, items, obj) {
        const bounds = new Phaser.Rectangle(
            x,
            y,
            500,
            600
        );

        const options = {
            direction: 'y',
            overflow: 100,
            padding: 50
        };

        obj = new ListView(this.game, this, bounds, options);

        obj.scroller.enable();

        obj.addMultiple(...items);

        obj.tweenToItem(0, 2);
    };

   const items = [
           this.game.add.image(0, 0, 'image-name'),
           this.game.add.image(0, 0, 'image-name')
     ];

    // Then calling the above render twice 
   this.renderScroller(100, 500, items, this.left);
   this.renderScroller(500, 500, items, this.right);

// 'this' is a class extending Phase.Group that contains this snippet 

any solution/ walk around??

Thanks

Render ListItem to specific position

Is it possible to render the ListView to be scrolled
to item N of the given list?

for example: I want the list to be focused on item number 26 when showing the first time

Thanks

(listView) onInputDown not dispatched (but maybe solved)

Hi,
fantastic plugin!
But testing it, I found that onInputDown event didn't work in list view (instead onInputUp worked).

In line 19096, there was this line:
this.events.onInputDown.dispatch(target, pointer);

I changed it with:
(0, _util.dispatchClicks)(pointer, this.clickables, 'onInputDown');
this.events.onInputDown.dispatch(target, pointer, _util.dispatchClicks);

and now it works. But I don't know if this change is really correct.

ListView support for Phaser.Group

Most entries for me will be a collection of images and texts so
it would be great if I could enter a list of group objects

thanks

Support for infinite scrolling

It would be very nice to add a configuration option to let culled items appear to the opposite side of the list (i.e., if I have 5 items, scrolling down after the 5th i would see my list restarting from 1st, 2nd, etc...)

Single file on es5

Can you please add it as single file on es5? It will be very helpfull for people who dev on Phonegap/Cordova (like me:))

Click Events doesn't work on elements inside list

Hi
I'm trying to add click event on the item inside list and this event won't fire
my code :

            let parent = modalGroup; //phaser group
            let bounds = new Phaser.Rectangle(10, header.bottom, this.game.world.width - 30, this.game.world.height - 150);
            let options = {
                direction: 'y',
                overflow: 50,
                padding: 10
            }
            let listView = new Scroller.ListView(this.game, parent, bounds, options)
            
            EquimpentSheet.forEach((e, i)=>{
                let bg = this.game.add.graphics(bounds.x, bounds.top + 110 * i);
                bg.beginFill(0xbfbdb3);
                bg.drawRect(0, 0, this.game.world.width - 20, 100);
                bg.anchor.setTo(0.5);
                bg.inputEnabled = true;
                bg.events.onInputDown.add(()=>{
                    this.player.buyItem(e);
                });
                modalGroup.add(bg);
                listView.addMultiple(bg);
                bg.endFill();
            });

Blurred images when using more than one list view

In my project, I need to use more than one list view in a menu scene. But when I instantiate them, all of then but the first one get blurry images. I'm using different arrays to feed them so the sprites doesn't have any kind of interference. Can you help me to fix it? Thanks.

List view not cropped when child of a group

Hi!

I'm using ListView as a child of some group. In this case list view items are not cropped as show in the images. Although items visibility is correctly switched when outside of bounds.

I've checked and cropping works properly when attached to game.world object.

Is it a bug?

image
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.