1

我刚刚开始学习 Metaio。我正在做一个简单的开发测试项目。

到目前为止,我已经制作了跟踪表,放置图像和两个箭头(按钮),这意味着下一个图像和上一个图像。

为了测试,我制作了一个按钮来显示图像,另一个按钮用于隐藏图像。到目前为止,这一切都很好。

我的问题是当我添加额外的图像时,如何使用我的下一个和上一个按钮动态地前后移动图像?

我的测试代码:

button2.onTouchStarted = function () {
    image1.hide();
};

button1.onTouchStarted = function () {
    image1.display();
};

X 射线

4

1 回答 1

1

它可以通过不同的方式完成,我建议您使用arel.Scene.getObject并将图像名称放入数组中,每次单击下一个或上一个时,您都会向上或向下计数数组键。

我假设您正在使用 Metaio Creator 编辑器。

您必须在 3 个不同的地方添加代码:

上一个(左箭头按钮)

button1.onTouchStarted = function () {  
    if (currentImageIndex == firstImageIndex) {
        return;
    }
    arel.Scene.getObject(imageArray[currentImageIndex]).hide();
    currentImageIndex--;
    arel.Scene.getObject(imageArray[currentImageIndex]).display();
    globalsVar['currentImageIndex'] = currentImageIndex;

};

下一步(右箭头按钮)

button2.onTouchStarted = function () {
    if (currentImageIndex == lastImageIndex) {
        return;
    }
    arel.Scene.getObject(imageArray[currentImageIndex]).hide();
    currentImageIndex++;
    arel.Scene.getObject(imageArray[currentImageIndex]).display();
    globalsVar['currentImageIndex'] = currentImageIndex;
};

在你的全局脚本上

var imageArray = ["image1", "image2"]; // and so on extra image names
var firstImageIndex = 0;
var lastImageIndex = imageArray.length - 1;
var currentImageIndex = firstImageIndex;
globalsVar = {};

arel.Scene.getObject(imageArray[currentImageIndex]).display();
于 2015-10-30T21:11:40.650 回答