Created
October 17, 2018 21:11
-
-
Save RobotGrrl/5a5d1ddaa3378529f6da9907ee8086f0 to your computer and use it in GitHub Desktop.
Aframe register component question
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AFRAME.registerComponent('voxelarena', { | |
init: function () { | |
var parentEl = this.el; | |
var col_ind = 0; | |
var row_ind = 0; | |
var num_tiles = 0; | |
setInterval(function () { | |
if(num_tiles >= 7*7) return; | |
var childEl = document.createElement('a-entity'); | |
childEl.setAttribute('mixin', 'voxel'); | |
childEl.setAttribute('position', {x: col_ind+x_pos, y: 0, z: row_ind+z_pos}); | |
childEl.setAttribute('changecolour', {tileindex: num_tiles}); | |
parentEl.appendChild(childEl); | |
col_ind++; | |
if(col_ind >= 7) { | |
row_ind++; | |
col_ind = 0; | |
} | |
if(col_ind >= 7) { | |
row_ind = 0; | |
} | |
num_tiles++; | |
}, 50); | |
} | |
}); | |
AFRAME.registerComponent('changecolour', { | |
schema: { | |
tileindex: {type: 'number', default: -1} | |
}, | |
init: function () { | |
this.el.setAttribute('material', 'color', '#CC00CC'); | |
console.log(this.data.tileindex); | |
}, | |
tick: function (time, timeDelta) { | |
if(time-last_change >= 100) { | |
if(hue_dir) { | |
hue_val += 10; | |
} else { | |
hue_val -= 10; | |
} | |
if(hue_val < stop_hue) { | |
hue_val = stop_hue; | |
hue_dir = !hue_dir; | |
} else if(hue_val > start_hue) { | |
hue_val = start_hue; | |
hue_dir = !hue_dir; | |
} | |
var hsv = { | |
h: hue_val, | |
s: 100, | |
v: 80 | |
}; | |
var myHsvColor = Color().fromHsv( hsv ); | |
this.el.setAttribute('material', 'color', myHsvColor.toCSS()); | |
console.log("ind = " + this.data.tileindex + " hue = " + hue_val + " time = " + time + " & delta = " + timeDelta); | |
last_change = time; | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment