QT Mobile Application Development (V): Scene switching
The previous article described how to use Qtquick to achieve brilliant particle effects. The advent of particle effects can give developers a chance to develop a personalized interface that will create more interesting interfaces and adapt them to mobile platforms such as Android and iOS, making your program even more fun!
original article, against undeclared references. Original Blog address:http://blog.csdn.net/gamesdev/article/details/34840415
This time I'll show how I can switch scenes when I'm actually applying development. The switching of scenes is an architectural problem, there are many implementations, and QT Quick provides a lot of useful classes for us to switch scenes. In QML, scene switching is essentially a way to hide an interface class and another interface class to display. The following code is a simple example:
Import QtQuick 2.2import qtquick.controls 1.1applicationwindow{visible:true width:640 height:480 Title:qs Tr ("Hello World") Item {id:scene_1 visible:true anchors.fill:parent Text { Anchors.centerIn:parent textFormat:Text.RichText text:qstr ("
The program demonstrates the following effects:
The first is the left scene, when the mouse click on the form, the right scene will pop up, the red text will disappear.
This example uses the Visible property of item, sets the visible of the original item to False, and then sets the visible of the item to true to achieve the purpose of the scene switch.
A scene instantaneous switching is also very simple, if you want to use some special effects, it is necessary to give full play to the developer's thinking, so that the interface becomes colorful! Here's how I use the particle system I talked about in my previous blog post to achieve brilliant scene switching effects:
Here's the code for the implementation:
Import QtQuick 2.2import qtquick.controls 1.1import qtquick.particles 2.0applicationwindow{visible:true width:640 height:480 title:qstr ("Test scene Toggle") Item {id:scene_1 visible:true Anchors.fill:paren T Text {anchors.centerIn:parent textFormat:Text.RichText text:qstr ("&L T;h1><font Color=red> This is the first scene </color>In my first independent game, "Take medicine," I carefully designed a fun way to switch the scene: first with about 6000 capsules covering the main main scene, and then set the corresponding layer in the back layer of the visible, until the capsule disappears after the next scene.
This article participated in the CSDN blog post Contest , please support me, vote for me!