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

3D: Difference between revisions

From Board Game Arena
Jump to navigation Jump to search
Morgalad (talk | contribs)
No edit summary
No edit summary
 
(12 intermediate revisions by 8 users not shown)
Line 1: Line 1:
{{Studio_Framework_Navigation}}


= Overview =
===Display3D===


Board Game Arena is using CSS 3D features to provide a basic 3D view of the games.
The Display3D class provides a 3D view for one or more HTML elements. It can rotate and move the view, zoom in and out, and optionally let players control the view with the mouse.


This is not a "100% real" 3D as this is very difficult to play with real 3D model with CSS, but most of the time it provides a satisfying 3D view of the game.
The class is available through the BGA game object:


The objective of 3D is to provide a nice view of the game : 90% of the time, 2D is more suitable for playing. So we don't force developers to make sure games can be played in 3D : this is just a "bonus".
'''this.bga.display3D: Display3D;'''


= Enabling 3D =
====Initialize a 3D view====


3D is enabled by default for your game.
'''this.bga.display3D.init3d(settings?: Display3DInitSettings): void;'''


You can click on the "3D" button at the top right and see your game in 3D.
Initializes the 3D view. If `elements` is not specified, the view uses the default game area elements.


If you don't want to allow players to use 3D with your game, you can add this to you "gameinfos.inc.php" file :
The optional `settings` object can contain:


'enable_3d' => false,
* `elements`: an array of `HTMLElement` objects transformed by the 3D view.
* `showControls`: whether to display the legacy 3D controls. The default is `false`.
* `view`: the initial view and optional limits. See [[#View settings|View settings]].
* `draggable`: enables dragging. It can be a boolean, a shared numeric multiplier, or a settings object.
* `zoomByWheel`: enables zooming with the mouse wheel. It can be a boolean, a numeric multiplier, or a settings object.


= Detecting 3D =
Example:
    this.bga.display3D.init3d({
        elements: [document.getElementById("game_play_area")],
        showControls: true,
        view: {
            xAxis: 40,
            zAxis: 0,
            xPos: -100,
            yPos: -50,
            zoom: 1,
            minZoom: 0.5,
            maxZoom: 3,
        },
        draggable: true,
        zoomByWheel: true,
    });


When 3D is "on", BGA adds CSS class "mode_3d" to the body element.
====Elements====


In CSS, you should prefix all your 3D mode specific directives by ".mode_3d".
'''this.bga.display3D.setElements(elements: HTMLElement[]): void;'''


.mode_3d .board {
Replaces the list of elements transformed by the 3D view.
overflow: visible;
}


In Javascript, you can detect 3D by using the following :
'''this.bga.display3D.addElements(elements: HTMLElement[]): void;'''


  if( this.control3dmode3d )
Add elements to the list of elements transformed by the 3D view.
  {
    // Only executed in 3d mode
  }


= Built-in 3D enhancements =
====Changing the view====


BGA is doing some built-in 3D enhancements with your 3D adaptations, so your adaptation will have some 3D effects without any efforts :
'''this.bga.display3D.change3d(xaxis: number, xpos: number, ypos: number, zaxis: number, scale: number): void;'''


* When executing a slideToObject, a slideToObjectPos or a slideTemporaryObject, BGA is moving the objects vertically (up, then down).
Applies relative changes to the current view. The arguments are, in order, X-axis rotation, X-position, Y-position, Z-axis rotation, and zoom changes.
* It also happens when moving elements of a Stock module, or to a Zone module.


'''this.bga.display3D.resetView(): void;'''


= Enhance your adaptation for 3D =
Resets the view to its neutral position while respecting the configured limits.


== Use Z axis ==
'''this.bga.display3D.rotate(x: number, y: number): void;'''


Using CSS transform: translateZ, you can translate your HTML elements along the Z axis. Example :
Applies a relative rotation. `x` changes the X-axis rotation and `y` changes the Z-axis rotation.


  .floating_element {
'''this.bga.display3D.slide(x: number, y: number): void;'''
      transform: translateZ( 20px ); /* This element is going to float 20px above the surface */
  }


The framework will add the following to all your divs:
Applies a relative translation. `x` changes the X position and `y` changes the Y position.
      transform-style: preserve-3d;


So they will keep their position in 3D space relative to other elemens with the transformation defined. Note that some CSS artifacts can break the css inheritance of the "preserve-3d" like "overflow:auto"
'''this.bga.display3D.zoom(inc: number): void;'''


Applies a relative zoom change.


At any moment, you can know the Z position of an element from javascript using :
'''this.bga.display3D.setZoom(value: number): void;'''


  this.getComputedTranslateZ( html_element );
Sets the zoom to an absolute value.


== Use pre-build BGA 3D CSS classes ==
Example:
    this.bga.display3D.rotate(5, 0);
    this.bga.display3D.slide(10, -5);
    this.bga.display3D.zoom(0.1);
    this.bga.display3D.setZoom(1);


By adding the following classes to your objects, they will look nicer in 3D:
====Mouse controls====


* thickness: add a (3px) black thickness to your HTML element.
'''this.bga.display3D.setDraggable(enabled?: boolean | number | Display3DDraggableSettings, settings?: number | Display3DDraggableSettings): void;'''
 
* roundthickness: (to be used with thickness) if your element is a circle, you should add roundthickness so your element thickness can be a circle too.
 
* whitethickness: (to be used with thickness) if you prefer to have a whitethickness instead of black.
 
* floatingabove: make your element "float" 10px above the surface, with a nice shadow.
 
* roundfloatingabove: (to be used with floatingabove) if your element is a circle, use roundfloatingabove in addition to floatingabove.


Enables or disables mouse dragging. Right-button dragging rotates the view and middle-button dragging slides the view.


Note: if you found some generic CSS that may help some other developers for 3D enhancements, please send it to us so we can add it there.
The first argument can be a boolean, a shared multiplier, or an object with these properties:


* `enabled`: whether dragging is enabled. The default is `true` when using the object form.
* `multiplier`: shared rotation and slide multiplier.
* `rotationMultiplier`: right-button rotation multiplier. The default is `0.1`.
* `slideMultiplier`: middle-button slide multiplier. The default is `1`.


== Setting the default point of view and enabling 3d by default ==
The second argument can provide the settings object or a shared numeric multiplier.


Your game may require to use 3D mode enabled by default and also with a certain custom default PoinOfView. You can achieve this setting in your constructor section of your game:
Examples:
    this.bga.display3D.setDraggable(true);
    this.bga.display3D.setDraggable(false);
    this.bga.display3D.setDraggable({
        rotationMultiplier: 0.1,
        slideMultiplier: 1,
    });


'''this.bga.display3D.setZoomByWheel(enabled?: boolean | number | Display3DZoomByWheelSettings, settings?: number | Display3DZoomByWheelSettings): void;'''


        if (!dojo.hasClass("ebd-body", "mode_3d")) {
Enables or disables mouse-wheel zooming.
            dojo.addClass("ebd-body", "mode_3d");
 
            dojo.addClass("ebd-body", "enableTransitions");
The first argument can be a boolean, a zoom multiplier, or an object with these properties:
    $("globalaction_3d").innerHTML = "2D";   // controls the upper right button
 
    this.control3dxaxis = 30;  // rotation in degrees of x axis (it has a limit of 0 to 80 degrees in the frameword so users cannot turn it upsidedown)
* `enabled`: whether wheel zoom is enabled. The default is `true` when using the object form.
    this.control3dzaxis = 0;   // rotation in degrees of z axis
* `multiplier`: wheel zoom multiplier. The default is `0.1`.
    this.control3dxpos = 100;   // center of screen in pixels
* `zoomMultiplier`: alias for `multiplier`, also defaulting to `0.1`.
        this.control3dypos = 300;   // center of screen in pixels
 
this.control3dscale = 1.4;   // zoom level, 1 is default 2 is double normal size,
The second argument can provide the settings object or a numeric multiplier.
this.control3dmode3d = true ; // is the 3d enabled
 
  $("game_play_area").style.transform = "rotatex(" + this.control3dxaxis + "deg) translate(" + this.control3dypos + "px," + this.control3dxpos + "px) rotateZ(" + this.control3dzaxis + "deg) scale3d(" + this.control3dscale + "," + this.control3dscale + "," + this.control3dscale + ")";
Example:
}
    this.bga.display3D.setZoomByWheel({
        multiplier: 0.1,
    });
 
====View settings====
 
The `view` object passed to `init3d` can set the initial view and its limits. All properties are optional:
 
* `xAxis`, `minXAxis`, `maxXAxis`: X-axis rotation and its limits.
* `zAxis`, `minZAxis`, `maxZAxis`: Z-axis rotation and its limits.
* `xPos`, `minXPos`, `maxXPos`: X position and its limits.
* `yPos`, `minYPos`, `maxYPos`: Y position and its limits.
* `zoom`, `minZoom`, `maxZoom`: zoom and its limits.
 
====Changing view limits====
 
Each limit method sets one limit. Passing `null` clears that limit.
 
'''this.bga.display3D.setMinXAxis(value?: number | null): void;'''
 
'''this.bga.display3D.setMaxXAxis(value?: number | null): void;'''
 
'''this.bga.display3D.setMinZAxis(value?: number | null): void;'''
 
'''this.bga.display3D.setMaxZAxis(value?: number | null): void;'''
 
'''this.bga.display3D.setMinXPos(value?: number | null): void;'''
 
'''this.bga.display3D.setMaxXPos(value?: number | null): void;'''
 
'''this.bga.display3D.setMinYPos(value?: number | null): void;'''
 
'''this.bga.display3D.setMaxYPos(value?: number | null): void;'''
 
'''this.bga.display3D.setMinZoom(value?: number | null): void;'''
 
'''this.bga.display3D.setMaxZoom(value?: number | null): void;'''
 
Example:
    this.bga.display3D.setMinZoom(0.5);
    this.bga.display3D.setMaxZoom(3);
    this.bga.display3D.setMaxZoom(null); // Remove the maximum zoom limit
 
 
[[Category:Studio]]

Latest revision as of 08:04, 13 July 2026


Game File Reference



Useful Components

Official

  • ItemManager: a PHP component to manage cards or other game items.
  • PlayerCounter and TableCounter: PHP components to manage counters.
  • 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).
  • 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).
  • bga-zoom : a JS component for zoom controls.
  • bga-animations : a JS component for animations.
  • bga-cards : a JS component for cards.
  • bga-dice : a JS component for dice.
  • bga-autofit : a JS component to make text fit on a fixed size div.
  • bga-score-sheet : a JS component to help you display an animated score sheet at the end of the game.
  • bga-jump-to : a JS component to add board shortcuts

Deprecated

  • Deck: a PHP component to manage cards (deck, hands, picking cards, moving cards, shuffle deck, ...).
  • Stock: a JS component to manage and display a set of game elements displayed at a position.

Unofficial



Game Development Process



Guides for Common Topics



Miscellaneous Resources

Display3D

The Display3D class provides a 3D view for one or more HTML elements. It can rotate and move the view, zoom in and out, and optionally let players control the view with the mouse.

The class is available through the BGA game object:

this.bga.display3D: Display3D;

Initialize a 3D view

this.bga.display3D.init3d(settings?: Display3DInitSettings): void;

Initializes the 3D view. If `elements` is not specified, the view uses the default game area elements.

The optional `settings` object can contain:

  • `elements`: an array of `HTMLElement` objects transformed by the 3D view.
  • `showControls`: whether to display the legacy 3D controls. The default is `false`.
  • `view`: the initial view and optional limits. See View settings.
  • `draggable`: enables dragging. It can be a boolean, a shared numeric multiplier, or a settings object.
  • `zoomByWheel`: enables zooming with the mouse wheel. It can be a boolean, a numeric multiplier, or a settings object.

Example:

    this.bga.display3D.init3d({
        elements: [document.getElementById("game_play_area")],
        showControls: true,
        view: {
            xAxis: 40,
            zAxis: 0,
            xPos: -100,
            yPos: -50,
            zoom: 1,
            minZoom: 0.5,
            maxZoom: 3,
        },
        draggable: true,
        zoomByWheel: true,
    });

Elements

this.bga.display3D.setElements(elements: HTMLElement[]): void;

Replaces the list of elements transformed by the 3D view.

this.bga.display3D.addElements(elements: HTMLElement[]): void;

Add elements to the list of elements transformed by the 3D view.

Changing the view

this.bga.display3D.change3d(xaxis: number, xpos: number, ypos: number, zaxis: number, scale: number): void;

Applies relative changes to the current view. The arguments are, in order, X-axis rotation, X-position, Y-position, Z-axis rotation, and zoom changes.

this.bga.display3D.resetView(): void;

Resets the view to its neutral position while respecting the configured limits.

this.bga.display3D.rotate(x: number, y: number): void;

Applies a relative rotation. `x` changes the X-axis rotation and `y` changes the Z-axis rotation.

this.bga.display3D.slide(x: number, y: number): void;

Applies a relative translation. `x` changes the X position and `y` changes the Y position.

this.bga.display3D.zoom(inc: number): void;

Applies a relative zoom change.

this.bga.display3D.setZoom(value: number): void;

Sets the zoom to an absolute value.

Example:

    this.bga.display3D.rotate(5, 0);
    this.bga.display3D.slide(10, -5);
    this.bga.display3D.zoom(0.1);
    this.bga.display3D.setZoom(1);

Mouse controls

this.bga.display3D.setDraggable(enabled?: boolean | number | Display3DDraggableSettings, settings?: number | Display3DDraggableSettings): void;

Enables or disables mouse dragging. Right-button dragging rotates the view and middle-button dragging slides the view.

The first argument can be a boolean, a shared multiplier, or an object with these properties:

  • `enabled`: whether dragging is enabled. The default is `true` when using the object form.
  • `multiplier`: shared rotation and slide multiplier.
  • `rotationMultiplier`: right-button rotation multiplier. The default is `0.1`.
  • `slideMultiplier`: middle-button slide multiplier. The default is `1`.

The second argument can provide the settings object or a shared numeric multiplier.

Examples:

    this.bga.display3D.setDraggable(true);
    this.bga.display3D.setDraggable(false);
    this.bga.display3D.setDraggable({
        rotationMultiplier: 0.1,
        slideMultiplier: 1,
    });

this.bga.display3D.setZoomByWheel(enabled?: boolean | number | Display3DZoomByWheelSettings, settings?: number | Display3DZoomByWheelSettings): void;

Enables or disables mouse-wheel zooming.

The first argument can be a boolean, a zoom multiplier, or an object with these properties:

  • `enabled`: whether wheel zoom is enabled. The default is `true` when using the object form.
  • `multiplier`: wheel zoom multiplier. The default is `0.1`.
  • `zoomMultiplier`: alias for `multiplier`, also defaulting to `0.1`.

The second argument can provide the settings object or a numeric multiplier.

Example:

    this.bga.display3D.setZoomByWheel({
        multiplier: 0.1,
    });

View settings

The `view` object passed to `init3d` can set the initial view and its limits. All properties are optional:

  • `xAxis`, `minXAxis`, `maxXAxis`: X-axis rotation and its limits.
  • `zAxis`, `minZAxis`, `maxZAxis`: Z-axis rotation and its limits.
  • `xPos`, `minXPos`, `maxXPos`: X position and its limits.
  • `yPos`, `minYPos`, `maxYPos`: Y position and its limits.
  • `zoom`, `minZoom`, `maxZoom`: zoom and its limits.

Changing view limits

Each limit method sets one limit. Passing `null` clears that limit.

this.bga.display3D.setMinXAxis(value?: number | null): void;

this.bga.display3D.setMaxXAxis(value?: number | null): void;

this.bga.display3D.setMinZAxis(value?: number | null): void;

this.bga.display3D.setMaxZAxis(value?: number | null): void;

this.bga.display3D.setMinXPos(value?: number | null): void;

this.bga.display3D.setMaxXPos(value?: number | null): void;

this.bga.display3D.setMinYPos(value?: number | null): void;

this.bga.display3D.setMaxYPos(value?: number | null): void;

this.bga.display3D.setMinZoom(value?: number | null): void;

this.bga.display3D.setMaxZoom(value?: number | null): void;

Example:

    this.bga.display3D.setMinZoom(0.5);
    this.bga.display3D.setMaxZoom(3);
    this.bga.display3D.setMaxZoom(null); // Remove the maximum zoom limit