Wikitude 샘플 ImageRecognition/MultipleTargets를 확인하십시오. SDK를 다운로드 할 때 샘플에서 찾을 수 있습니다. 이 코드를 추가하여 샘플을 확장 :
sound1: null,
sound2: null,
loadAudio: function() {
this.sound1 = new AR.Sound("assets/sound1.mp3", {
onLoaded: function() {
// if the sound finished loading
},
onError: function() {
// alert the user that the sound file could not be loaded
},
});
this.sound2 = new AR.Sound("assets/sound2.mp3", {
onLoaded: function() {
// if the sound finished loading
},
onError: function() {
// alert the user that the sound file could not be loaded
},
});
},
는 그 다음 초기화 기능에 loadAudio를 호출합니다.
var World = {
loaded: false,
init: function initFn() {
/* Disable all sensors in "IR-only" Worlds to save performance. If the property is set to true, any geo-related components (such as GeoObjects and ActionRanges) are active. If the property is set to false, any geo-related components will not be visible on the screen, and triggers will not fire.*/
AR.context.services.sensors = false;
this.loadAudio();
this.createOverlays();
},
sound1: null,
sound2: null,
loadAudio: function() {
this.sound1 = new AR.Sound("assets/sound1.mp3", {
onLoaded: function() {
// if the sound finished loading
},
onError: function() {
// alert the user that the sound file could not be loaded
},
});
this.sound2 = new AR.Sound("assets/sound2.mp3", {
onLoaded: function() {
// if the sound finished loading
},
onError: function() {
// alert the user that the sound file could not be loaded
},
});
},
createOverlays: function createOverlaysFn() {
// Initialize Tracker
this.tracker = new AR.Tracker("assets/magazine.wtc", {
onLoaded: this.worldLoaded
});
// 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
},
onEnterFieldOfVision: function() {
if (World.sound2 !== null) {
World.sound1.play();
}
}
});
// 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
},
onEnterFieldOfVision: function() {
if (World.sound2 !== null) {
World.sound2.play();
}
}
});
},
worldLoaded: function worldLoadedFn() {
var cssDivLeft = " style='display: table-cell;vertical-align: middle; text-align: right; width: 50%; padding-right: 15px;'";
var cssDivRight1 = " style='display: table-cell;vertical-align: middle; text-align: left; padding-right: 15px; width: 38px'";
var cssDivRight2 = " style='display: table-cell;vertical-align: middle; text-align: left; padding-right: 15px;'";
document.getElementById('loadingMessage').innerHTML =
"<div" + cssDivLeft + ">Scan Target #1 (surfer) or #2 (biker):</div>" +
"<div" + cssDivRight1 + "><img src='assets/surfer.png'></img></div>" +
"<div" + cssDivRight2 + "><img src='assets/bike.png'></img></div>";
}
};
World.init();
이 (내가 자바에 새로운 오전 코드가 매우 도움이되었다 포함, 매우 U 감사합니다 여기에 전체 소스 코드
: 그런 다음 Trackable2DObject의 onEnterFieldOfVision 기능을 구현 스크립트 구문 :)). 예, 이제는 내가 가지고있는 모든 다른 타겟에 대해 사운드를 재생할 수 있습니다. 한가지 더 묻고 싶습니다. 첫 번째 타겟을 스캔 한 후 다음 타겟으로 이동하면 첫 번째 사운드가 완료되지 않은 경우 두 번째 사운드가 방해를받습니다. 어떻게 이런 일이 일어나지 않도록 할 수 있습니까? onExitFieldOfVision 어쩌면? 하지만 여기서 소리가 나는 물건을 어떻게 불러야합니까? – Sandra
좋아요, onExitFieldOfVIsion과 Sound 객체의 pause() 호출이 훌륭하게 작동했습니다. – Sandra
내가 도울 수있어서 기쁩니다 :) – ChrisE