Start a new topic

Loading multiple targets in a loop with different url

Loading multiple targets in a loop with different url


Hi, I am currently having 20 targets and they all have differnt URL. Following the sample, all of them have to be declared one by one like:

// Create overlay for page one

var imgOne = new AR.ImageResource("assets/imageOne.png");

var overlayOne = new AR.ImageDrawable(imgOne, 1, {

offsetX: -0.15,

offsetY: 0

});

var pageOne = new AR.Trackable2DObject(this.tracker, "pageOne", {

drawables: {

cam: overlayOne

}

});

 

and again we declare

 


// Create overlay for page two

var imgTwo = new AR.ImageResource("assets/imageTwo.png");

var overlayTwo = new AR.ImageDrawable(imgTwo, 0.5, {

offsetX: 0.12,

offsetY: -0.01

});

var pageTwo = new AR.Trackable2DObject(this.tracker, "pageTwo", {

drawables: {

cam: overlayTwo

}

});

 

I want to put them in a loop instead. I found another thread having similar problem, and the solution is:

 


loop(condition){

new AR.Trackable2DObject(this.tracker, "targetName", {

drawables: {

cam: new AR.ImageDrawable(new AR.ImageResource("assets/targetImage.png"), 1, {

offsetX: -0.15,

offsetY: 0

})

}

});

}

 

But my overlay is html with URL, so when i tried

 


for(i=0;i<targetList.length;i++){
new AR.Trackable2DObject(this.tracker, targetList, {
drawables: {
cam:
}
});




 

all target in the list can be recognized with the correct overlay. but when i click the overlay, all of them leads to the same URL, which is the last item in the list. I have been trying for few hours T^T
for your kind help please. many thanks!!!!

Hi,

You can work with wildcards to match targets. For that please check the multiple targets sample.

As written in the documentation, the first parameter of the onEnterFieldOfVision is the targetName in case you were using wildcard.

I hope this helps. Should you need anything further, just let me know anytime.

Greetings

Nicola
Login or Signup to post a comment