This is a documentation for Board Game Arena: play board games online !
Scrollmap: Skirtumas tarp puslapio versijų
No edit summary |
|||
38 eilutė: | 38 eilutė: | ||
this.scrollmap = new ebg.scrollmap(); | this.scrollmap = new ebg.scrollmap(); | ||
</pre> | </pre> | ||
Now, open your template (TPL) file and add this HTML code: | |||
<pre> | |||
<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> | |||
</pre> | |||
Finally, to link your HTML code with your Javascript, place this in your Javascript "Setup" method: | |||
<pre> | |||
// Make map scrollable | |||
this.scrollmap.create( $('map_container'),$('map_scrollable'),$('map_surface'),$('map_scrollable_oversurface') ); | |||
this.scrollmap.setupOnScreenArrows( 150 ); | |||
</pre> | |||
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. | |||
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. |
13:54, 8 balandžio 2013 versija
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>
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.
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.