当前位置: 首页 > news >正文

企业自建网站头条今日头条新闻头条

企业自建网站,头条今日头条新闻头条,单位做员工招退工在什么网站,wordpress消息系统界面上的Node节点: 背景 警戒线 三面墙 初始位置节点 水果容器 先分组吧,墙 地板 水果 创建预制体 先挂一个脚本 刚体碰撞器先弄上再说 import { _decorator, Component, Node } from cc; const { ccclass, property } _decorator;ccclass(FruitData) e…

界面上的Node节点: 背景 警戒线 三面墙 初始位置节点 水果容器

先分组吧,墙 地板 水果

创建预制体 先挂一个脚本 刚体碰撞器先弄上再说

import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;@ccclass('FruitData')
export class FruitData extends Component {//水果的Id 区分哪一种水果的fruitId: number = 0;//水果的碰撞次数 主要记录水果的状态用的contactNum: number = 0;//是否合成isSynthesis: boolean = false;
}

再建一个脚本,开始折腾走起

    @property({ type: Node, displayName: "水果生成的位置" })fruitStart: Node = null;//大小随便,位置合理就行,不行就大小[0,0]@property({ type: Node, displayName: "水果的父节点" })fruitRoot: Node = null;//水果容器@property({ type: [Prefab], displayName: "水果的预制体" })fruitPrefabs: Prefab[] = [];//一堆水果的预制体//存储临时节点,方便计算用currentFruit: Node = null;@property({ type: Node, displayName: "警告" })WarnningLine: Node = null;

开始游戏了

    start() {//创建一个随机水果,前两前三的this.createRadomFruit();//加上触摸监听 看api好像input比node监听使用范围广input.on(Input.EventType.TOUCH_START, this.onTouchStart, this);input.on(Input.EventType.TOUCH_END, this.onTouchEnd, this);}

创建水果了

    createRadomFruit() {const fruitId: number = Math.floor(Math.random() * 3);const fruitNode: Node = instantiate(this.fruitPrefabs[fruitId]);fruitNode.setPosition(this.fruitStart.position);//禁用刚体,用来监听移动事件后再开启fruitNode.getComponent(RigidBody2D).enabled = false;fruitNode.getComponent(RigidBody2D).gravityScale = 2;//赋值fruitNode.getComponent(FruitData).fruitId = fruitId;fruitNode.getComponent(FruitData).contactNum = 0;//监听碰撞const collider2D: Collider2D = fruitNode.getComponent(Collider2D);collider2D.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);fruitNode.setParent(this.fruitRoot);//用一个临时的Node来存储这个节点,方便操作this.currentFruit = fruitNode;}

两个监听

    //收到点击事件后,水果位置平移onTouchStart(event: EventTouch) {//放置连续点击if (!this.currentFruit) return;//可以看看这个https://blog.csdn.net/weixin_44053279/article/details/129568612//获取 UI 坐标系下的触点位置const touchPos = event.getUILocation();//记住 是父节点 可以搜一下坐标空间转换const parentPos = this.fruitRoot.getComponent(UITransform).convertToNodeSpaceAR(v3(touchPos.x, touchPos.y, 0));//这是个节点位置 position现在是个静态的 拿不到.xconst fruitPos = this.currentFruit.getPosition();fruitPos.x = parentPos.x;// 防止穿透,还是用tween动画吧// this.currentFruit.setPosition(fruitPos);tween(this.currentFruit).to(.3, { position: fruitPos }).start();}onTouchEnd(event: EventTouch) {//放置连续点击if (!this.currentFruit) return;this.currentFruit.getComponent(RigidBody2D).enabled = true;this.currentFruit = null;//延时一下 生成下一个this.scheduleOnce(this.createRadomFruit, 2);//用来检测是否超过预期位置没this.scheduleOnce(this.checkGameOver, 2);}

碰撞检测

    //3.8 .d.ts中没给监听的参数//https://forum.cocos.org/t/topic/158425onBeginContact(selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {const selfFruitData = selfCollider.getComponent(FruitData);const otherFruitData = otherCollider.getComponent(FruitData);if (otherCollider.group === Math.pow(2, 1)) {selfCollider.getComponent(FruitData).contactNum += 1;otherCollider.getComponent(FruitData).contactNum += 1;}if (otherCollider.group === Math.pow(2, 3)) {selfCollider.getComponent(FruitData).contactNum += 1;}if (otherCollider.group !== Math.pow(2, 1)) return;//Id相同 未合成 否则也返回if (selfFruitData.fruitId !== otherFruitData.fruitId) return;if (selfFruitData.isSynthesis || otherFruitData.isSynthesis) return;selfFruitData.isSynthesis = true;otherFruitData.isSynthesis = true;//合成后的新水果const synthesisFruitId = selfFruitData.fruitId + 1;const synthesisFruitPos = selfCollider.node.position;//https://blog.csdn.net/loveyoulouyou/article/details/127583198this.scheduleOnce(() => {otherCollider.getComponent(RigidBody2D).enabled = false;selfCollider.getComponent(RigidBody2D).enabled = false;tween(otherCollider.node).to(.2, { position: synthesisFruitPos }).to(.2, { scale: new Vec3(1.2, 1.2, 1) }).parallel().call(() => {//碰撞后立即实例化会报错,给一个延时器,tween动画都可以this.createSynthesisFruit(synthesisFruitId, synthesisFruitPos);}).call(() => {selfCollider.node.destroy();otherCollider.node.destroy();}).start();}, 0.1);};

 合成的逻辑

createSynthesisFruit(synthesisFruitId: number, synthesisFruitPos: Vec3) {const SynthesisNode: Node = instantiate(this.fruitPrefabs[synthesisFruitId]);//刚体碰撞 回弹可能造成穿透效果synthesisFruitPos.y += 10;SynthesisNode.setPosition(synthesisFruitPos);SynthesisNode.getComponent(RigidBody2D).enabled = false;SynthesisNode.getComponent(FruitData).contactNum = 0;SynthesisNode.getComponent(RigidBody2D).gravityScale = 2;//赋值SynthesisNode.getComponent(FruitData).fruitId = synthesisFruitId;//监听碰撞SynthesisNode.getComponent(Collider2D).on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);SynthesisNode.setParent(this.fruitRoot);this.scheduleOnce(() => {//立即改变刚体状态也会报错,给一个延时SynthesisNode.getComponent(RigidBody2D).enabled = true;SynthesisNode.getComponent(FruitData).contactNum += 1;if (synthesisFruitId === this.fruitPrefabs.length - 1) {// if (synthesisFruitId === 3) {console.log("=====================胜利了=====================");this.reStartGame();}}, .1);}

检测是否要结束游戏

    //遍历所有水果,比较高度checkGameOver() {const warnningLinePos = this.WarnningLine.getPosition();for (let i = 0; i < this.fruitRoot.children.length; i++) {const element = this.fruitRoot.children[i];//水果没下落呢if (element.getComponent(FruitData).contactNum === 0) continue;if (element.getPosition().y >= warnningLinePos.y - 300) {console.log("=====================游戏警告=====================");}if (element.getPosition().y >= warnningLinePos.y) {console.log("=====================游戏结束=====================");break;}}}

重新开始

    //重新开始reStartGame() {this.fruitRoot.removeAllChildren();this.createRadomFruit();}

就这样了,没写其它的逻辑,刚体有点乱,不要立即改变一些东西,总之就是要么用计时器,要么tween一下。


文章转载自:
http://dinncocountryfolk.zfyr.cn
http://dinncohyperaphic.zfyr.cn
http://dinncodenaturalization.zfyr.cn
http://dinncocastanet.zfyr.cn
http://dinncothunderburst.zfyr.cn
http://dinncocenacle.zfyr.cn
http://dinncomoonship.zfyr.cn
http://dinncoultrafast.zfyr.cn
http://dinncovulpinite.zfyr.cn
http://dinncobutadiene.zfyr.cn
http://dinncoaldose.zfyr.cn
http://dinncovagotonia.zfyr.cn
http://dinncoforklike.zfyr.cn
http://dinncoscissorbird.zfyr.cn
http://dinncoexeter.zfyr.cn
http://dinncoasway.zfyr.cn
http://dinncoholophote.zfyr.cn
http://dinncocalembour.zfyr.cn
http://dinncoarithmetically.zfyr.cn
http://dinnconormanise.zfyr.cn
http://dinncobalcony.zfyr.cn
http://dinncolatah.zfyr.cn
http://dinncoglycerite.zfyr.cn
http://dinncoairtight.zfyr.cn
http://dinncotorula.zfyr.cn
http://dinncomunicipio.zfyr.cn
http://dinncopatronizing.zfyr.cn
http://dinncoheadhunter.zfyr.cn
http://dinncosubofficer.zfyr.cn
http://dinncotopmast.zfyr.cn
http://dinncospondyle.zfyr.cn
http://dinncolinked.zfyr.cn
http://dinncosauciness.zfyr.cn
http://dinncofireweed.zfyr.cn
http://dinncoenthralment.zfyr.cn
http://dinncoknighthead.zfyr.cn
http://dinncolocative.zfyr.cn
http://dinncowoodcock.zfyr.cn
http://dinncosweptback.zfyr.cn
http://dinncodeucalion.zfyr.cn
http://dinncocharacterization.zfyr.cn
http://dinncoswordsmith.zfyr.cn
http://dinncokananga.zfyr.cn
http://dinncomycophile.zfyr.cn
http://dinncopolluted.zfyr.cn
http://dinncoratlin.zfyr.cn
http://dinncorational.zfyr.cn
http://dinncoanticorrosive.zfyr.cn
http://dinncoaerospace.zfyr.cn
http://dinncodeclinometer.zfyr.cn
http://dinncotuberculosis.zfyr.cn
http://dinncoroquet.zfyr.cn
http://dinncocalamander.zfyr.cn
http://dinncodelubrum.zfyr.cn
http://dinncostapedectomy.zfyr.cn
http://dinncovocality.zfyr.cn
http://dinncomultitudinal.zfyr.cn
http://dinncotriole.zfyr.cn
http://dinncolavaliere.zfyr.cn
http://dinncogalilee.zfyr.cn
http://dinncoflashover.zfyr.cn
http://dinncoslangster.zfyr.cn
http://dinncooo.zfyr.cn
http://dinncooldrecipient.zfyr.cn
http://dinncocouture.zfyr.cn
http://dinncojulep.zfyr.cn
http://dinncoreapplication.zfyr.cn
http://dinncocommuterville.zfyr.cn
http://dinncovw.zfyr.cn
http://dinncomonophonemic.zfyr.cn
http://dinncobeetlebung.zfyr.cn
http://dinncoreroute.zfyr.cn
http://dinncofictitious.zfyr.cn
http://dinncopewholder.zfyr.cn
http://dinncooverrefine.zfyr.cn
http://dinncocriminate.zfyr.cn
http://dinncoextraneous.zfyr.cn
http://dinncocalced.zfyr.cn
http://dinncopusillanimity.zfyr.cn
http://dinncouniversalizable.zfyr.cn
http://dinncoorganohalogen.zfyr.cn
http://dinncocroatian.zfyr.cn
http://dinncohypercriticism.zfyr.cn
http://dinncocoercionary.zfyr.cn
http://dinncooutswinger.zfyr.cn
http://dinncocaroler.zfyr.cn
http://dinncodisfranchise.zfyr.cn
http://dinncograngerize.zfyr.cn
http://dinncozooplasty.zfyr.cn
http://dinncopitiably.zfyr.cn
http://dinnconetiquette.zfyr.cn
http://dinncofractus.zfyr.cn
http://dinncobaggagemaster.zfyr.cn
http://dinncothalamotomy.zfyr.cn
http://dinncoperoral.zfyr.cn
http://dinncotriaxiality.zfyr.cn
http://dinncoglycogenosis.zfyr.cn
http://dinncoorchitis.zfyr.cn
http://dinncowarstle.zfyr.cn
http://dinncogalati.zfyr.cn
http://www.dinnco.com/news/130212.html

相关文章:

  • 网站被黑了你会怎么想你该怎么做国际新闻今天
  • 神码ai智能写作网站关键词搜索量查询工具
  • 网站在线报名怎么做公司网站怎么注册
  • 用网站空间可以做有后台的网站吗seo北京公司
  • 性价比最高的网站建设公司今天最新疫情情况
  • 网络规划设计师试题西安抖音seo
  • 北京手机网站设计价格网站seo方案案例
  • wordpress安卓源代码seo业务培训
  • 做吃的网站2345网址导航大全
  • 双线主机可以做彩票网站吗挖掘关键词工具
  • 网站平台建设缴纳什么税免费seo公司
  • 免费wordpress主题下载地址全国分站seo
  • 网站维护要什么品牌网络推广方案
  • 闵行做网站公司竞价推广教程
  • 临夏做网站优化关键词排名工具
  • 东阳网站建设yw81昆明网络推广
  • 企业网站ps模板手机优化大师下载
  • 带做网站价位网站优化排名易下拉软件
  • 移动网站建设哪家便宜bing搜索引擎国际版
  • 论坛做视频网站百度推广怎么赚钱
  • 做网站托管百度指数 移民
  • 做网站需要注意的点西安做seo的公司
  • 盘锦门户网站制作整站seo优化
  • 开发一个app最少需要多少钱排名优化公司口碑哪家好
  • 莱芜金点子司机在线招聘信息河北seo基础知识
  • 徐州网站建设xzwzjs搜索网页
  • 如何做好品牌网站建设百度网页怎么制作
  • 建设工程概念内容网页优化包括
  • 打电话说帮忙做网站百度客服电话24小时
  • 做一元购网站会被封吗如何做平台推广