Jump to content

Scrollbar


claire
 Share

Recommended Posts

There isn't one built-in by default, no, but you could easily create one using a Sprite with enableDrag turned on, but lock the drag so it only works vertically (or horizontally if your scroll bar needs to go that way). Then limit the area it can move to a 1px wide Rectangle (the bounds parameter) as tall as you need.

Link to comment
Share on other sites

Is it something like this?
var bg = game.add.sprite(this.game.world.centerX, this.game.world.centerY, 'game-bg').anchor.setTo(0.5, 0.5);bg.draggable = true;

This code is not working. Am I getting this wrong?

 

Is there any way to have a scrollbar exactly like DOM element which have scrollbar at the side and can scroll using mouse?

Link to comment
Share on other sites

  • 8 months later...
  • 11 months later...

I know this is old, but I want to reply to a few of these because I know people are searching. I'm hoping to get an example into the examples area...

 

You want to create a container sprite, not a group.

var containerSprite = game.add.sprite( 0, 0 );var scrollMask = game.add.graphics(0, 0);scrollMask.beginFill(0xffffff);scrollMask.drawRect( yourX, yourY, maskWidth, maskHeight );scrollMask.endFill();containerSprite.mask = scrollMask;// Add your sprites and text to the containerSprite using addChild// You can move the mask, move the container sprite, and move the sprites within the container.

From there, you just need a scrolling control.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...