-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainscene.cpp
107 lines (77 loc) · 2.48 KB
/
mainscene.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "mainscene.h"
#include "ui_mainscene.h"
#include<QPainter>
#include "mypushbutton.h"
#include<QDebug>
#include<QTimer>
#include<QSoundEffect>
#include<QMessageBox>
MainScene::MainScene(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainScene)
{
ui->setupUi(this);
//配置主场景
//设置固定大小
setFixedSize(320,588);
//设置图标
setWindowIcon(QIcon(":/res/Coin0001.png"));
//设置标题
setWindowTitle("翻金币主场景");
//退出按钮实现
connect(ui->actionquit,&QAction::triggered,[=](){
this->close();
});
//详情
connect(ui->actionxiangqing,&QAction::triggered,[=](){
QMessageBox::information(this,"详情","制作人:Elysia");
});
//准备开始按钮音效
QSoundEffect * startSound = new QSoundEffect(this);
startSound->setSource(QUrl::fromLocalFile("://res/TapButtonSound.wav"));
//开始按钮
MyPushButton * startBtn = new MyPushButton(":/res/MenuSceneStartButton.png");
startBtn->setParent(this);
startBtn->move(this->width()*0.5 - startBtn->width()*0.5,this->height()*0.7);
//实例化选择关卡场景
chooselevel = new ChooseLevel;
//监听选择关卡的返回按钮信号
connect(chooselevel,&ChooseLevel::chooseSceneBack,this,[=](){
this->setGeometry(chooselevel->geometry());
chooselevel->hide();//将选择关卡场景 隐藏掉
this->show();//重新显示主场景
});
connect(startBtn,&MyPushButton::clicked,[=](){
//qDebug()<<"1";
//播放开始音效
startSound->play();
//弹起特效
startBtn->zoom1();
startBtn->zoom2();
//进入到选择关卡场景中
//延时进入选择关卡
QTimer::singleShot(200,this,[=](){
chooselevel->setGeometry(this->geometry());
//自身隐藏
this->hide();
//显示选择关卡
chooselevel->show();
});
});
}
void MainScene::paintEvent(QPaintEvent *)
{
QPainter painter(this);
QPixmap pix;
pix.load(":/res/PlayLevelSceneBg.png");
painter.drawPixmap(0,0,this->width(),this->height(),pix);
//左上角图标
pix.load(":/res/Title.png");
//缩放
pix = pix.scaled(pix.width()*0.5,pix.height()*0.5);
painter.drawPixmap(10,30,pix);
}
MainScene::~MainScene()
{
delete ui;
}