mirror of
https://github.com/Leo501/CocosCreatorTutorial.git
synced 2026-05-08 06:38:37 +08:00
转盘demo
This commit is contained in:
67
TurntableDemo/.gitignore
vendored
Normal file
67
TurntableDemo/.gitignore
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
#/////////////////////////////////////////////////////////////////////////////
|
||||
# Fireball Projects
|
||||
#/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
library/
|
||||
temp/
|
||||
local/
|
||||
build/
|
||||
|
||||
#/////////////////////////////////////////////////////////////////////////////
|
||||
# Logs and databases
|
||||
#/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
*.log
|
||||
*.sql
|
||||
*.sqlite
|
||||
|
||||
#/////////////////////////////////////////////////////////////////////////////
|
||||
# files for debugger
|
||||
#/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
*.sln
|
||||
*.csproj
|
||||
*.pidb
|
||||
*.unityproj
|
||||
*.suo
|
||||
|
||||
#/////////////////////////////////////////////////////////////////////////////
|
||||
# OS generated files
|
||||
#/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
.DS_Store
|
||||
ehthumbs.db
|
||||
Thumbs.db
|
||||
|
||||
#/////////////////////////////////////////////////////////////////////////////
|
||||
# exvim files
|
||||
#/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
*UnityVS.meta
|
||||
*.err
|
||||
*.err.meta
|
||||
*.exvim
|
||||
*.exvim.meta
|
||||
*.vimentry
|
||||
*.vimentry.meta
|
||||
*.vimproject
|
||||
*.vimproject.meta
|
||||
.vimfiles.*/
|
||||
.exvim.*/
|
||||
quick_gen_project_*_autogen.bat
|
||||
quick_gen_project_*_autogen.bat.meta
|
||||
quick_gen_project_*_autogen.sh
|
||||
quick_gen_project_*_autogen.sh.meta
|
||||
.exvim.app
|
||||
|
||||
#/////////////////////////////////////////////////////////////////////////////
|
||||
# webstorm files
|
||||
#/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
.idea/
|
||||
|
||||
#//////////////////////////
|
||||
# VS Code
|
||||
#//////////////////////////
|
||||
|
||||
.vscode/
|
||||
2
TurntableDemo/README.md
Normal file
2
TurntableDemo/README.md
Normal file
@@ -0,0 +1,2 @@
|
||||
# 转盘demo
|
||||
一个简单实现的转盘demo
|
||||
6
TurntableDemo/assets/Scene.meta
Normal file
6
TurntableDemo/assets/Scene.meta
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"ver": "1.0.1",
|
||||
"uuid": "29f52784-2fca-467b-92e7-8fd9ef8c57b7",
|
||||
"isGroup": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
1089
TurntableDemo/assets/Scene/helloworld.fire
Normal file
1089
TurntableDemo/assets/Scene/helloworld.fire
Normal file
File diff suppressed because it is too large
Load Diff
7
TurntableDemo/assets/Scene/helloworld.fire.meta
Normal file
7
TurntableDemo/assets/Scene/helloworld.fire.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"ver": "1.0.0",
|
||||
"uuid": "2d2f792f-a40c-49bb-a189-ed176a246e49",
|
||||
"asyncLoadAssets": false,
|
||||
"autoReleaseAssets": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
6
TurntableDemo/assets/Script.meta
Normal file
6
TurntableDemo/assets/Script.meta
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"ver": "1.0.1",
|
||||
"uuid": "4734c20c-0db8-4eb2-92ea-e692f4d70934",
|
||||
"isGroup": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
22
TurntableDemo/assets/Script/HelloWorld.js
Normal file
22
TurntableDemo/assets/Script/HelloWorld.js
Normal file
@@ -0,0 +1,22 @@
|
||||
cc.Class({
|
||||
extends: cc.Component,
|
||||
|
||||
properties: {
|
||||
label: {
|
||||
default: null,
|
||||
type: cc.Label
|
||||
},
|
||||
// defaults, set visually when attaching this script to the Canvas
|
||||
text: 'Hello, World!'
|
||||
},
|
||||
|
||||
// use this for initialization
|
||||
onLoad: function () {
|
||||
this.label.string = this.text;
|
||||
},
|
||||
|
||||
// called every frame
|
||||
update: function (dt) {
|
||||
|
||||
},
|
||||
});
|
||||
9
TurntableDemo/assets/Script/HelloWorld.js.meta
Normal file
9
TurntableDemo/assets/Script/HelloWorld.js.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"uuid": "280c3aec-6492-4a9d-9f51-a9b00b570b4a",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
145
TurntableDemo/assets/Script/TurntableMgr.js
Normal file
145
TurntableDemo/assets/Script/TurntableMgr.js
Normal file
@@ -0,0 +1,145 @@
|
||||
cc.Class({
|
||||
extends: cc.Component,
|
||||
|
||||
properties: {
|
||||
nodeBoxBg: cc.Node,
|
||||
total: 6,//几项
|
||||
section: 0,//一项分多少
|
||||
resultIdx: 0,
|
||||
delayTime: 0,
|
||||
},
|
||||
|
||||
initProperties() {
|
||||
this.rotationSpeed = 0;
|
||||
this.choiceIdx = -1;
|
||||
this.isFinish = false;
|
||||
this.showResult = false;
|
||||
this.initSection();
|
||||
},
|
||||
|
||||
/**
|
||||
* 分盘
|
||||
*/
|
||||
initSection() {
|
||||
console.log('initSection');
|
||||
this.rotaionList = [];
|
||||
let totalPath = this.section * this.total;
|
||||
let path = 360 / totalPath;
|
||||
this.path = path;
|
||||
this.pathDelRota = 360 / (totalPath);
|
||||
for (let i = 0; i < this.section; i++) {
|
||||
this.rotaionList.push(path * i);
|
||||
}
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.initProperties();
|
||||
this.initSection();
|
||||
},
|
||||
|
||||
start() {
|
||||
this.init();
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {*} data
|
||||
*/
|
||||
init(data) {
|
||||
this.onAccelerate();
|
||||
this.node.runAction(cc.sequence(cc.delayTime(1 + this.delayTime), cc.callFunc(() => {
|
||||
console.log('已经选择了');
|
||||
this.choiceIdx = (this.total - this.resultIdx) * this.section;
|
||||
})));
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {*} rotation
|
||||
*/
|
||||
wacthRotaion(rotation) {
|
||||
rotation %= 360;
|
||||
rotation |= 0;
|
||||
let idx = rotation / this.path;
|
||||
idx |= 0;
|
||||
|
||||
if (this.nowIdx != idx) {
|
||||
this.nowIdx = idx;
|
||||
if (this.showResult) {
|
||||
this.onDecelerate(this.pathDelRota);
|
||||
}
|
||||
if (!this.showResult && this.choiceIdx == this.nowIdx) {
|
||||
console.log('开始减速');
|
||||
console.log(rotation, this.rotationSpeed);
|
||||
this.showResult = true;
|
||||
}
|
||||
console.log('rotation=', rotation, this.rotationSpeed, idx);
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {*} rotation
|
||||
*/
|
||||
wacthRotaion_type1(rotation) {
|
||||
rotation %= 360;
|
||||
rotation |= 0;
|
||||
let idx = rotation / this.path;
|
||||
idx |= 0;
|
||||
|
||||
if (this.nowIdx != idx) {
|
||||
this.nowIdx = idx;
|
||||
// console.log('nowIdx=', idx);
|
||||
if (this.choiceIdx == this.nowIdx) {
|
||||
console.log('开始减速');
|
||||
this.onDecelerate(30);
|
||||
}
|
||||
if (this.rotationSpeed == 5) {
|
||||
this.rotationSpeed = 0;
|
||||
}
|
||||
if (this.isFinish) {
|
||||
this.onDecelerate(15);
|
||||
// if(this)
|
||||
}
|
||||
if (this.rotationSpeed == 120) {
|
||||
this.isFinish = true;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 减速
|
||||
*/
|
||||
onDecelerate(del = 30) {
|
||||
this.rotationSpeed -= del;
|
||||
},
|
||||
|
||||
/**
|
||||
* 加速
|
||||
*/
|
||||
onAccelerate() {
|
||||
if (this.accelerateAction) this.node.stopAction(this.accelerateAction);
|
||||
this.accelerateAction = cc.repeat(cc.sequence(cc.delayTime(0.25), cc.callFunc(() => {
|
||||
this.rotationSpeed += 90;
|
||||
console.log('this.rotationSpeed', this.rotationSpeed);
|
||||
})), 4);
|
||||
this.node.runAction(this.accelerateAction);
|
||||
},
|
||||
|
||||
/**
|
||||
* 每一帧回调
|
||||
* @param {*} dt
|
||||
*/
|
||||
update(dt) {
|
||||
if (this.rotationSpeed >= 0) {
|
||||
this.nodeBoxBg.rotation += this.rotationSpeed * dt;
|
||||
}
|
||||
this.wacthRotaion(this.nodeBoxBg.rotation);
|
||||
},
|
||||
|
||||
/**
|
||||
* 统一回收组件
|
||||
*/
|
||||
onDestroy() {
|
||||
}
|
||||
});
|
||||
9
TurntableDemo/assets/Script/TurntableMgr.js.meta
Normal file
9
TurntableDemo/assets/Script/TurntableMgr.js.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"uuid": "1d8b1997-8bd5-4477-a346-c84e4156668f",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
6
TurntableDemo/assets/Texture.meta
Normal file
6
TurntableDemo/assets/Texture.meta
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"ver": "1.0.1",
|
||||
"uuid": "7b81d4e8-ec84-4716-968d-500ac1d78a54",
|
||||
"isGroup": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
BIN
TurntableDemo/assets/Texture/HelloWorld.png
Normal file
BIN
TurntableDemo/assets/Texture/HelloWorld.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 37 KiB |
30
TurntableDemo/assets/Texture/HelloWorld.png.meta
Normal file
30
TurntableDemo/assets/Texture/HelloWorld.png.meta
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"ver": "2.0.0",
|
||||
"uuid": "6aa0aa6a-ebee-4155-a088-a687a6aadec4",
|
||||
"type": "sprite",
|
||||
"wrapMode": "clamp",
|
||||
"filterMode": "bilinear",
|
||||
"subMetas": {
|
||||
"HelloWorld": {
|
||||
"ver": "1.0.3",
|
||||
"uuid": "31bc895a-c003-4566-a9f3-2e54ae1c17dc",
|
||||
"rawTextureUuid": "6aa0aa6a-ebee-4155-a088-a687a6aadec4",
|
||||
"trimType": "auto",
|
||||
"trimThreshold": 1,
|
||||
"rotated": false,
|
||||
"offsetX": 0,
|
||||
"offsetY": 0,
|
||||
"trimX": 0,
|
||||
"trimY": 0,
|
||||
"width": 195,
|
||||
"height": 270,
|
||||
"rawWidth": 195,
|
||||
"rawHeight": 270,
|
||||
"borderTop": 0,
|
||||
"borderBottom": 0,
|
||||
"borderLeft": 0,
|
||||
"borderRight": 0,
|
||||
"subMetas": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
1036
TurntableDemo/assets/Texture/home1.plist
Normal file
1036
TurntableDemo/assets/Texture/home1.plist
Normal file
File diff suppressed because it is too large
Load Diff
1728
TurntableDemo/assets/Texture/home1.plist.meta
Normal file
1728
TurntableDemo/assets/Texture/home1.plist.meta
Normal file
File diff suppressed because it is too large
Load Diff
BIN
TurntableDemo/assets/Texture/home1.png
Normal file
BIN
TurntableDemo/assets/Texture/home1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.9 MiB |
30
TurntableDemo/assets/Texture/home1.png.meta
Normal file
30
TurntableDemo/assets/Texture/home1.png.meta
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"ver": "2.0.0",
|
||||
"uuid": "cc005f24-8e90-4c6c-80aa-661538dfcfbd",
|
||||
"type": "sprite",
|
||||
"wrapMode": "clamp",
|
||||
"filterMode": "bilinear",
|
||||
"subMetas": {
|
||||
"home1": {
|
||||
"ver": "1.0.3",
|
||||
"uuid": "8c081859-7885-43ad-a1fe-2a87bcc7d45e",
|
||||
"rawTextureUuid": "cc005f24-8e90-4c6c-80aa-661538dfcfbd",
|
||||
"trimType": "auto",
|
||||
"trimThreshold": 1,
|
||||
"rotated": false,
|
||||
"offsetX": 0,
|
||||
"offsetY": 0,
|
||||
"trimX": 2,
|
||||
"trimY": 2,
|
||||
"width": 2028,
|
||||
"height": 1919,
|
||||
"rawWidth": 2032,
|
||||
"rawHeight": 1923,
|
||||
"borderTop": 0,
|
||||
"borderBottom": 0,
|
||||
"borderLeft": 0,
|
||||
"borderRight": 0,
|
||||
"subMetas": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
TurntableDemo/assets/Texture/singleColor.png
Normal file
BIN
TurntableDemo/assets/Texture/singleColor.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
30
TurntableDemo/assets/Texture/singleColor.png.meta
Normal file
30
TurntableDemo/assets/Texture/singleColor.png.meta
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"ver": "2.0.0",
|
||||
"uuid": "a8027877-d8d6-4645-97a0-52d4a0123dba",
|
||||
"type": "sprite",
|
||||
"wrapMode": "clamp",
|
||||
"filterMode": "bilinear",
|
||||
"subMetas": {
|
||||
"singleColor": {
|
||||
"ver": "1.0.3",
|
||||
"uuid": "410fb916-8721-4663-bab8-34397391ace7",
|
||||
"rawTextureUuid": "a8027877-d8d6-4645-97a0-52d4a0123dba",
|
||||
"trimType": "auto",
|
||||
"trimThreshold": 1,
|
||||
"rotated": false,
|
||||
"offsetX": 0,
|
||||
"offsetY": 0,
|
||||
"trimX": 0,
|
||||
"trimY": 0,
|
||||
"width": 2,
|
||||
"height": 2,
|
||||
"rawWidth": 2,
|
||||
"rawHeight": 2,
|
||||
"borderTop": 0,
|
||||
"borderBottom": 0,
|
||||
"borderLeft": 0,
|
||||
"borderRight": 0,
|
||||
"subMetas": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
24149
TurntableDemo/creator.d.ts
vendored
Normal file
24149
TurntableDemo/creator.d.ts
vendored
Normal file
File diff suppressed because it is too large
Load Diff
15
TurntableDemo/jsconfig.json
Normal file
15
TurntableDemo/jsconfig.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es6",
|
||||
"module": "commonjs",
|
||||
"experimentalDecorators": true
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
".vscode",
|
||||
"library",
|
||||
"local",
|
||||
"settings",
|
||||
"temp"
|
||||
]
|
||||
}
|
||||
4
TurntableDemo/project.json
Normal file
4
TurntableDemo/project.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"engine": "cocos2d-html5",
|
||||
"packages": "packages"
|
||||
}
|
||||
13
TurntableDemo/settings/builder.json
Normal file
13
TurntableDemo/settings/builder.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"excludeScenes": [],
|
||||
"orientation": {
|
||||
"landscapeLeft": true,
|
||||
"landscapeRight": true,
|
||||
"portrait": false,
|
||||
"upsideDown": false
|
||||
},
|
||||
"packageName": "org.cocos2d.helloworld",
|
||||
"startScene": "2d2f792f-a40c-49bb-a189-ed176a246e49",
|
||||
"title": "hello_world",
|
||||
"webOrientation": "auto"
|
||||
}
|
||||
7
TurntableDemo/settings/builder.panel.json
Normal file
7
TurntableDemo/settings/builder.panel.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"excludeScenes": [],
|
||||
"packageName": "org.cocos2d.helloworld",
|
||||
"platform": "web-mobile",
|
||||
"startScene": "2d2f792f-a40c-49bb-a189-ed176a246e49",
|
||||
"title": "HelloWorld"
|
||||
}
|
||||
28
TurntableDemo/settings/project.json
Normal file
28
TurntableDemo/settings/project.json
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"collision-matrix": [
|
||||
[
|
||||
true
|
||||
]
|
||||
],
|
||||
"excluded-modules": [],
|
||||
"group-list": [
|
||||
"default"
|
||||
],
|
||||
"start-scene": "current",
|
||||
"design-resolution-width": 960,
|
||||
"design-resolution-height": 640,
|
||||
"fit-width": false,
|
||||
"fit-height": true,
|
||||
"use-project-simulator-setting": false,
|
||||
"simulator-orientation": false,
|
||||
"use-customize-simulator": false,
|
||||
"simulator-resolution": {
|
||||
"width": 960,
|
||||
"height": 640
|
||||
},
|
||||
"cocos-analytics": {
|
||||
"enable": false,
|
||||
"appID": "13798",
|
||||
"appSecret": "959b3ac0037d0f3c2fdce94f8421a9b2"
|
||||
}
|
||||
}
|
||||
BIN
TurntableDemo/template-banner.png
Normal file
BIN
TurntableDemo/template-banner.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
5
TurntableDemo/template.json
Normal file
5
TurntableDemo/template.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "TEMPLATES.helloworld.name",
|
||||
"desc": "TEMPLATES.helloworld.desc",
|
||||
"banner": "template-banner.png"
|
||||
}
|
||||
Reference in New Issue
Block a user