Qt高分制

问题描述 投票:1回答:2

我还是Qt的新手,我想为我的游戏增加一个高分系统。我发现这个文件http://grip.espace-win.net/doc/apps/qt4/html/demos-declarative-snake-content-highscoremodel-qml.html这是一个高分模型qml元素。我已将它添加到我的项目中,但我完全失去了如何实现它。我只是想知道当我的窗口进入某个状态时如何使用它来显示高分表。我还想知道如何添加分数并在游戏重启时关闭它。这看起来很傻但我真的无法弄清楚如何使用它。

qt list qml states
2个回答
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
  }
}

虽然如果您想进一步控制列表中每个元素的格式,如上面HighScoreModel.qml引用的示例中使用delegate: Component所示,文档中的第二个用法示例将向您展示如何。


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

© www.soinside.com 2019 - 2024. All rights reserved.