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

Scrollmap: Perbedaan antara revisi

Dari Board Game Arena
Loncat ke navigasi Loncat ke pencarian
Baris 79: Baris 79:
     text-align: center;
     text-align: center;
}
}
/** 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;
}
</pre>
</pre>



Revisi per 20 April 2013 17.06

Scrollmap is a BGA client side component to display an infinite game area.

In some games, players are building the main game area with tiles or cards. Examples:

  • Carcassonne
  • Saboteur
  • Takenoko
  • Taluva
  • ...

Of course this cause 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 in action

If you want to see how Scrollmap looks like, please try "Saboteur" or "Takenoko" games on BGA, or watch a game in progress.

In both 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 drag'n'drop the game area to scroll.

How to use Scrollmap

At first, 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>
        <a id="movetop" href="#"></a>
        <a id="moveleft" href="#"></a>
        <a id="moveright" href="#"></a>
        <a id="movedown" href="#"></a>
    </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;
}

/** 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;
}

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 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 2 - and only 2 - places where you should place your HTML stuff 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 drag'n'drop the game area, 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 to drag'n'drop the game area 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.

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.