QT音乐播放&属性动画&图形像&qt发布

----------
    
QT       += core gui multimedia
    //工程文件中添加

QMediaPlayer类是一个高级媒体播放类。它可以用来播放歌曲、电影和网络广播等内容。回放的内容被指定为QMediaContent对象,可以将其视为附加了附加信息的主URL或规范URL。当提供一个QMediaContent回放可能能够开始。

 m_welcomePlayer=new QMediaPlayer(this);//生成音乐
    //m_welcomePlayer->setMedia(QUrl("qrc:/BirdGame/Resources/sound/welcome.mp3"));//设置音乐
    //m_welcomePlayer->setVolume(100);//设置音量0-100
    //m_welcomePlayer->play();//播放
    
    m_welcomePlayerList=new QMediaPlaylist(this);//音乐链表
    m_welcomePlayerList->addMedia(QUrl("qrc:/BirdGame/Resources/sound/welcome.mp3"));//添加音乐到列表(可用于播放器)
    m_welcomePlayerList->setPlaybackMode(QMediaPlaylist::CurrentItemInLoop);//循环播放当前链表中得曲目
    m_welcomePlayer->setPlaylist(m_welcomePlayerList);//播放器设置播放列表
    m_welcomePlayer->play();//播放

    m_welcomePlayer->stop();//播放器停止
    m_welcomePlayerList->clear();//播放器列表情空

QT 动画属性类 QPropertyAnimation

QPropertyAnimation *moveAnimation=new QPropertyAnimation(this,"pos");//属性动画pos是根据位置来设置动画效果 "opacity"根据透明度来设置动画效果0为完全不透明
    moveAnimation->setLoopCount(-1);//设置动画循环次数 -1为无限循环 0不启动
    moveAnimation->setDuration(6000);//动画时长6秒钟
    moveAnimation->setStartValue(QPoint(0,pos().y()));//设置动画得启动值(位置初始值)
    moveAnimation->setEndValue(QPoint(0-m_scene->width(),pos().y()));//设置动画得结束值
    moveAnimation->setEasingCurve(QEasingCurve::Linear);//动画变化得曲线值
    moveAnimation->start();//动画启动
 
 

#include<QGraphicsItem>//图形像 可使用z值实现立体感  
void QGraphicsItem::setZValue(qreal z);//可使用z值实现立体感 





 

#include<QGraphicsObject>//图形对像

需重新写

void paint(QPainter*,const QStyleOptionGraphicsItem*,QWidget*);//QStyleOptionGraphicsItem类用于描述绘制QGraphicsItem所需的参数

  QRectF  boundingRect()const;//虚函数返回图像所在得矩形 重写绘图区域







//如果要实现碰撞检测需重写实现 
QPainterPath xxxx::shape() const//返回形状 用于碰撞检测
{
    QPainterPath path;//图形得轮廓
    path.addRect(QRectF(m_scene->width(),0,PIPE_WIDTH,m_uoPipeHeight));//添加矩形
    path.addRect(QRectF(m_scene->width(),m_uoPipeHeight+140,PIPE_WIDTH,m_uoPipeHeight));//添加矩形
    return path;

}






//检测是否碰撞
bool xxxx::checkIsCollided()//碰撞检测
{
    if(!collidingItems().isEmpty())//collidingItems()返回当前图形像有碰撞所有项得链表   如果没有碰撞那就为空
    {
        return true;
    }
    else
    {
        return false;
    }

}

#include<QGraphicsView>//图像视图
#include<QGraphicsScene>//场景类




QGraphicsScene *m_scene=new QGraphicsScene;//生成场景
QGraphicsView * view=new QGraphicsView(m_scene,this);//为场景生成视图
    view->setScene(m_scene);//视图设置场景
    view->setStyleSheet("border:none;background:transparent;");//设置视图样式无边框 透明
    view->setCacheMode(QGraphicsView::CacheBackground);//设置视图缓存模式 ,没有变化时背景不进行更新
    view->setForegroundBrush(QColor(255,123,88,100));//设置场景得前景色 颜色第四个参数是透明度
    view->setBackgroundBrush(QPixmap("strawbrt.png"));//设置场景得背景图片 注图片在Run运行目录下
    view->resize(400,400);//设置场景得大小
    view->show();//场景显示

**

注图形像坐标,场景坐标都是以中心点为原点得坐标 视图坐标是以左上角为原点坐标

**


状态机
QState 类
QState对象可以有子状态,也可以有到其他状态的转换。QState是状态机框架的一部分。
函数的作用是:添加一个转换。函数的作用是:删除一个转换。函数的作用是:返回状态的传出转换。

QStateMachine类
qstatemine是以Statecharts的概念和符号为基础的。QStateMachine是状态机框架的一部分。

QState *rootState = new QState;//生成子状态 用于保存其他状态
QState *ellipseState = new QState(rootState);//生成状态 父类是子状态
xxxxxxxxxxx
xxxxxxxxxxx

QStateMachine states;
states.addState(rootState);//子状态添加状态到状态机(参照示例 Animated)


qt发布
首先添加环境变量用得什么编译器就添加什么变量
此电脑属性——高级系统设置——高级——环境变量——系统变量——path——编辑——新建——浏览——选择qt编译器得bin目录----确定
将Release下生成得exe文件拷贝到另一个文件侠
用cmd命令进入这个文件侠 输入windeployqt 文件名.exe 即可

猜你喜欢

转载自blog.csdn.net/qq_45743563/article/details/109079178