Cocos2d-x   发布时间:2022-05-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Cocos2d-android 学习笔记大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
/*

SurfaceView 
	getHolder() -->SurfaceHolder

SurfaceHolder 代理者 代理Surface完成界面相关的操作
	getSurface
	lockCanvas()
	unlockCanvasAndPost(Canvas C) 放在finally块中
	


Surface
	lockCanvas()
	lockCanvas(Rect dirty) --> Canvas 锁定一个矩形区域当作画布
	                                  花东西
	unlockCanvas(Canvas C)		  解锁,更新界面

	
FPS : 帧率  >=30 性能的最低要求

Point  
	x   y  
 
CopyOnWriteList

Rect 
	contain(x,y)

Cocos2d_Android

CCDirector  管理场景  与SurfaceView 打交道 derived from CCDirector.sharedDirector()
	attachInView() 开启绘制线程 
	runWithScene(scenE)
	replaceScene(scenE)
	setDisplayFPS(true)
	onResume() onPause() end()
	setDeviceOrientation(CCDirector.kCCDiviceOrientation...)
	setScreenSize(x,y); 480 320
	getWinSize()
	


CCSecene  derived from CCSecene.node()

	addChild(layer)  把树根与树枝连在一起
	作为parents存在


在一个场景所以的CCLayer中,有且只有一个CCLayer可以处理touch事件
CCLayer  extends CCNode implements CCTouchDelegateProtocol
	addChild(leaf)
	setScaleX() setScaleY()  setScale() 

	setIsTouchEnabled(true)
	主要处理 CCTouchDelegateProtocol 里面的方法
	ccTouchesBegan() 按下 
	ccTouchesMoved()
	ccTouchesCancel

	convertTouchToNodeSpace(MotionEvent)
	

	坐标原点在左下角
	图片的锚点 默认在图片的中心

	setAnchorPoint(0,0)
	坐标的计算越简单越好

	图片位置的确定 结合锚点和坐标综合定位

CCSprite  derived from CCSprite.sprite(filepath)  assets文件夹上的图片资源
	setFlipX(true) 在x轴上的镜像
	setPosition(CGPoint) CGPoint deprived from CGPoint.ccp(x,y);
	
	addChild() 按照添加的顺序决定显示的优先级 默认后添加的优先级高
	addChild(child,priority);priority表示在z轴的位置
	addChild(child,priority,tag);priority表示在z轴的位置
	getChildByTag();
	getBoundingBox()-->CGRect
	serOpacity(0--255)
	setVisible()
	removeSelf();
	runAction()
	stopAllActions()
	
	--CCLabel --> CCLabel.makeLable(text,font,fontsizE);  .ttf 放置于assets目录下
		setColor(color)
	


fps_images.png cocos2d需要的图片  所以要把这张图片放在自己的assets目录下

CCNode 

CGRect  static containsPoint(aRect,Point)

CCAction 
	--CCFiniteTimeAction 受时间限制的动作

		--CCInstantAction 瞬时当作

		--CCIntervalAction 瞬时当作

			--CCMoveTo derived from CCMoveTo.action(float time,CGPoint pos)

			--CCMoveBy derived from CCMoveBy.action(float time,CGPoint pos) 相对移动
				reverse();
			CCSequence CCSequence.actions(...actions)
			
			--CCJumpBy -->CCJumpBy.action(time,goal_position,height,jumps)height实际的最高点

			--CCBezierBy -->CCBezierBy.action(time,CCBezierConfig)  
				CCBezierConfig.centrolPoint_1  CCBezierConfig.centrolPoint_2(最高点) CCBezierConfig.endPosition

			--CCEaseAction 
				--CCEaseIn-->CCEaseIn.action(action,ratE) 加速
				--CCEaseOut-->CCEaseIn.reverse()
			
			--CCScaleBy -->CCScaleBy.action(int time,int scalE); scale 缩放的比例

			--CCRotateBy --> CCRotateBy.action(time,anglE) 总是顺时针
			--CCRotateTo --> CCRotateTo.action(time,anglE) >180 逆时针转 偷懒
			--CCTintBy (颜色渐变) CCTintBy.action(time,color) ccColor3B-->ccColor3B.ccc(r,g,b)
			--CCBlink  (闪烁动画) CCBlink.action(time,blinkTimes)
			--CCHide --> CCHide.action();
			--CCShow --> CCShow.action();
			CCDelayTime() 停歇动画
			起点 终点 时间间隔 

	以下三个都不受时间限制
	--CCFollow  跟着一个CCNode 跑  layer follow a hero 

	--CCRepeatForever 应用场景 行走的序列帧播放
		CCRepeatForever.action(action)

	--CCSpeed 游戏速度的控制 


当作组合  串联当作
	CCSpawn --> CCSpawn.actions(actions,params) actions 串联 一个或多个params 
		reverse()


地图的制作
	.tmx
	图片要用相对路径
	name must be English
	对象层的数据存储需要注意顺序
	
	地图的加载
	CCTMXTiledMap --> CCTMXTiledMap.tiledMap(tmxFilE) tmxFile in assets

	地图解析
	CCTMXObjectGroup -->CCTMXTiledMap.objectGroupName(Name)
		objects --> ArrayList<HashMap<String,String>>

	CCCallFunc-->CCCallFunc.action(target,SELEctor) target.getClass().getMethod(SELEctor) public method
	CGPointUtil.distance(pos1,pos2)

序列帧的播放
	CCAnimate -->CCAnimate.action(CCAnimation anim)
	CCAnimation --> CCAnimation.animation(name,delay,ArrayList<CCSpriteFrame> frames)
	CCSpriteFrame --> CCSprite.sprite(filepath).displayFrame()

	String filename = "z_0%d.png"  String.foormat(filename,num);
	String filename = "z_%02d.png" (1--99) String.foormat(filename,num);

粒子系统  
	CCParticleSystem --> 
		--CCParticlesnow  -->CCParticlesnow.node();
			setTexture(CCTextureCache.sharedTextureCache().addImage(imgUrl))  in assets
			stopSystem()
	ParticleDesigner   .plist

声音引擎 
	音乐+音效 MediaPlayer + SoundPool

	SoundENGIne-->sharedSoundENGIne()
		playSound(ctxt,resID,isLoop)

地图移动
	大地图移动 
		CCFollow   CCFollow action follow hero
			action(CCNodE)  
	小地图的移动
		setIsTouchEnable(true)
		override ccTouchesMoved(MotionEvent event)
			gameMap.touch
	如果需要手动移动地图 必须将地图的锚点设置成中心点 修改地图的坐标(中心)
	
	gameMap.getContentSize() -->CGSize
	gameMap.addChild(spritE) 将地图和精灵绑在一起
	gameMap.getParent() -->layer
	

游戏暂停
	主layer DemoLayer 和 处理的暂停的layer PauseLayer

	override ccTouchBegan()-->显示暂停layer 冻结主layer 
	
	关于暂停layer的添加 必须添加到场景中
	
	this.getParent.addChild()  this-->主layer
	this.onExit();

	游戏继续
	PauseLayer.removeSelf()
	DemoLayer.this.onEnter()

	
植物VS僵尸
	展示logo 停顿一会 隐藏logo 停顿一会
	背景图片加载 进度条处理
	耗时操作: 访问网络 版本检测 预加载图片 预加载声音文件


欢迎界面 
	展示FPS  引入图片(切记) 设置屏幕方向 设置屏幕大小 activity全屏

	CCAnimate.action(animation,Boolean stroE); 第二个参数取false 表示只播放一次序列帧
	Layer.getChildByTag()

界面切换
	切换场景
	淡入淡出 CCFadeTransition.transition(time,CCScenE);	
	derector.replaceScene(transition)

菜单操作
	CCMenu -->CCMenu.menu();
		--addChild(CCMenuItemSprite item)
	CCMenuItemSprite  --> CCMenuItemSprite.item(CCNode normalSprite,CCNode SELEctedSprite,CCNode target,String SELEctor); public void SELEctor(Obect o) 要加参数 指明哪个精灵被激活了
	
	
地图展示(不能处理用户touch)
	展示对战对图(展示时间)--> 加载展示用的僵尸(展示用的点位) --> 移动地图(停留一会) --> 展示两个容器
	
植物选择(处理用户touch)
	加载玩家已经获取到的植物信息 --> 选择植物 --> 取消植物 --> 点击一起摇滚
	
游戏开始前的准备工作(不能处理用户touch) 
	回收玩家已有的植物容器 --> 移动地图 --> 回收展示用的僵尸 --> 播放序列帧: 准备 安放 植物
	
对战处理(处理用户touch)
	
	对战处理 用户可以touch
	对战元素分析+战场划分
	公共部分+分支
	公共部分:元素创建+元素的销毁及存活过程中的动作信息+死亡监听
		分支处理: 植物+僵尸+产物
			植物
				生产型植物+攻击型植物+防御型植物
				向日葵 普通豌豆射手 坚果墙
			僵尸: 
				按等级划分 初级僵尸 终极僵尸
			产物: 
				子弹+阳光
	
	添加僵尸 (集合)
		lineNum * 2  是起点 lineNum * 2 + 1 是终点

	安放僵尸
	僵尸攻击植物 (判断当前所在的块内是否有植物)
		记录僵尸的工作状态 Boolean
		如果僵尸正在攻击 
		停止僵尸所有的动作
		播放僵尸攻击的序列帧
		造成植物的持续性杀伤
		

	植物攻击僵尸   攻击型植物的集合 + 僵尸的集合中是否有僵尸

	辅助功能
		阳关管理
		游戏进度:游戏的整体进度(植物冷冻 整体进度)


	安放植物 
		位置计算 ( 16 + ((id - 1) % ROWNUM) * 54,175 - ((id - 1)/ROWNUM) *59 )

	CGPointUtil.distance(Pos1,Pos2);

	每隔多长时间做上面事情
	CCschedule --> CCschedule.sharedschedule.schedule(SELEctor,target,float interval,Boolean paused)  
			SELEctor方法要带一个float 参数 --> SELEctor(float t){}
		

	停止timer: CCschedule.sharedschedule.unschedule(SELEctor,target)


	游戏进度
	CCProgressTimer --> CCProgressTimer.progressWithFile("res")
		--setYype(int newTypE) 
		--setPercentage(float percent)

	
	

CCGLSurfaceView



*/

大佬总结

以上是大佬教程为你收集整理的Cocos2d-android 学习笔记全部内容,希望文章能够帮你解决Cocos2d-android 学习笔记所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。