3DDiceRoller
3DDiceRoller copied to clipboard
trying to use your library in my project. looking for documentation
I have a little javascript app and I want to roll a d20 on screen and specify a predetermined value. is this possible? is there any example code or documentation I could refer to aside from just reading the code directly?
Thanks!
You can specify forced numbers in the notation, 1d20@14
will force a 14. You can specify more than one by using a comma to seperate them: 4d20@1,2,3,4
okay here's what I've got so far, It doesn't work but I want to know if I'm headed in the right direction:
db = new DiceBox();
db.container = document.body;
db.initialize();
db.rollDice('1d20@14');
That's close, but you'll want to use a DiceNotation to parse a string into parts, then use that in your roll.
element_container = $('#container'); //this should be your canvas element
vector2_dimensions = new THREE.Vector2(1024, 768); // this is the size of the initial canvas
notation = new DiceNotation('1d20@14'); //create a new notation object
db = new DiceBox(element_container, vector2_dimensions); // the box needs a canvas and starting bounds
db.initialize();
db.startClickThrow(notation); // throw your dice
db.RollDice()
expects a list of vectors that describe the speed and direction of the throw, this is for synchronization of the physics between players because that list of vectors is sent to each one. Normally these vectors are created by clicking and dragging the mouse on the canvas.
By using db.startClickThrow()
, it generates randomized vectors for a throw as if you had clicked the "Throw" button instead.
@MajorVictory
Thank you for your help, unfortunately I'm not there yet... this is what my project looks like:
import { DiceBox } from './3DDiceRoller-master/includes/DiceBox.js'
import {DiceNotation} from './3DDiceRoller-master/includes/DiceNotation.js';
import {DiceFactory} from './3DDiceRoller-master/includes/DiceFactory.js';
import {DiceRoller} from './3DDiceRoller-master/includes/DiceRoller.js';
//new DiceRoller();
window.DiceBox = DiceBox;
window.DiceNotation = DiceNotation;
//window.DiceFactory = DiceFactory;
let df = new DiceFactory();
//df.setBumpMapping();
window.DiceFactory = df;
window.DiceRoller = {};
window.DiceRoller.DiceFavorites = {};
window.DiceRoller.DiceFavorites.settings = {};
window.DiceRoller.DiceFavorites.settings.sounds = {value: 1};
window.DiceRoller.DiceFavorites.settings.volume = {value: 4};
window.DiceRoller.DiceFavorites.settings.shadows = {value: 0};
window.DiceRoller.DiceFavorites.settings.tally = {value: 0};
let element_container = document.body.firstElementChild; //this should be your canvas element
let vector2_dimensions = new THREE.Vector2(1024, 768); // this is the size of the initial canvas
let notation = new DiceNotation('1d20@14'); //create a new notation object
let db = new DiceBox(element_container, vector2_dimensions); // the box needs a canvas and starting bounds
db.initialize();
db.startClickThrow(notation);
and I'm getting console errors when i try to run this
i feel like I took a wrong turn somewhere.
Just a quick update here. I noticed that you specified 'canvas' when I was just using any old dom element. I've replaced that with a literal