添加一个使用碰撞系统实现的触摸or选择poker的demo

This commit is contained in:
leo
2019-04-14 22:10:52 +08:00
parent 36bce9e7ac
commit 42789fdac9
28 changed files with 26469 additions and 0 deletions

67
TouchPointDemo/.gitignore vendored Normal file
View 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/

54
TouchPointDemo/README.md Normal file
View File

@@ -0,0 +1,54 @@
# TouchPointDemo
> 使用collision来实现触摸系统,
### 环境
* creator 2.0.6
### 介绍
例子使用碰撞系统
* 设置碰撞分组 [官方教程](https://docs.cocos.com/creator/manual/zh/physics/collision/collision-group.html)
![image.png](https://upload-images.jianshu.io/upload_images/2315803-2ac2b9ae0bb392f2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* 设置碰撞大小 [官方教程](https://docs.cocos.com/creator/manual/zh/physics/collision/edit-collider-component.html)
![image.png](https://upload-images.jianshu.io/upload_images/2315803-aea4315bd9a4f9ec.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* 脚本设置碰撞事件 [官方教程](https://docs.cocos.com/creator/manual/zh/physics/collision/collision-manager.html)
~~~
/**
* 当碰撞产生的时候调用
* @param {Collider} other 产生碰撞的另一个碰撞组件
* @param {Collider} self 产生碰撞的自身的碰撞组件
*/
onCollisionEnter(other: cc.BoxCollider, self: cc.BoxCollider) {
console.log('on collision enter');
console.log(other, self);
let node = self.node;
this.isSelect = !this.isSelect;
if (this.isSelect) {
node.color = new cc.Color().fromHEX('#D8D8D8');
} else {
node.color = new cc.Color().fromHEX('#FFFFFF');
}
}
/**
* 当碰撞产生后,碰撞结束前的情况下,每次计算碰撞结果后调用
* @param {Collider} other 产生碰撞的另一个碰撞组件
* @param {Collider} self 产生碰撞的自身的碰撞组件
*/
onCollisionStay(other: cc.BoxCollider, self: cc.BoxCollider) {
console.log('on collision stay');
}
/**
* 当碰撞结束后调用
* @param {Collider} other 产生碰撞的另一个碰撞组件
* @param {Collider} self 产生碰撞的自身的碰撞组件
*/
onCollisionExit(other: cc.BoxCollider, self: cc.BoxCollider) {
console.log('on collision exit');
}
~~~
* 对node选择碰撞分组
![](https://upload-images.jianshu.io/upload_images/2315803-80de7cbc1a9f9930.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
### 最后
介绍完了,放出一个例子。给大家参考~

View File

@@ -0,0 +1,6 @@
{
"ver": "1.0.1",
"uuid": "29f52784-2fca-467b-92e7-8fd9ef8c57b7",
"isGroup": false,
"subMetas": {}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
{
"ver": "1.0.0",
"uuid": "2d2f792f-a40c-49bb-a189-ed176a246e49",
"asyncLoadAssets": false,
"autoReleaseAssets": false,
"subMetas": {}
}

View File

@@ -0,0 +1,6 @@
{
"ver": "1.0.1",
"uuid": "4734c20c-0db8-4eb2-92ea-e692f4d70934",
"isGroup": false,
"subMetas": {}
}

View File

@@ -0,0 +1,10 @@
const { ccclass, property } = cc._decorator;
@ccclass
export default class Helloworld extends cc.Component {
start() {
// 开启碰撞检测系统,未开启时无法检测
cc.director.getCollisionManager().enabled = true;
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "e1b90feb-a217-4493-849d-9a611900d683",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,74 @@
const { ccclass, property } = cc._decorator;
@ccclass
export default class TouchArea extends cc.Component {
// LIFE-CYCLE CALLBACKS:
@property(cc.Node)
point: cc.Node = null;
private canvas: cc.Node;
onLoad() {
this.canvas = cc.find('Canvas');
this.setPointOut();
}
setPointOut() {
this.point.setPosition(-1000, -1000);
}
onEnable() {
this.node.on('touchstart', this.onTouchStart, this);
this.node.on('touchmove', this.onTouchMove, this);
this.node.on('touchend', this.onTouchEnd, this);
this.node.on('touchcancel', this.onTouchCancel, this);
}
onTouchStart(touch: cc.Touch) {
let pos = touch.getLocation();
// console.log('onTouchStart', ' touch=', pos);
let vec2 = this.worldConvertLocalPointAR(this.canvas, pos);
this.point.setPosition(vec2);
}
onTouchMove(touch: cc.Touch) {
let pos = touch.getLocation();
// console.log('onTouchMove', 'touch=', pos);
let vec2 = this.worldConvertLocalPointAR(this.canvas, pos);
this.point.setPosition(vec2);
}
onTouchEnd(touch: cc.Touch) {
let pos = touch.getLocation();
// console.log('onTouchEnd', 'touch=', pos);
this.setPointOut();
}
onTouchCancel(touch: cc.Touch) {
let pos = touch.getLocation();
// console.log('onTouchCancel', 'touch=', pos);
this.setPointOut();
}
worldConvertLocalPointAR(node: cc.Node, vec2) {
if (node) {
return node.convertToNodeSpaceAR(vec2);
}
return new cc.Vec2(0, 0);
}
onDisable() {
this.node.off('touchstart', this.onTouchStart, this);
this.node.off('touchmove', this.onTouchMove, this);
this.node.off('touchend', this.onTouchEnd, this);
this.node.off('touchcancel', this.onTouchCancel, this);
}
// update (dt) {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "27effc3c-f64a-4422-beed-b65caf529324",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,57 @@
const { ccclass, property } = cc._decorator;
@ccclass
export default class TouchPoker extends cc.Component {
// LIFE-CYCLE CALLBACKS:
private isSelect = false;
onEnable() {
this.isSelect = false;
}
onLoad() {
}
start() {
}
/**
* 当碰撞产生的时候调用
* @param {Collider} other 产生碰撞的另一个碰撞组件
* @param {Collider} self 产生碰撞的自身的碰撞组件
*/
onCollisionEnter(other: cc.BoxCollider, self: cc.BoxCollider) {
console.log('on collision enter');
console.log(other, self);
let node = self.node;
this.isSelect = !this.isSelect;
if (this.isSelect) {
node.color = new cc.Color().fromHEX('#D8D8D8');
} else {
node.color = new cc.Color().fromHEX('#FFFFFF');
}
}
/**
* 当碰撞产生后,碰撞结束前的情况下,每次计算碰撞结果后调用
* @param {Collider} other 产生碰撞的另一个碰撞组件
* @param {Collider} self 产生碰撞的自身的碰撞组件
*/
onCollisionStay(other: cc.BoxCollider, self: cc.BoxCollider) {
console.log('on collision stay');
}
/**
* 当碰撞结束后调用
* @param {Collider} other 产生碰撞的另一个碰撞组件
* @param {Collider} self 产生碰撞的自身的碰撞组件
*/
onCollisionExit(other: cc.BoxCollider, self: cc.BoxCollider) {
console.log('on collision exit');
}
// update (dt) {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "7f2ad2de-103b-4464-980a-3fc15bf5049b",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,6 @@
{
"ver": "1.0.1",
"uuid": "7b81d4e8-ec84-4716-968d-500ac1d78a54",
"isGroup": false,
"subMetas": {}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@@ -0,0 +1,31 @@
{
"ver": "2.2.0",
"uuid": "2d957df4-cc1f-48d9-b0f1-e68636f4569e",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"subMetas": {
"3heitao": {
"ver": "1.0.3",
"uuid": "b43bd92a-fc5e-4cdd-9b89-aa16f418ed4b",
"rawTextureUuid": "2d957df4-cc1f-48d9-b0f1-e68636f4569e",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 155,
"height": 216,
"rawWidth": 155,
"rawHeight": 216,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

View File

@@ -0,0 +1,31 @@
{
"ver": "2.2.0",
"uuid": "6aa0aa6a-ebee-4155-a088-a687a6aadec4",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"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": {}
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@@ -0,0 +1,31 @@
{
"ver": "2.2.0",
"uuid": "a8027877-d8d6-4645-97a0-52d4a0123dba",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"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": {}
}
}
}

24453
TouchPointDemo/creator.d.ts vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,15 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"experimentalDecorators": true
},
"exclude": [
"node_modules",
".vscode",
"library",
"local",
"settings",
"temp"
]
}

View File

@@ -0,0 +1,4 @@
{
"engine": "cocos2d-html5",
"packages": "packages"
}

View File

@@ -0,0 +1,47 @@
{
"android-instant": {
"REMOTE_SERVER_ROOT": "",
"host": "",
"pathPattern": "",
"recordPath": "",
"scheme": "https",
"skipRecord": false
},
"appKey": "",
"appSecret": "",
"encryptJs": true,
"excludeScenes": [],
"fb-instant-games": {},
"includeAnySDK": false,
"includeSDKBox": false,
"inlineSpriteFrames": true,
"inlineSpriteFrames_native": true,
"jailbreakPlatform": false,
"md5Cache": false,
"mergeStartScene": false,
"oauthLoginServer": "",
"optimizeHotUpdate": false,
"orientation": {
"landscapeLeft": true,
"landscapeRight": true,
"portrait": false,
"upsideDown": false
},
"packageName": "org.cocos2d.helloworld",
"privateKey": "",
"qqplay": {
"REMOTE_SERVER_ROOT": "",
"orientation": "portrait"
},
"startScene": "2d2f792f-a40c-49bb-a189-ed176a246e49",
"title": "hello_world",
"webOrientation": "auto",
"wechatgame": {
"REMOTE_SERVER_ROOT": "",
"appid": "wx6ac3f5090a6b99c5",
"orientation": "portrait",
"subContext": ""
},
"xxteaKey": "4beb14fe-5f38-43",
"zipCompressJs": true
}

View File

@@ -0,0 +1,7 @@
{
"excludeScenes": [],
"packageName": "org.cocos2d.helloworld",
"platform": "web-mobile",
"startScene": "2d2f792f-a40c-49bb-a189-ed176a246e49",
"title": "HelloWorld"
}

View File

@@ -0,0 +1,60 @@
{
"cocos-analytics": {
"appID": "13798",
"appSecret": "959b3ac0037d0f3c2fdce94f8421a9b2",
"channel": "",
"enable": false,
"version": ""
},
"collision-matrix": [
[
false
],
[
false,
false,
true
],
[
false,
true,
false,
true
],
[
false,
false,
true,
false
]
],
"design-resolution-height": 640,
"design-resolution-width": 960,
"excluded-modules": [],
"facebook": {
"appID": "",
"audience": {
"enable": false
},
"enable": false,
"live": {
"enable": false
}
},
"fit-height": true,
"fit-width": false,
"group-list": [
"default",
"point",
"poker",
"pokerBoard"
],
"last-module-event-record-time": 0,
"simulator-orientation": false,
"simulator-resolution": {
"height": 640,
"width": 960
},
"use-customize-simulator": false,
"use-project-simulator-setting": false
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

View File

@@ -0,0 +1,5 @@
{
"name": "TEMPLATES.helloworld-ts.name",
"desc": "TEMPLATES.helloworld-ts.desc",
"banner": "template-banner.png"
}

View File

@@ -0,0 +1,18 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [ "dom", "es5", "es2015.promise" ],
"target": "es5",
"allowJs": true,
"experimentalDecorators": true,
"skipLibCheck": true
},
"exclude": [
"node_modules",
"library",
"local",
"temp",
"build",
"settings"
]
}