After seven days of searching for a solution, I am determined to create a simple game by calling for an Object.
My vision is to develop a modular game structure, starting with the scene in the usual way:
main.js:
var scene, controls, camera, renderer;
var SCREEN_WIDTH, SCREEN_HEIGHT;
.....
var customObject;
init();
animate();
function init() {
.....
customObject = new GameElement();
.....
}
function animate() {
.....
}
function render() {
......
}
Next, I introduce my Player.js class:
function GameElement() {
var character;
this.loader = new THREE.JSONLoader();
this.loader.load(
'obj/models/game_model.json',
function ( geometry, materials ) {
var material = new THREE.MultiMaterial( materials );
var character = new THREE.Mesh( geometry, material );
character.position.set(0, 0, 0);
character.castShadow = true;
character.receiveShadow = false;
scene.add( character );
}
);
}
GameElement.prototype.animate = function() {
this.character.rotation.y -= 0.5;
}
In the initial code block, a new object is created:
customObject = new GameElement();
Everything seems to be functioning properly - the model loads, textures load, but there is one hurdle I can't overcome:
Within the Player class, I aim to define the render() and animate() functions for the Player Object, so that when the Player object is invoked in the main file (main.js), it will appear on the scene and animate based on these internal methods.
I am seeking guidance on the correct approach to creating a new Object with all its properties intact. Please assist me with this dilemma.