3js-game-framework
Version:
3js-game-framework is a lightweight and flexible framework designed to streamline the creation of 3D games and interactive applications using Three.js
51 lines • 2.07 kB
JavaScript
import * as THREE from "three";
import constants from "../constants";
export class TJSBox {
/**
* @param game - The game instance
* @param initOptions - Initialization options for the plane
* @param initOptions.width - The width of the plane, default is 10
* @param initOptions.height - The height of the plane, default is 10
* @param initOptions.color - The color of the plane, default is 0x00ff00 (green)
*/
constructor(game, initOptions) {
this.game = game;
this.initOptions = initOptions || {};
}
/**
*
* @param game - The game instance
* @description Creates a plane in the game scene with the specified width, height, and color.
*/
start(game) {
var _a, _b, _c;
this.game = game;
const defaultPlaneOptions = constants.plane;
const width = ((_a = this.initOptions) === null || _a === void 0 ? void 0 : _a.width) || defaultPlaneOptions.width;
const height = ((_b = this.initOptions) === null || _b === void 0 ? void 0 : _b.height) || defaultPlaneOptions.height;
const color = ((_c = this.initOptions) === null || _c === void 0 ? void 0 : _c.color) || defaultPlaneOptions.color;
// Create a plane geometry and material
const geometry = new THREE.BoxGeometry(width, height);
const material = new THREE.MeshBasicMaterial({
color,
side: THREE.DoubleSide,
});
// Create the mesh and add it to the scene
this.mesh = new THREE.Mesh(geometry, material);
this.mesh.rotation.x = -Math.PI / 2; // Rotate to make it horizontal
this.game.scene.add(this.mesh);
this.mesh.position.set(0, 0, 0); // Set the position of the plane
}
update(dt, args) {
// Method not implemented.
}
end() {
if (this.mesh) {
this.game.scene.remove(this.mesh);
this.mesh.geometry.dispose();
this.mesh.material.dispose();
}
this.mesh = undefined;
}
}
//# sourceMappingURL=TJSCube.js.map