所以我想检查节点是否在一定范围内,如果有,请绘制它们。 在计时器内部检查节点,因此创建了线程。现在唯一的问题是必须从UI线程调用方法setRenderable()。那么有办法绕过它吗?我需要在一定间隔内进行更新,这就是为什么我创建计时器的原因。
public void updateNodes()
{
Camera camera = arFragment.getArSceneView().getScene().getCamera();
timer = new Timer();
timer.schedule(new TimerTask(){
int last = 0;
int copy_last = 0;
@Override
public void run(){
Vector3 camera_position = camera.getWorldPosition();
// We're checking all nodes for distance between them
for(Node al : copied_nodes_list){
if(last<copy_last) last++;
else if(countDistanceOfNodes(al,camera_position)<3.0 && copy_last >= last) {
al.setRenderable(andyRenderable);
last++;
copy_last = last;
}
else {
al.setRenderable(andyRenderable);
}
}
last = 0;
}
},0,250);
}
答案 0 :(得分:0)
答案 1 :(得分:0)
好的,所以android中有一个名为runOnUiThread();的函数。基本上,这就是所谓的。我附上工作代码。
public void updateNodes()
{
Camera camera = arFragment.getArSceneView().getScene().getCamera();
Timer timer = new Timer();
timer.schedule(new TimerTask(){
int last = 0;
int copy_last = 0;
@Override
public void run(){
Vector3 camera_position = camera.getWorldPosition();
// We're checking all nodes for distance between them
for(Node al : copied_nodes_list){
camera_position = camera.getWorldPosition();
if(last<copy_last) last++;
else if(countDistanceOfNodes(al,camera_position)<3.0 && copy_last >= last) {
runOnUiThread(new Runnable(){
@Override
public void run(){
al.setRenderable(andyRenderable);
}
});
last++;
copy_last = last;
}
else {
runOnUiThread(new Runnable(){
@Override
public void run(){
al.setRenderable(null);
}
});
}
}
last = 0;
}
},0,100);
}