我有一個winJS應用程序是一個蒸汽遊戲的工作發射器。即使沒有運行,我也想讓它循環播放5張圖片。在活動瓷磚中騎自行車的圖像
它使用只有小瓷磚 - 這個應用程序沒有寬的瓷磚圖像。
下面的代碼:
(function() {
"use strict";
WinJS.Namespace.define("Steam", {
launch: function launch(url) {
var uri = new Windows.Foundation.Uri(url);
Windows.System.Launcher.launchUriAsync(uri).then(
function (success) {
if (success) {
// File launched
window.close();
} else {
// File launch failed
}
}
);
}
});
WinJS.Namespace.define("Tile", {
enqueue: function initialize() {
var updaterHandle = Windows.UI.Notifications.TileUpdateManager.createTileUpdaterForApplication();
updaterHandle.enableNotificationQueue(true);
return updaterHandle;
},
update: function update() {
var template = Windows.UI.Notifications.TileTemplateType.tileSquareImage;
var tileXml = Windows.UI.Notifications.TileUpdateManager.getTemplateContent(template);
var randIndx = Math.floor(Math.random() * 5);
var randUpdatetime = 1000 * 3 * (((randIndx == 0) ? 1 : 0) + 1); // let the base image stay longer
var tileImageAttributes = tileXml.getElementsByTagName("image");
tileImageAttributes[0].setAttribute("src", "ms-appx:///images/Borderlands2/borderlands_2_" + randIndx + "_sidyseven.png");
tileImageAttributes[0].setAttribute("alt", "Borderlands 2");
var tileNotification = new Windows.UI.Notifications.TileNotification(tileXml);
var currentTime = new Date();
tileNotification.expirationTime = new Date(currentTime.getTime() + randUpdatetime);
tileNotification.tag = "newTile";
var updater = Tile.enqueue();
updater.update(tileNotification);
setTimeout('Tile.update();', randUpdatetime);
}
});
WinJS.Binding.optimizeBindingReferences = true;
var app = WinJS.Application;
var activation = Windows.ApplicationModel.Activation;
app.onactivated = function (args) {
if (args.detail.kind === activation.ActivationKind.launch) {
setTimeout('Steam.launch("steam://rungameid/49520");', 800);
args.setPromise(WinJS.UI.processAll().then(function() {
return WinJS.Navigation.navigate("/default.html", args).then(function() {
Tile.update();
});
}));
}
};
app.start();
})();
注:
的代碼目前不循環的形象,而不是要麼 顯然並沒有發生變化,或發射後更換應用 名帶有默認圖像的小視圖的文本。這會在短時間後恢復爲 文本,並且循環可能會重複。它從不顯示 不同的圖像(既不在它錯誤顯示的小圖像中,也不在主要圖塊中顯示 )。
當我在調試運行,並在
TileUpdater.update(TileNotification)
階段設置斷點,我可以在圖像SRC屬性被設置爲隨機圖像 就像我想要的 控制檯驗證:>>>>tileNotification.content.getElementsByTagName("image")[0].getAttribute("src")
"ms-appx:///images/Borderlands2/borderlands_2_4_sidyseven.png"
但這從來沒有真正顯示在瓷磚上。
這些圖像文件包含在解決方案中,它們出現在解決方案資源管理器的正確目錄中。
很長一段時間沒有得到,實際上涉及到Visual Studio 2012的答案 - 我甚至提出這個賞金。有人回答說,誰擁有visual studio 2012/win8! –