Reputation: 554
First post here on stack overflow...
I've been playing around with the three.js based world editor called verold. It has some great features, but I've run into a problem with the scripting setup.
I'm trying to implement a THREE.Sprite() and attach it as a component of an object.
Here's what I've tried:
Component.prototype.objectCreated = function() {
// this.getThreeData() is available
this.spriteimage.load({
load:_.bind(function() {
this.createImageSprite();
}, this)
});
};
Component.prototype.createImageSprite = function(){
//Load the spriteimage
var map = this.spriteimage.threeData;
var spriteMaterial = new THREE.SpriteMaterial( { map: map, color: "rgb(255,0,0)", fog: true, useScreenCoordinates: false} );
var mySprite = new THREE.Sprite( spriteMaterial );
mySprite.scale.set(1,1,1);
mySprite.location.x = 0.5;
mySprite.location.y = 0.5;
mySprite.location.y = 0.5;
scene.add(mySprite);
};
The script has an attribute called spriteimage, which is a verold asset -> 2D texture.
When this script is added as a component of the scene, the project runs, but you can't see a sprite at all.
I've tried replicating this code in a regular three.js project with success.
Can anybody offer a solution to this?
thanks.
Upvotes: 2
Views: 98
Reputation: 81
There are a couple of minor issues with your code. Otherwise, it works fine.
First, mySprite.location
should be mySprite.position
. Perhaps an earlier version of Three.JS used 'location'?
The second issue is the reference to 'scene' is not defined. In a script, you can call 'this.getThreeScene()' to return the reference to the THREE.Scene that the object that this script is attached to is part of.
Upvotes: 2