This is a documentation for Board Game Arena: play board games online !

Scrollmap

From Board Game Arena
Revision as of 02:15, 31 March 2021 by Victoria La (talk | contribs) (update wording to use term Panning intead of drag'n'drop which is not applicable in this case)
Jump to navigation Jump to search


Game File Reference



Useful Components

Official

  • Deck: a PHP component to manage cards (deck, hands, picking cards, moving cards, shuffle deck, ...).
  • Draggable: a JS component to manage drag'n'drop actions.
  • Counter: a JS component to manage a counter that can increase/decrease (ex: player's score).
  • ExpandableSection: a JS component to manage a rectangular block of HTML than can be displayed/hidden.
  • Scrollmap: a JS component to manage a scrollable game area (useful when the game area can be infinite. Examples: Saboteur or Takenoko games).
  • Stock: a JS component to manage and display a set of game elements displayed at a position.
  • Zone: a JS component to manage a zone of the board where several game elements can come and leave, but should be well displayed together (See for example: token's places at Can't Stop).

Undocumented component (if somebody knows please help with docs)

  • Wrapper: a JS component to wrap a <div> element around its child, even if these elements are absolute positioned.

Unofficial



Game Development Process



Guides for Common Topics



Miscellaneous Resources

In some games, players are building the main game area with tiles or cards and it has no boundaries. This causes an additional difficulty for the adaptation, because we have to display an infinite game area into a finite space on the screen. This is where Scrollmap component can help you.

Scrollmap is a BGA client side component to display an infinite game area. It supports Scrolling and Panning. Scrolling - allows user to scroll area inside the view port using the buttons drawn on the top/bottom/left/right. Panning - allows user to drag the surface area (using mouse).


Scrollmap in action

Examples of game that use Scrollmap (try on BGA or watch):

  • Carcassonne
  • Saboteur
  • Takenoko
  • Taluva

In these games, you can see that there are arrow controls around the main game area, so that players can use them to scroll the view. You can also use Panning (i.e drag'n'drop the game area to scroll).

How to use Scrollmap

At first, in the Javascript file, don't forget to add "ebg/scrollmap" as a dependency:

define([
    "dojo","dojo/_base/declare",
    "ebg/core/gamegui",
    "ebg/counter",
    "ebg/scrollmap"     /// <==== HERE
],


Then, declare a new variable in your class for the Scrollmap object:

        constructor: function(){
        console.log('yourgame constructor');
              
        // Scrollable area        	
        this.scrollmap = new ebg.scrollmap();

Now, open your template (TPL) file and add this HTML code:

    <div id="map_container">
    	<div id="map_scrollable"></div>
        <div id="map_surface"></div>
        <div id="map_scrollable_oversurface"></div>

        <div class="movetop"></div> 
	<div class="movedown"></div> 
	<div class="moveleft"></div> 
	<div class="moveright"></div> 
    </div>

There are also some lines to add to your CSS stylesheet. Please note that you can adapt it to your needs, especially the default width of the scrollable area:

/** Scrollable area **/

#map_container {
    position: relative;
    width: 100%;
    height: 400px;
    overflow: hidden;
}
#map_scrollable, #map_scrollable_oversurface {
    position: absolute;
    top: 205px;
    left:  315px;
}
#map_surface {
    position: absolute;
    top: 0px;
    left: 0px;
    width: 100%;
    height: 100%;
    cursor: move;
}
#map_footer {
    text-align: center;
}

Finally, to link your HTML code with your Javascript, place this in your Javascript "Setup" method:

   	// Make map scrollable        	
        this.scrollmap.create( $('map_container'),$('map_scrollable'),$('map_surface'),$('map_scrollable_oversurface') );
        this.scrollmap.setupOnScreenArrows( 150 ); // this will hook buttons to onclick functions with 150px scroll step

This is it! Now, you should see on your game interface a scrollable game area. This is not really impressive though, because you didn't add anything on the game area yet. This is the next step.

Scrollable area layers

There are two and only two places where you should place your elements in your scrollable area:

  • inside "map_scrollable" div
  • inside "map_scrollable_oversurface" div

The difference is very important: "map_scrollable" is beneath the surface that is used to pan scroll ("map_surface"), and "map_scrollable_oversurface" is above this surface. In practice:

  • If some element on the game area need to be clicked (or any kind of user interaction), you should place it in map_scrollable_oversurface, otherwise no click can reach it.
  • If some element on the game area don't need to be clicked, you'd better place it in "map_scrollable", so it is possible pan scroll from a point on this element.

Of course, all layers are scrolled synchronously.

Tips: in some situation, it's also useful to place a game element on map_scrollable and a corresponding invisible element over the surface to manage the interactions. Example: when an interactive element must be placed beneath a non interactive element for display reason.

The other layer is 'map_surface' - it is what user would use to pan scroll. If this div is not visible because 'map_scrollable_oversurface' covering it completely - panning will be possible.


Positioning elements on game area

All elements on the game are must be absolute positioned (with "top" and "left" attributes).

By default, the game area is centered on 0,0 coordinates.

Enable move arrows

To show move arrows icons around the scrollmap in order to enable click based navigation in addition to drag and drop, add these lines to your CSS:

/** Move arrows **/

.movetop,.moveleft,.moveright,.movedown {
    display: block;
    position: absolute;
    background-image: url('../../../img/common/arrows.png');
    width: 32px;
    height: 32px;
}

.movetop {
    top: 0px;
    left: 50%;
    background-position: 0px 32px;
}
.moveleft {
    top: 50%;
    left: 0px;
    background-position: 32px 0px;
}
.moveright {
    top: 50%;
    right: 0px;
    background-position: 0px 0px;
}
.movedown {
    bottom: 0px;
    left: 50%;
    background-position: 32px 32px;
}

The buttons handler already defined in the scrollmap control just make sure you call function setupOnScreenArrows (and in .tpl file buttons have to be defined with exact these classes verbatim)

Enable scrollmap zone extension

This is optional, when there can be unused screen space under the scrollmap that a player might want to use. Add this in your .tpl after the scrollmap div (the matching css rules has already been defined):

<div id="map_footer" class="whiteblock">
    <a href="#" id="enlargedisplay">↓  {LABEL_ENLARGE_DISPLAY}  ↓</a>
</div>

In your javascript, define the following function:

        onIncreaseDisplayHeight: function( evt )
        {
        	console.log( '$$$$ Event : onIncreaseDisplayHeight' );
        	evt.preventDefault();
        	
            var cur_h = toint( dojo.style( $('map_container'), 'height' ) );
            dojo.style( $('map_container'), 'height', ( cur_h+300 ) + 'px' );
        },

and connect them to the 'enlargedisplay' link in your setup:

dojo.connect( $('enlargedisplay'), 'onclick', this, 'onIncreaseDisplayHeight' );

In your view.php file, define the template variable LABEL_ENLARGE_DISPLAY so that it gets substituted with appropriate translatable text:

$this->tpl['LABEL_ENLARGE_DISPLAY'] = self::_("Enlarge display");