QT Mobile Application Development (II): Using animated Frames

Source: Internet
Author: User

QT Mobile Application Development (II): Using animated Frames

The previous blog describes how to use QT qml to adapt to screen resolution size, in fact, the adaptation of different resolutions is a very tricky problem, in addition to different resolutions, aspect ratio (aspect ratio) is not the same. Some tablets on the hardware and ipad is the same as the Retina screen (2048x1536), some low-end phone resolution only 320x480, so the aspect ratio is not the same, so the process of designing the app must be planning for the content layout. The use of Anchor layout method can help us solve certain problems, but also make good use of the members of the screen class to obtain more information about the system resolution.

This article mainly introduces the animation frame of Qtquick. Qt Quick Animation Framework since the QT4 era has been, there are a lot of demo to us before the light. Derived from C + + animation frame, Qt quick animation frame is gorgeous and easy to use, it is worth learning.

original article, against undeclared references. Original blog address:http://blog.csdn.net/gamesdev/article/details/32730079

Let's start by introducing several classes related to the animation framework:

Animation is the base class for these classes, and it has these properties:

AlwaysRunToEnd:boolloops:intpaused:boolrunning:bool

The last three properties are very good to understand, the first one to explain, if set to true, then regardless of whether the animation is finished, he will let the animation complete the final round of playback. Set to False, then once the animation is finished, the animation ends immediately.

Animation has many subcategories, including Anchoranimation, Parallelanimation, Parentanimation, Pathanimation, PauseAnimation, propertyaction , Propertyanimation, Scriptaction, and Sequentialanimation. In practical applications, a single animation uses propertyanimation subclasses ColorAnimation, Numberanimation, Rotationanimation, and Vector3DAnimation, The following is a simple example:

Numberanimation on x {from:0;to:100; duration:1000}

As shown in the above example, the sub-classes below propertyanimation are flexible and varied in form of grammatical existence, often with prepositions on and phrase behavior on. The above example indicates that the animation type on the left side of the preposition must correspond to the property type on the right. If you want to apply a preposition on to a Vector3D variable, you should write this:

Vector3DAnimation on position {from:Qt.vector3d (0, 0, 0); to Qt.vector3d (1, 1, 1); duration:1000}

The difference between Behavior on and on is that Behavioron provides the default animation operation, that is, Behavior can describe the default animation:

Behavior on width{        numberanimation {duration:1000}}

But it may be that the QT quick animation this piece of imperfect, sometimes in different platform performance will be different, at times behavior not work, sometimes is good (problem description).

When behavior encounters a state Transition (transition), behavior is overwritten. For more information, please refer to the QT documentation.

You see the game I made three bacteria and capsules have been moved from left to right and are circular, here is the code:

image{         id:animatecapsule         height:parent.width/10         width:height/2         propertyint xFrom:parent.width + Height * 8         propertyint xTo:-height * 2         x:xfrom         y:parent.height * 0.45         Source: ". /.. /images/capsule.png "          rotationanimation on rotation         {                   from:0                   to:360                   loops: Animation.infinite                   duration:2000         }          //@ Desktop: Note Using this section of code         Behavioron x         {                   Numberanimation                   {                            from:animateCapsule.xFrom                            to:animateCapsule.xTo                            loops:Animation.Infinite                            duration:2000                   }}}         

This article participated in the CSDN Bowen Contest, please support me, vote for me!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.