`
icrwen
  • 浏览: 261932 次
  • 性别: Icon_minigender_2
  • 来自: 济南
社区版块
存档分类
最新评论

cocos2d做游戏之一入门

 
阅读更多

有的时候发现做一件事情真不容易,哪怕是换一种语言,要下多大的决心,要做多久的坚持。

apple developer api

http://developer.apple.com/library/ios/navigation/


http://bbs.weiphone.com/read-htm-tid-1493600.html

 

http://www.iphonegametutorials.com/2010/09/07/cocos2d-menu-tutorial/

 

http://gamerboom.com/archives/33682

http://o0o0o0o.iteye.com/blog/649331

http://archive.cnblogs.com/a/2107758/

http://www.open-open.com/lib/view/open1326595638890.html

http://www.cocoachina.com/bbs/read.php?tid-55155.html

http://www.raywenderlich.com/352/how-to-make-a-simple-iphone-game-with-cocos2d-tutorial

http://www.j2megame.com/html/xwzx/ty/2258.html

http://gamerboom.com/archives/33682

http://blog.csdn.net/liu734197637/article/details/6416990

 

http://www.cnblogs.com/andyque/archive/2011/04/11/2012770.html

在cocos2d-iphone 1.0版本以后  将CCColorLayer改为了CCLayerColor
以前的程序可以改用CCLayerColor 
能够实现CCColorLayer原有功能

以下是具体修改背景颜色的方法

在cocos2d中,所有的demo都是黑色为背景的,这里提供方法改变背景颜色:

方法一:
1.首先要让你的类继承自CCColorLayer(0.9以前版本)或者CCLayerColor(1.0版本以后)
HelloworldLayer : CCColorLayer
{
}
2.在.m文件中的init中做如下修改
if( (self=[super initWithColor:ccc4(255,255,255,255)] ))
{
}
这样背景色就变为白色。

///////////////////////////////////////////////////////////////////
CCDirector  是引擎的静态类不用生成对象,可以用来管理场景,和帧率
CCLayer负责响应触摸和加速事件。
CCNodes是所有可以绘画的都是CCNode对象,比如场景、层和精灵

从plist和大图png里加载多个图
CCSpriteFrameCache * cache = [CCSpriteFrameCache sharedSpriteFrameCache];
[cache addSpriteFrameWithFile:@"***.plist"];
CCSpriteBatchNode * batch = [CCSpriteBatchNode batchNodeWithFile@"同名的png"];
[self addChild:bath z:1];

CCSprite  t= [CCSprite spriteWithSpriteFrameName:@"小图.png"];
[self addChild:t z:1];




 

 

C代码   收藏代码
  1. // 触摸屏  
  2. -(void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event  
  3. {  
  4.   
  5.     for( UITouch *touch in touches ) {  
  6.         CGPoint location = [touch locationInView: [touch view]];  
  7.         location = [[CCDirector sharedDirector] convertToGL: location];  
  8.   
  9.         // 各种动作  
  10.           
  11.         // 瞬时动作  
  12.         // 设置坐标  
  13.         id action0 = [CCPlace actionWithPosition:ccp(240,160)];  
  14.         // 隐藏  
  15.         id action1 = [CCHide action];  
  16.         // 显示  
  17.         id action2 = [CCShow action];  
  18.         // 隐藏/显示  
  19.         id action3 = [CCToggleVisibility action];  
  20.           
  21.         // 延时动作  
  22.         // 移动  
  23.         id action4 = [CCMoveTo actionWithDuration:2 position:ccp(0,0)];  
  24.         id action5 = [CCMoveBy actionWithDuration:2 position:ccp(100,100)];  
  25.         // 弹跳  
  26.         id action6 = [CCJumpTo actionWithDuration:2 position:ccp(0,200) height:30 jumps:5];  
  27.         id action7 = [CCJumpBy actionWithDuration:2 position:ccp(100, 0) height:30 jumps:5];  
  28.         // 贝塞尔移动  
  29.         ccBezierConfig bezier;  
  30.         bezier.controlPoint_1 = ccp(0, 0);  
  31.         bezier.controlPoint_2 = ccp(100, 300);  
  32.         bezier.endPosition = ccp(0,100);  
  33.         id action8 = [CCBezierTo actionWithDuration:3 bezier:bezier];  
  34.         id action9 = [CCBezierBy actionWithDuration:3 bezier:bezier];  
  35.         // 缩放  
  36.         id action10 = [CCScaleTo actionWithDuration:2 scale:4];  
  37.         id action11 = [CCScaleBy actionWithDuration:2 scale:0.5];  
  38.         // 旋转  
  39.         id action12 = [CCRotateTo actionWithDuration:2 angle:180];  
  40.         id action13 = [CCRotateBy actionWithDuration:2 angle:-180];  
  41.         // 闪烁  
  42.         id action14 = [CCBlink actionWithDuration:3 blinks:5];  
  43.         // 色调变化  
  44.         id action15 = [CCTintTo actionWithDuration:2 red:255 green:0 blue:0];  
  45.         id action16 = [CCTintBy actionWithDuration:0.5 red:0 green:255 blue:255];  
  46.         // 淡化到/淡入/淡出  
  47.         id action17 = [CCFadeTo actionWithDuration: 1 opacity:80];  
  48.         id action18 = [CCFadeIn actionWithDuration:1.0f];  
  49.         id action19 = [CCFadeOut actionWithDuration:1.0f];  
  50.           
  51.         // 动画顺序播放  
  52.         CCAnimation *animation = [CCAnimation animation];  
  53.         [animation setDelay:2];  
  54.         // 这里就添加两帧,需要自己添加  
  55.         [animation addFrameWithTexture:sprTest.texture rect:CGRectMake(0, 0, 44, 34)];  
  56.         [animation addFrameWithTexture:sprTest.texture rect:CGRectMake(0, 34, 44, 34)];   
  57.         id action20 = [CCAnimate actionWithAnimation: animation];  
  58.           
  59.         // 组合动作  
  60.         // 动画序列  
  61.         id action21 = [CCSequence actions:action19, action18, nil];  
  62.         // 重复动作  
  63.         id action22 = [CCRepeat actionWithAction:action21 times:10];  
  64.         // 延时动作  
  65.         id action23 = [CCDelayTime actionWithDuration:1];  
  66.         // 同时动作  
  67.         id action24 = [CCSpawn actions:action0, action4, action21, nil];  
  68.         // 无限循环动作  
  69.         id action25 = [CCRepeatForever actionWithAction:action21];  
  70.           
  71.         // 扩展动作  
  72.         // 回调动作  
  73.         id acf0 = [CCCallFunc actionWithTarget:self selector:@selector(CallBack1)];  
  74.         // 回调动作,传递动画自身指针  
  75.         id acf1 = [CCCallFuncN actionWithTarget:self selector:@selector(CallBack2:)];    
  76.         // 回调动作,传递动画自身指针已经一个参数  
  77.         id acf2 = [CCCallFuncND actionWithTarget:self selector:@selector(CallBack3:data:) data:(void*)2];  
  78.         id action26 = [CCSequence actions:action19, action18, acf0, action23, action0, nil];  
  79.         // 反转动作,只能用在有方向有顺序的动作上  
  80.         id action27 = [action9 reverse];  
  81.   
  82.         // 速度变化  
  83.         //id ac = [CCSequence actions:action9,action27,nil];  
  84.         id actiontest = [CCMoveBy actionWithDuration:0.5 position:ccp(200,0)];  
  85.         id  ac = [CCSequence actions:actiontest,actiontest, nil];  
  86.         // 渐快  
  87.         id action28 = [CCEaseIn actionWithAction:ac rate:3];  
  88.         // 渐慢  
  89.         id action29 = [CCEaseOut actionWithAction:ac rate:3];  
  90.         // 先渐快再渐慢  
  91.         id action30 = [CCEaseInOut actionWithAction:ac rate:3];  
  92.         // 正弦波移动  
  93.         id action31 = [CCEaseSineIn actionWithAction:ac];  
  94.         id action32 = [CCEaseSineOut actionWithAction:ac];  
  95.         id action33 = [CCEaseSineInOut actionWithAction:ac];  
  96.         // 由极慢至极快  
  97.         id action34 = [CCEaseExponentialIn actionWithAction:ac];  
  98.         // 由极快到极慢  
  99.         id action35 = [CCEaseExponentialOut actionWithAction:ac];  
  100.         // 由极慢至极快 再由极快到慢  
  101.         id action36 = [CCEaseExponentialInOut actionWithAction:ac];  
  102.         // 手动设定速度,可通过SetSpeed不断调整  
  103.         id action37 = [CCSpeed actionWithAction:ac speed:(CCRANDOM_0_1() * 5)];  
  104.   
  105.         [sprTest runAction:action37];  
  106.       
  107.     }    
  108. }  
  109. // 回调函数1  
  110. - (void) CallBack1  
  111. {  
  112.     [sprTest runAction:[CCTintBy actionWithDuration:2 red:255 green:0 blue:255]];     
  113. }  
  114.   
  115. // 回调函数2  
  116. - (void) CallBack2:(id)sender  
  117. {  
  118.     [sender runAction:[CCTintBy actionWithDuration:1 red:255 green:0 blue:255]];  
  119. }  
  120.   
  121. // 回调函数3  
  122. -(void) CallBack3:(id)sender data:(void*)data  
  123. {  
  124.     [sender runAction:[CCTintBy actionWithDuration:(NSInteger)data red:255 green:0 blue:255]];    
  125. }  

 

 

 

opengl es 画图

 

http://wenku.baidu.com/view/ca42e422a5e9856a56126086.html

http://www.byywee.com/page/M0/S572/572297.html

http://www.cocoachina.com/gamedev/opengl/2010/0126/409.html

 

 

OpenGL ES on iOS: Losing Transparency on texture with a shape from Quartz

glGenTextures(1, &brushTexture);

glBindTexture(GL_TEXTURE_2D, brushTexture);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, brushData);

 

http://developer.android.com/resources/tutorials/opengl/opengl-es10.html

 

http://hi.baidu.com/%E1%B0%B7%E7%D0%F1/blog/item/d3af65e27cad5e20b90e2df2.html

 

https://developer.apple.com/search/index.php?q=opengl+es

 

http://developer.apple.com/library/ios/#samplecode/GLEssentials/Introduction/Intro.html

 

https://developer.apple.com/library/ios/#documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/WorkingwithEAGLContexts/WorkingwithEAGLContexts.html#//apple_ref/doc/uid/TP40008793-CH103-SW1

https://developer.apple.com/library/ios/#documentation/2DDrawing/Conceptual/DrawingPrintingiOS/Introduction/Introduction.html

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics