Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

LevelBase

The base class for custom QML levels that are loaded in a game with LevelLoader. More...

Import Statement: import Felgo 3.0
Inherits:

Item

Properties

Signals

Detailed Description

The LevelBase is the base class for levels defined in QML that get loaded with LevelLoader from the LevelEditor.

It has the advantage that the levelData is available as a property after it got loaded and you can add custom data to be saved when the onLevelAboutToBeSaved handler occurs.

Also see the LevelLoader and LevelEditor for further information.

Example Usage

Every game will have different level properties. Whatever these are, you can use the loading functionality of LevelEditor and LevelEditor to simplify creation and loading of levels. The following example shows the definition of two different QML levels for a game:

 // Level01.qml:
 LevelBase {
   property int startGold: 30
 }

 // Level02.qml:
 LevelBase {
   property int startGold: 50
 }

Property Documentation

levelData : alias

This property holds the loaded LevelData object once it got loaded with LevelEditor::loadSingleLevel().

You can access the levelData to display levelMetaData like the levelName for example. The following Level shows how to display the current loaded levelName with a Text item:

 import Felgo 3.0
 import QtQuick 2.0

 LevelBase {

   Text {
     text: levelData.levelMetaData.levelName
   }
 }

Signal Documentation

levelAboutToBeSaved()

This handler is called when the LevelBase has the chance to modify customData or levelMetaData of levelData. Thus you can store customData to the level by setting levelData.customData or changing levelData.levelMetaData.

Alternatively, customData can be added to LevelEditor::saveCurrentLevel with the saveProperties parameter.

Note: The custom properties from saveProperties will overwrite the ones specified here! But usually it is more convenient to set the customData in the derived LevelBase, as you have direct access to the level properties.

The following order is applied when LevelEditor::saveCurrentLevel() is called:

  1. LevelBase::onLevelAboutToBeSaved
  2. LevelEditor::onSaveLevelFinished

The following example shows how to save and load the startGold property to customData when the level is stored:

 LevelBase {
   property int startGold: 30

   onLevelAboutToBeSaved: {
     // store the current startGold level that might have been changed by the game to the level
     levelData.customData = { startGoldLevel: startGold }
   }

   onLevelLoaded: {
     // load the stored startGold value
     startGold = levelData.customData.startGoldLevel
   }
 }

Note: The corresponding handler is onLevelAboutToBeSaved.

See also levelLoaded.


levelLoaded()

This handler is called when customData and levelMetaData of levelData are loaded from LevelEditor.

The following order is applied when LevelEditor::saveCurrentLevel() is called:

  1. LevelLoader::onLoaded
  2. LevelBase::onLevelLoaded
  3. LevelEditor::onLoadLevelFinished

See the onLevelAboutToBeSaved handler for an example how to store and load customData to a level.

Note: The corresponding handler is onLevelLoaded.


Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded