2011-11-13 56 views
1

我對Qt還很陌生,我想在遊戲中添加高分系統。我發現這個文件http://grip.espace-win.net/doc/apps/qt4/html/demos-declarative-snake-content-highscoremodel-qml.html這是一個高分模型qml元素。我已經將它添加到了我的項目中,但是我對如何實施它卻一無所知。我只想知道當我的窗口進入某個特定狀態時,我可以如何使用它來顯示高分表。我還想知道如何添加分數並在遊戲重新啓動時關閉它。這看起來很愚蠢,但我真的無法弄清楚如何使用它。Qt高分系統

回答

2

從上面的鏈接文件:

使用這個組件是這樣的:

HighScoreModel { 
    id: highScores 
    game: "MyCoolGame" 
} 

則...使用的視圖模型:

ListView { 
    model: highScores 
    delegate: Component { 
    ... player ... score ... 
    } 
} 

所以通過稍微改變QML ListView docs中給出的兩個示例中較簡單的一個,我們得到:

import QtQuick 1.0 

ListView { 
    width: 180; height: 200 
    model: highScores {} 
    delegate: Text { 
    text: player + ": " + score 
    } 
} 

雖然如果要在列表中的每個元素的格式的進一步控制,通過在實施例中使用的delegate: Component在文檔顯示從HighScoreModel.qml,第二使用示例上面引述的建議你怎麼。

+0

「這意味着你將需要遠程SQL服務器「 可以?我很確定它使用自己的本地SQL數據庫。您當然不必運行數據庫來運行Snake示例(並記錄高分)。 – sepp2k

+0

@ sepp2k:我的壞 - 沒有閱讀[this](http://doc.qt.nokia.com/4.7-snapshot/qdeclarativeglobalobject.html#offline-storage-api)。 – sjwarner

+0

我不明白如何實現列表視圖部分 – Gerharddc

0

您還可以看看基於qt的應用程序和遊戲的V-Play引擎。它配備了許多組件,可以使移動開發更加輕鬆。

您也可以排行榜和用戶配置文件添加到您的應用程序的幾行代碼:

import VPlay 2.0 
import VPlayApps 1.0 
import QtQuick 2.9 

App { 

// app navigation 
Navigation { 
    NavigationItem { 
    title: "User Profile" 
    icon: IconType.user 
    NavigationStack { 
     initialPage: socialView.profilePage 
    } 
    } 

    NavigationItem { 
    title: "Leaderboard" 
    icon: IconType.flagcheckered 
    NavigationStack { 
     initialPage: socialView.leaderboardPage 
    } 
    } 
} 

// service configuration 
VPlayGameNetwork { 
    id: gameNetwork 
    gameId: 285 
    secret: "AmazinglySecureGameSecret" 

    // increase leaderboard score by 1 for each app start 
    Component.onCompleted: gameNetwork.reportRelativeScore(1) 
} 

// social view setup 
SocialView { 
    id: socialView 
    gameNetworkItem: gameNetwork 
    multiplayerItem: multiplayer 
    visible: false // we show the view pages on our custom app navigation 
} 
} 

在這裏看到更多的信息:https://v-play.net/cross-platform-app-development/how-to-add-chat-service-and-cross-platform-leaderboard-with-user-profiles-to-your-ios-or-android-app#add-leaderboard-with-user-profiles