LevelStore

Allows to monetize user-generated levels with in-app purchases. More...

Import Statement: import VPlay 2.0
Inherits:

Store

Properties

Signals

Methods

Detailed Description

The LevelStore allows to monetize your user-created levels with in-app purchases. It also allows to award your best level creators to give them an incentive to create good levels.

The LevelStore makes it very easy to connect your level sharing with the LevelEditor component with in-app purchases with these main use cases:

  • Call buyLevel() to purchase & download the level for a player.
  • Call buyCurrencyPack() to let the player buy new playerCredits with the native in-app purchase plugin for iOS & Android by V-Play.
  • To reward your players with new currency, call giveCurrency(). You can reward players for example when they start your game to give an incentive for returning, or if their published level reaches a certain number of downloads. For more details see the V-Play Crash Course Lesson 8 about How to Motivate Players to Create Levels.
  • During development, the functions resetCurrency() and clearAllBoughtLevels() are useful to test the level purchase functionality in your game.

Example Usage

For a tutorial about monetizing user-generated levels see V-Play Crash Course Lesson 8 - How to benefit from user-generated content in your game with V-Play Level Store.

The following example shows a minimal example of the interaction between LevelEditor, LevelStore, a LevelScene and a ShopScene.

import VPlay 2.0

GameWindow {

  Component.onCompleted: {
    // give the player 1 credit every time starting the game to motivate to return
    levelStore.giveCurrency(1)
  }

  // use the LevelEditor to create new levels, save them and later on publish the levels
  // for showing a list of user-generated levels, call loadCommunityLevels()
  LevelEditor {
    id: levelEditor
  }

  LevelStore {
    id: levelStore

    currencies: [
      Currency { id: moneyCurrency; itemId: "currency_money_id"; name: "money"; }
    ]

    currencyPacks: [
      CurrencyPack {
        id: money2Pack
        itemId: "money_pack_2_id"
        name: "2 Coins"
        currencyId: moneyCurrency.itemId
        currencyAmount: 2
        purchaseType:  StorePurchase { id: money2Purchase; productId: money2Pack.itemId; }
      }
      // you can add multiple packs here, e.g. for 5 coins, 10 coins and 50 coins
      // define the € or $ price for them in the Google Play Store Backend or iTunes Connect
    ]

    onInsufficientFundsError: {
      // notify the player he has not enough playerCredits to buy this level and to go to the shop
      nativeUtils.displayMessageBox("Not enough Credits to buy this level", "You do not have enough credits to buy this level. You can go to the shop and purchase more levels.")
    }
  }

  LevelScene {

    onBuyLevelClicked: {

      // the LevelScene contains a list of levels and emits a buyLevelClicked(levelData) signal if one was selected for buying
      // if the player has enough playerCredits, the level is purchased (levelBoughtSuccessfully() is emitted) and downloaded (levelDownloadedSuccessfully() is emitted)
      // if he has not enough playerCredits, insufficientFundsError() is emitted in LevelStore
      levelStore.buyLevel(levelData)
    }
  }

  ShopScene {

    Text {
      // in the ShopScene, show the current credits of the player
      text: "Current Credits: " + levelStore.playerCredits
    }

    onPurchaseCurrencyPack: {

      // the ShopScene contains a list of all currencyPacks with a button to buy a Package
      // in this example we only have 1 pack which will increase the playerCredits by 2 after the purchase
      // you can set the amount of € or $ how much this currencyPack should cost in Google Play or iTunes Connect (see the Store plugin for more details)
      levelStore.buyCurrencyPack(money2Pack.itemId)
    }

    // ... shop UI
  }

  // required for user-generated levels
  VPlayGameNetwork {
    id: gameNetwork
  }

  // ... other scenes like the GameScene or OptionsScene

}

A full example game with a LevelStore, LevelEditor, VPlayGameNetwork, ShopScene & LevelScene is available in the Stack With Friends Demo.

It contains a LevelStore implementation with a shop UI shown in this image:

The level selection in Stack With Friends Demo looks like that:

Dependencies & Build Server Usage

The LevelStore requires a LevelEditor in your game - set it with the levelEditorItem property.

The LevelStore is an extended component of the Store plugin for in-app purchases. In addition to the Store functionality, it adds the possibilty to monetize user-generated levels with in-app purchases with the extended functions buyLevel(), giveCurrency(), resetCurrency() and clearAllBoughtLevels(). To use the LevelStore with V-Play Build Server, add the following line to your config.json file:

"plugins": [ "store" ]

Testing the LevelStore

For testing the LevelStore on your iOS or Android devices with V-Play Build Server, see the section Set-up & Test In-App Purchases in the Soomla Plugin.

Testing on desktop platforms works with all functions fully supported. Also, the LevelStore persistently saves the playerCredits the user had at exiting the app. The only limitiation on desktop is the following: A call of buyCurrencyPack() increases the playerCredits without real billing as it is done on iOS or Android, because there is no App Store on desktop. Thus to simulate a call of onInsufficientFundsError, you would need to call it yourself.

Property Documentation

costPerLevel : int

The default price for a level. If playerCredits is >= costPerLevel then a call of buyLevel() will succeed, otherwise onInsufficientFundsError will be called.

The default value is 1.

To set a custom price per level, add a price key to the LevelData::levelMetaData.

See also playerCredits and buyLevel().


levelEditorItem : variant

Set this property to the id of LevelEditor.

By default, it will be set to the id levelEditor if one is found in the main qml file, or it is undefined if no such id is found.

Note: It is required that a LevelEditor component exists for the LevelStore component so buyLevel() works.

This is an example how to use it in your main qml file:

import VPlay 2.0

GameWindow {

  LevelStore {
    id: levelStore

    levelEditorItem: myLevelEditor
  }

  LevelEditor {
    id: myLevelEditor
  }

  // ... Scenes, VPlayGameNetwork and other items
}

playerCredits : int

This read-only property contains the player's credits of the currency entered in Store::currencies.

You can increase playerCredits by calling giveCurrency() or buyCurrencyPack(). The playerCredits decrease by calling buyLevel(). To set the playerCredits to 0 call resetCurrency().

Internally, it is bound to the Currency::balance property of the Store plugin.

Use this property for example to display the current player credits in a Text element:

Text {
  // in the ShopScene, show the current credits of the player
  text: "Current Credits: " + levelStore.playerCredits
}

See also Store::insufficientFundsError, buyLevel(), buyCurrencyPack(), giveCurrency(), and resetCurrency().


Signal Documentation

levelBoughtSuccessfully(variant levelData)

This handler is called after a successful purchase with buyLevel(). For a successful purchase, the playerCredits must be >= costPerLevel.

After onLevelBoughtSuccessfully was called, either onLevelDownloadedSuccessfully or onLevelDownloadedError will be called.


levelDownloadedError(variant levelData, variant errorData)

This handler is called after buyLevel() and then onLevelBoughtSuccessfully was called and the level then could not be downloaded to LevelEditor::downloadedLevels.

This might happen if the internet connection got lost after the level purchase. So you can notify the user to check the internet connection if this handler is called. The level will be tried to re-download again after the app is closed and then started again.

See also levelDownloadedSuccessfully.


levelDownloadedSuccessfully(variant levelData)

This handler is called after buyLevel() and then onLevelBoughtSuccessfully was called and the level then got successfully downloaded to LevelEditor::downloadedLevels.

You can notify the user after the level was downloaded that it is now available offline and the purchase was successful.

See also levelDownloadedError.


Method Documentation

buyCurrencyPack( currencyPackItemId)

Purchase new playerCredits with the native in-app purchase dialog for iOS or Android.

On desktop platforms this call will increase the playerCredits without any payment processing, because there is no App Store available.

The currencyPackItemId is the string value of your Store::currencyPacks itemId. See the following example how to use this function:

import VPlay 2.0

GameWindow {

  LevelStore {
    id: levelStore

    currencies: [
      Currency { id: moneyCurrency; itemId: "currency_money_id"; name: "money"; }
    ]

    currencyPacks: [
      CurrencyPack {
        id: money2Pack
        itemId: "money_pack_2_id"
        name: "2 Coins"
        currencyId: moneyCurrency.itemId
        currencyAmount: 2
        purchaseType:  StorePurchase { id: money2Purchase; productId: money2Pack.itemId; }
      }
      // you can add multiple packs here, e.g. for 5 coins, 10 coins and 50 coins; define the € or $ price for them in the Google Play Store Backend or iTunes Connect
    ]

    onInsufficientFundsError: {
      // notify the player he has not enough playerCredits to buy this level and to go to the shop
      nativeUtils.displayMessageBox("Not enough Credits to buy this level", "You do not have enough credits to buy this level. You can go to the shop and purchase more levels.")
    }
  }

  ShopScene {

    onPurchaseCurrencyPack: {

      // the ShopScene contains a list of all currencyPacks with a button to buy a Package
      // in this example we only have 1 pack which will increase the playerCredits by 2 after the purchase
      // you can set the amount of € or $ how much this currencyPack should cost in Google Play or iTunes Connect (see the Store plugin for more details)
      levelStore.buyCurrencyPack(money2Pack.itemId)
    }
  }

  // ... other items like LevelEditor & VPlayGameNetwork + other scenes like GameScene or OptionsScene

}

buyLevel( levelData)

Starts a purchase of the provided levelData. If levelData contains a price key in the JSON map, this price will be deduced from the playerCredits. If no price is entered per level, the default costPerLevel is used.

If playerCredits are greater than the level price, the purchase will be successful and a onLevelBoughtSuccessfully is emitted followed by a onLevelDownloadedSuccessfully or onLevelDownloadedError. If the playerCredits are lower than the level price onInsufficientFundsError is called.

The levelData originates from your LevelSelectionList. This is where you show the available levels in your game. This is an example how to call this function from a LevelSelectionList:

import VPlay 2.0

GameWindow {

  LevelStore {
    id: levelStore

    currencies: [
      Currency { id: moneyCurrency; itemId: "currency_money_id"; name: "money"; }
    ]

    currencyPacks: [
      CurrencyPack {
        id: money2Pack
        itemId: "money_pack_2_id"
        name: "2 Coins"
        currencyId: moneyCurrency.itemId
        currencyAmount: 2
        purchaseType:  StorePurchase { id: money2Purchase; productId: money2Pack.itemId; }
      }
      // you can add multiple packs here, e.g. for 5 coins, 10 coins and 50 coins
      // define the € or $ price for them in the Google Play Store Backend or iTunes Connect
    ]

    onInsufficientFundsError: {
      // notify the player he has not enough playerCredits to buy this level and to go to the shop
      nativeUtils.displayMessageBox("Not enough Credits to buy this level", "You do not have enough credits to buy this level. You can go to the shop and purchase more levels.")
    }
  }

  LevelScene {

    onBuyLevelClicked: {

      // the LevelScene contains a list of levels and emits a buyLevelClicked(levelData) signal if one was selected for buying
      // if the player has enough playerCredits, the level is purchased (levelBoughtSuccessfully() is emitted) and downloaded (levelDownloadedSuccessfully() is emitted)
      // if he has not enough playerCredits, insufficientFundsError() is emitted in LevelStore
      levelStore.buyLevel(levelData)
    }
  }

}

See also playerCredits and giveCurrency().


clearAllBoughtLevels()

Call this function during development to clear all downloaded levels to test the buying process with buyLevel().

Alternatively, you could also call LevelEditor::clearAllDownloadedLevels().


giveCurrency( amount)

Increase the playerCredits by amount. Use this function to award the player for actions in the game like starting the application once a day or reaching an achievement.

For more details see the V-Play Crash Course Lesson 8 about How to Motivate Players to Create Levels.

Note: By calling giveCurrency the user gets more playerCredits without the need to buy them with buyCurrencyPack(). As such you are not earning money and giving the playerCredits away "for free" - so consider wisely how you spend your gifted credits to not ruin your game ecosystem. If it is very easy for players to get playerCredits, they will not buy them.

See also buyLevel(), buyCurrencyPack(), resetCurrency(), and playerCredits.


resetCurrency()

Call this function during development to reset playerCredits to 0. If playerCredits are 0 you can then test the game flow when the player has insufficient funds when calling buyLevel().

See also buyLevel(), giveCurrency(), and Store::insufficientFundsError.


Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support
Sign up for Free and start developing right away!
I want to make Games
I want to make Apps
Game Development
Cross-Platform, Any Resolution

Use one IDE to deploy to all supported platforms, including iOS and Android, from a single code base.

Support all screen resolutions, aspect ratios and sizes with auto-adapting UI elements, smart scene scaling and memory efficient asset selection.

Learn More

V-Play ranked #1 at research2guidance cross-platform tool benchmarking 2014 by 2188 developers comparing 40 leading tools.

Multiplayer

V-Play Multiplayer supports both real-time and turn-based gameplay, so you can use it to make many different types of cross-platform multiplayer games. It's perfect for making player-vs-player games like 'Words with Friends' or games for a large amount of players, such as 'Clash of Clans'.

Learn More Video

Highscores & Achievements

The V-Play Game Network is a cross-platform gaming service that allows players around the world to compare game highscores and achievements. Players can also challenge each other across multiple platforms and share their progress on Facebook.

Learn More

QML & JavaScript

Qt Meta Language is a highly intuitive reactive language, which is super easy to learn, yet it's extremely powerful and flexible. Mix it with JavaScript to create awesome stuff, with just a few lines of code.

import QtQuick 2.0
import VPlay 2.0

GameWindow {
  Scene {
    
    SimpleButton {
      anchors.centerIn: parent
      text: "Press Me"
      onClicked: {
        console.debug("Wow you pressed me!")
      }
    }
  }
}

Learn More

Monetize & Analyze

With V-Play, you can use many 3rd party services for ads, in-app purchases, analytics and more, with just a few lines of code. All of these plugins work cross-platform, which allows you to maintain a single code base.

Learn More

Level Editor

The LevelEditor can be used during development to create and modify levels for your game, which you can then bundle in your final publishing build. Additionally, you can also integrate the in-game level editor to your published game and let your gamers create new levels.

Learn More Video

Card Game like UNO, Hearthstone or Poker

We got a demo game for you!

The V-Play SDK includes an open-source demo for this game genre. You can use its source code and build your game in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/demos/OneCard/OneCard.pro

Match-3 like Candy Crush Saga

We got a demo game for you!

The V-Play SDK includes an open-source demo for this game genre. You can use its source code and build your game in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/demos/JuicySquash/JuicySquash.pro

<Path to V-PlaySDK>/Examples/V-Play/demos/JuicySquashAdvanced/JuicySquashAdvanced.pro

Puzzle like 2048 or Threes!

We got a demo game for you!

The V-Play SDK includes an open-source demo for this game genre. You can use its source code and build your game in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/demos/2048/2048.pro

Casino like Big Win Slots

We got a demo game for you!

The V-Play SDK includes an open-source demo for this game genre. You can use its source code and build your game in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/demos/FlaskOfRum/FlaskOfRum.pro

Side Scroller like Jetpack Joyride or Flappy Bird

We got a demo game for you!

The V-Play SDK includes an open-source demo for this game genre. You can use its source code and build your game in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/demos/FlappyBird/FlappyBird.pro

Tower Defense like Castle Defense or Bloons TD

We got a demo game for you!

The V-Play SDK includes an open-source demo for this game genre. You can use its source code and build your game in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/demos/Squaby/Squaby.pro

Falldown & Jump like Doodle Jump or Mega Jump

We got a demo game for you!

The V-Play SDK includes an open-source demo for this game genre. You can use its source code and build your game in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/demos/ChickenOutbreak/ChickenOutbreak.pro

<Path to V-PlaySDK>/Examples/V-Play/demos/ChickenOutbreak2/ChickenOutbreak2.pro

<Path to V-PlaySDK>/Examples/V-Play/demos/DoodleJump/DoodleJump.pro

Platformer like Super Mario or Lep's World

We got a demo game for you!

The V-Play SDK includes an open-source demo for this game genre. You can use its source code and build your game in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/demos/Platformer/Platformer.pro

<Path to V-PlaySDK>/Examples/V-Play/demos/PlatformerWithLevelEditor/PlatformerWithLevelEditor.pro

Action like Angry Birds, Fruit Ninja, Cut the Rope

We got a demo game for you!

The V-Play SDK includes an open-source demo for this game genre. You can use its source code and build your game in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/demos/StackTheBoxWithCommunityEditor/StackTheBoxWithCommunityEditor.pro

<Path to V-PlaySDK>/Examples/V-Play/demos/BalloonPop/BalloonPop.pro

<Path to V-PlaySDK>/Examples/V-Play/demos/CarChallenge/CarChallenge.pro

Arcade like Arkanoid or Space Invaders

We got a demo game for you!

The V-Play SDK includes an open-source demo for this game genre. You can use its source code and build your game in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/demos/ZombieBreak/ZombieBreak.pro

Community like Super Mario Maker or Minecraft

We got a demo game for you!

The V-Play SDK includes an open-source demo for this game genre. You can use its source code and build your game in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/examples/Squaby/Squaby.pro

<Path to V-PlaySDK>/Examples/V-Play/demos/StackTheBoxWithCommunityEditor/StackTheBoxWithCommunityEditor.pro

<Path to V-PlaySDK>/Examples/V-Play/demos/PlatformerWithLevelEditor/PlatformerWithLevelEditor.pro

Any other Idea? let us know how we can help you

You are looking for another demo?

The V-Play SDK includes many open-source demos for different game genres. You can use their source code and build your game in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

If you do not find your game genre in this list and wonder if V-Play is the right choice, just contact us, we are happy to help!

Contact Us

App Development
Better Apps, Less Effort

Develop feature-rich, cross-platform mobile apps from a single code base.

V-Play apps look, feel and perform exactly like native iOS, Android and Desktop apps. With less code & much faster development time.

Learn More Highlights Video

V-Play ranked #1 at research2guidance cross-platform tool benchmarking 2014 by 2188 developers comparing 40 leading tools.

Save Time, Code & Money

Save up to 90% source code with V-Play, compared to frameworks like Xamarin, Titanium, React Native and others.

Learn More

QML & JavaScript

Qt Meta Language is a highly intuitive reactive language, which is super easy to learn, yet it's extremely powerful and flexible. Mix it with JavaScript to create awesome stuff, with just a few lines of code. QML also allows you to easily create smooth and complex animations.

import QtQuick 2.0
import VPlayApps 2.0

App {
  Page {
    
    AppButton {
      anchors.centerIn: parent
      text: "Press Me"
      onClicked: {
        console.debug("Wow you pressed me!")
      }
    }
  }
}

Learn More

Monetize & Analyze

With V-Play, you can use many 3rd party services for ads, in-app purchases, analytics and more, with just a few lines of code. All of these plugins work cross-platform, which allows you to maintain a single code base.

Learn More

Native Sensors & More

V-Play Apps harness the power of Qt, the leading cross-platform development framework used by over 1,000,000 developers.

This gives your access to native device features like sensors, camera, file system as well as multimedia, networking, localization and much more.

Learn More

Responsive Design

V-Play has built in responsive design capabilities, you can target phones and tablets with the same source code.

Learn More

Highly Extensible

You have existing JavaScript, C++ or native code? You want to add any 3rd party SDK that we do not offer already?

No worries, you can add any JS, C++, Java or Objective-C code to your project.

Learn More

Component Showcase App shows the most important V-Play features and components

We got a demo app for you!

The V-Play SDK includes an open-source demo for this app type. You can use its source code and build your app in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/appdemos/showcase/Showcase.pro

Qt World Summit Conference App a full-featured conference management app made by V-Play

We got a demo app for you!

The V-Play SDK includes an open-source demo for this app type. You can use its source code and build your app in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/appdemos/qtws2016/QtWS2016.pro

Twitter App how to build layouts like in the official Twitter app for iOS and Android

We got a demo app for you!

The V-Play SDK includes an open-source demo for this app type. You can use its source code and build your app in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/appdemos/twitter/Twitter.pro

Maps App displays free bikes or boxes at bike stations for Vienna's bike sharing service Citybike Wien

We got a demo app for you!

The V-Play SDK includes an open-source demo for this app type. You can use its source code and build your app in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/appdemos/maps/Maps.pro

Messaging App demonstrates how to create the UI of a Facebook Messenger like app

We got a demo app for you!

The V-Play SDK includes an open-source demo for this app type. You can use its source code and build your app in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/appdemos/messaging/Messaging.pro

Weather App how to include powerful animations into your user interface

We got a demo app for you!

The V-Play SDK includes an open-source demo for this app type. You can use its source code and build your app in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/appdemos/waether/Weather.pro

Any other Idea? let us know how we can help you

You are looking for another app demo?

The V-Play SDK includes many open-source demos for different app types. You can use their source code and build your app in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play..

If you do not find your app type in this list and wonder if V-Play is the right choice, just contact us, we are happy to help!

Contact Us