Forums

OverviewV-Play 1 SupportSplashscreen on Android › Reply To: Splashscreen on Android

OverviewV-Play 1 SupportSplashscreen on Android › Reply To: Splashscreen on Android
#6546

V-Play User

If i try this with 2 Timer and 2 Loader in the main.qml like in squaby, the SplashScreen appears. but the window size is wrong. (only on android, on desktop and ios all is fine) see images:

Phone: https://www.dropbox.com/s/4kjdz15o73qt06l/phone.JPG

Tablet: https://www.dropbox.com/s/5lry2xix52bjm8m/tablet.JPG

 

main.qml:

import VPlay 1.0
import QtQuick 1.1

// Plugins
import VPlay.plugins.gamecenter 1.0
import VPlay.plugins.flurry 1.0
import VPlay.plugins.facebook 1.0
import VPlay.plugins.store 1.0

import "base"
import "values"
import "entities"
import "gnView"

// add this for Meego, to fix the portrait mode issue there
//import com.nokia.meego 1.0
//Page {

// main with Android Splashscreen
GameWindow {
    id: window
    // depending on which window size is defined as start resolution here, the corresponding image sizes get loaded here! so for testing hd2 images, at least use factor 3.5
    // the window size can be changed at runtime by pressing the keys 1-6 (see GameWindow.qml)
    width: 480*2//*1.5//854// // for testing on desktop with the highest res, use *1.5 so the -hd2 textures are used
    height: 320*2//*1.5//480//

    displayFpsEnabled: false
    fpsTextItem.color: "white"

    state: "main"

    // use BackgroundMusic for long-playing background sounds
    BackgroundMusic {
        id: backgroundMusic
        source: system.isPlatform(System.Meego) || system.isPlatform(System.Symbian) ? "snd/bg-slow-mono.ogg" : "snd/bg-slow.wav"
        //        muted: settings.soundEnabled
    }

    // Custom font loading of ttf fonts
    FontLoader {
        id: fontHUD
        source: "fonts/MoonFlowerBold.ttf"
    }

    Timer {
        id: splashScreenOff
        repeat: false
        interval: system.isPlatform(System.IOS) ? 0 : 1000
        onTriggered: {
            if(splashLoader.item) {
                splashLoader.item.exitScene()
            }
        }
    }
    Timer {
        id: startLoading
        repeat: false
        interval: system.isPlatform(System.IOS) ? 0 : 500 // on iOS start in 0ms
        onTriggered: {
            // load actual game
            implLoader.source = "MainItem.qml"
        }
    }

    Connections {
        target: splashLoader.item ? splashLoader.item : null
        onLoadingFinished: {
            if(implLoader.item) {
                implLoader.item.activateMain()
            }
            // unload splashscreen
            splashLoader.source = ""
        }
    }

    Loader {
        id: splashLoader
        source: "SplashScreen.qml"
        onLoaded: {
            if(item) {
                item.enterScene()
                loadItemWithCocos(item)
            }
            startLoading.start()
        }
    }

    Loader {
        id: implLoader
        onLoaded: {
            console.log("implLoader onLoaded")
            if(item) {
                loadItemWithCocos(item)
                splashScreenOff.start()
            }
        }
    }

    onStateChanged: {
        if(implLoader.item) implLoader.item.state = state
    }

}
//} // add this when building for MeeGo

 

MainItem.qml:

import VPlay 1.0
import QtQuick 1.1

// Plugins
import VPlay.plugins.gamecenter 1.0
import VPlay.plugins.flurry 1.0
import VPlay.plugins.facebook 1.0
import VPlay.plugins.store 1.0

import "base"
import "values"
import "entities"
import "gnView"

// add this for Meego, to fix the portrait mode issue there
//import com.nokia.meego 1.0
//Page {

Item {
//    width: 480*2
//    height: 320*2

    function activateMain() {
        // fade in
        state = "main"
    }

    property alias level: scene.level
    property alias player: scene.player

    // start position of the player
    property int startPositionX: 70
    property int startPositionY: 60

    // for loading the stored highscore
    property int maximumHighscore: 0
    property int lastScore: 0
    property variant levelScores: ({})
    property variant currentSelectedLevel: ({})
    // stores the levelPack datas
    LevelPacks{
        id:levelPacks
    }
    property variant currentSelectedPack: ({})

    // no ads purchase
    property bool purchasedNoAdsPackage: noadsGood.purchased

    Component.onCompleted: {
        // get called if the whole scene is loaded finished, and repeater is finished

        // Authenticate player to gamecenter
        gameCenter.authenticateLocalPlayer()

        if(system.debugBuild)
            settings.language = "en_EN"
        else {
            // enable System language for translations
            translation.useSystemLanguage = true
        }
        console.debug("current language:", settings.language)

        // Sheduling needs to be turned off on iOS, Android and Mac to avoid small lags during fast movement.
        if(system.isPlatform(System.IOS) || system.isPlatform(System.Mac) || system.isPlatform(System.Android) ) {
            vplayScheduler.schedulingMethod = VPlayScheduler.None
        }

        console.debug("Component.onCompleted")

        // Copy/paste into csv file for setting up in-app purchases in platform stores
        // console.debug(store.printStoreProductLists())
        nativeUtils.displayMessageBox("debug","width"+width+", height"+height+", mainScene.width"+mainScene.width+", mainScene.height"+mainScene.height)
        // load the leveldata with a timer, otherwise the app start will be blocked for the loading time(1sec)
        //initializeAll.start()
    }

  // functions....

    onLevelScoresChanged: {

    }
    onMaximumHighscoreChanged: {
        var storedScore = settings.getValue("maximumHighscore")
        console.debug("onMaximumHighscoreChanged:  settings.highscore from", storedScore, "to", maximumHighscore)

        // if not stored anything yet, store the new value
        // or if a new highscore is reached, store that
        // if the same score is submitted, call reportScore() too to update the score on GameCenter
        if(!storedScore || maximumHighscore > storedScore) {
            console.debug("onMaximumHighscoreChanged: stored improved highscore from", storedScore, "to", maximumHighscore)
            settings.setValue("maximumHighscore", maximumHighscore)

            // this call posts the highscore both to V-Play Game Network and GameCenter, because gameCenterItem is set in VPGN
            gameNetwork.reportScore(maximumHighscore)
        }
    }
    LevelEditor {
        id: levelEditor
        applicationJSONLevelsDirectory: "JSONLevels/"
    }

    //    // use BackgroundMusic for long-playing background sounds
    //    BackgroundMusic {
    //        id: backgroundMusic
    //        source: system.isPlatform(System.Meego) || system.isPlatform(System.Symbian) ? "snd/bg-slow-mono.ogg" : "snd/bg-slow.wav"
    //        //        muted: settings.soundEnabled
    //    }

    // if star collieded
    Sound {
        id: starSound
        source: "./snd/pling.wav"
    }

    // other item plugins

    // this scene is set to visible when loaded initially, so its opacity value gets set to 1 in a PropertyChange below
    MainScene {
        id: mainScene
        // when opacity is 0, visible gets set to false in SceneBase
        opacity: 0
    }

    GrumpyDudeScene {
        id: scene
        // when opacity is 0, visible gets set to false in SceneBase
        opacity: 0
        onVisibleChanged: console.debug("GameScene changed visible to", visible)
    }

    GameOverScene {
        id: gameOverScene
        // when opacity is 0, visible gets set to false in SceneBase
        opacity: 0
    }

    LevelSelectScene {
        id: levelSelectScene
        onLevelPressed: window.state = "game"
        // when opacity is 0, visible gets set to false in SceneBase
        opacity: 0
    }

    LevelFinishedScene {
        id: levelFinishedScene
        // when opacity is 0, visible gets set to false in SceneBase
        opacity: 0
    }

    CreditsScene {
        id: creditsScene
        // when opacity is 0, visible gets set to false in SceneBase
        opacity: 0
    }

    HelpScene {
        id: helpScene
        // when opacity is 0, visible gets set to false in SceneBase
        opacity: 0
    }

    VPlayGameNetworkScene {
        id: vplayGameNetworkScene
        opacity: 0
    }

    LevelEditorScene {
        id: levelEditorScene
        opacity: 0
    }

    LevelPackScene {
        id: levelPackScene
        opacity: 0
    }

    // for creating & removing entities
    EntityManager {
        id: entityManager
        entityContainer: scene
        poolingEnabled: true // entity pooling works since version 0.9.4, so use it
        // required for LevelEditor, so the entities can be created by entityType
        dynamicCreationEntityList: [ Qt.resolvedUrl("entities/Platform.qml"), Qt.resolvedUrl("entities/Goal.qml"), Qt.resolvedUrl("entities/Star.qml")]
    }

    // this gets used for analytics, to know which state was ended before
    property string lastActiveState: ""

    onStateChanged: {

        console.debug("GrumpyDudeMain: changed state to", state)

        if(state === "main")
            activeScene = mainScene
        else if(state === "game")
            activeScene = scene
        else if(state === "gameOver")
            activeScene = gameOverScene
        else if(state === "levelFinished")
            activeScene = levelFinishedScene
        else if(state === "credits")
            activeScene = creditsScene
        else if(state === "gameNetwork")
            activeScene = vplayGameNetworkScene
        else if(state === "selectLevel")
            activeScene = levelSelectScene
        else if(state === "levelEditing")
            activeScene = levelEditorScene
        else if(state === "help")
            activeScene = helpScene
        else if(state === "selectLevelPack")
            activeScene = levelPackScene

        if(lastActiveState === "main") {
            flurry.endTimedEvent("Display.Main")
        } else if(lastActiveState === "game") {
            flurry.endTimedEvent("Display.Game")

            // NOTE: Android doesnt support endTimedEventWithParams yet!?! http://stackoverflow.com/questions/12205860/android-flurry-and-endtimedevent
            //flurry.endTimedEvent("Display.Game", { "score": lastScore, "collectedStars" : player.collectedStars, "scoreForStars": player.collectedStars*player.bonusScoreForStar })
            // thus emit them with own events

        } else if(lastActiveState === "gameOver") {
            flurry.endTimedEvent("Display.GameOver")
        } else if(lastActiveState === "levelFinished") {
            flurry.endTimedEvent("Display.LevelFinished")
        } else if(lastActiveState === "credits") {
            flurry.endTimedEvent("Display.Credits")
        } else if(lastActiveState === "gameNetwork") {
            flurry.endTimedEvent("Display.VPlayGameNetwork")
        } else if(lastActiveState === "selectLevel") {
            flurry.endTimedEvent("Display.LevelSelect")
        } else if(lastActiveState === "levelEditing") {
            flurry.endTimedEvent("Display.LevelEditor")
        } else if(lastActiveState === "help") {
            flurry.endTimedEvent("Display.Help")
        } else if(lastActiveState === "selectLevelPack") {
            flurry.endTimedEvent("Display.LevelPack")
        }

        if(state === "main") {
            flurry.logTimedEvent("Display.Main")
        } else if(state === "game") {
            flurry.logTimedEvent("Display.Game")
        } else if(state === "gameOver") {
            flurry.logTimedEvent("Display.GameOver")
        } else if(state === "levelFinished") {
            flurry.logTimedEvent("Display.LevelFinished")
        } else if(state === "credits") {
            flurry.logTimedEvent("Display.Credits")
        } else if(state === "gameNetwork") {
            flurry.logTimedEvent("Display.VPlayGameNetwork")
        } else if(state === "selectLevel") {
            flurry.logTimedEvent("Display.LevelSelect")
        } else if(state === "levelEditing") {
            flurry.logTimedEvent("Display.LevelEditor")
        } else if(state === "help") {
            flurry.logTimedEvent("Display.Help")
        } else if(state === "selectLevelPack") {
            flurry.logTimedEvent("Display.LevelPack")
        }

        lastActiveState = state
    }

    state: "main"
    // use one of the following states to start with another state when launching the game
    //    state: "game"
    //state: "gameOver"

    // these states are switched when the play button is pressed in MainScene, when the game is lost and when the Continue button is pressed in GameOverScene
    states: [
        State {
            name: "main"
            // by switching the propery to 1, which is by default set to 0 above, the Behavior defined in SceneBase takes care of animating the opacity of the new Scene from 0 to 1, and the one of the old scene from 1 to 0
            PropertyChanges { target: mainScene; opacity: 1}
        },
        State {
            name: "game"
            PropertyChanges { target: scene; opacity: 1}
            StateChangeScript {
                script: {
                    console.debug("entered state 'game' with levelId: '"+currentSelectedLevel.levelId+"': "+JSON.stringify(currentSelectedLevel))
                    scene.state = ""
                    scene.enterScene();
                }
            }
        },
        State {
            name: "gameOver"
            PropertyChanges { target: gameOverScene; opacity: 1}
            StateChangeScript {
                script: {
                    console.debug("entered state 'gameOver'")
                    gameOverScene.enterScene();
                }
            }
        },
        State {
            name: "levelFinished"
            PropertyChanges { target: levelFinishedScene; opacity: 1}
            StateChangeScript {
                script: {
                    console.debug("entered state 'levelFinished'")
                    levelFinishedScene.enterScene();
                }
            }
        },
        State {
            name: "credits"
            PropertyChanges { target: creditsScene; opacity: 1}
        },
        State {
            name: "help"
            PropertyChanges { target: helpScene; opacity: 1}
        },
        State {
            name: "gameNetwork"
            PropertyChanges { target: vplayGameNetworkScene; opacity: 1}
        },
        State {
            name: "selectLevelPack"
            PropertyChanges { target: levelPackScene; opacity: 1}
            StateChangeScript {
                script: {
                    currentSelectedPack = ({})
                }
            }
        },
        State {
            name: "selectLevel"
            PropertyChanges { target: levelSelectScene; opacity: 1}
            StateChangeScript {
                script: {
                    levelSelectScene.enterScene()
                    currentSelectedLevel = {}
                }
            }
        },
        State {
            name: "levelEditing"
            PropertyChanges { target: levelEditorScene; opacity: 1}
            StateChangeScript {
                script: {
                    levelEditorScene.clearSceneAndNewLevel()
                }
            }
        }
    ]
}
//} // add this when building for MeeGo

i tried with every width/height in the MainItem.. no effect

 

 

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