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
53 lines • 2.04 kB
JavaScript
import * as THREE from "three";
import constants from "../constants";
export class TJSPSphere {
/**
* @param game - The game instance
* @param options - Initialization options for the sphere (width, height, color)
* @description Creates a sphere in the game scene with the specified width, height, and color.
* If no options are provided, default values from constants are used.
* The sphere is created with a double-sided material.
*/
constructor(game, options = {}) {
this.name = "TJSSphere";
this.game = game;
const defaultSphereOptions = constants.sphere;
const radius = (options === null || options === void 0 ? void 0 : options.radius) || defaultSphereOptions.radius;
const color = (options === null || options === void 0 ? void 0 : options.color) || defaultSphereOptions.color;
// Create a sphere geometry and material
this.geometry = new THREE.SphereGeometry(radius);
this.material = (options === null || options === void 0 ? void 0 : options.material) || new THREE.MeshBasicMaterial({ color });
// Create the mesh and add it to the scene
this.mesh = new THREE.Mesh(this.geometry, this.material);
}
/**
*
* @description Creates a sphere in the game scene with the specified width, height, and color.
*/
start() {
if (this.game) {
this.game.scene.add(this.mesh);
}
else {
console.warn("game is undefined in:", this.name);
}
}
update(dt) {
// Method not implemented.
}
end() {
if (this.mesh) {
this.game.scene.remove(this.mesh);
this.mesh.geometry.dispose();
if (Array.isArray(this.mesh.material)) {
this.mesh.material.forEach((material) => {
material.dispose();
});
}
else {
this.mesh.material.dispose();
}
}
}
}
//# sourceMappingURL=TJSSphere.js.map