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

cocos2d game +ios5

 
阅读更多

http://bsr1983.iteye.com/blog/1628520

 

http://code.google.com/p/sinaweiboios/source/browse/#svn%2Ftrunk%2FSina-OAuth-iPhone%2FTwitter%2BOAuth

http://blog.csdn.net/kobbbb/article/details/7750458

 

http://blog.csdn.net/kmyhy/article/details/6583782

http://www.devdiv.com/%E5%85%B3%E4%BA%8E%E6%B8%B8%E6%88%8F%E5%BC%80%E5%8F%91%E7%9A%84%E4%B8%80%E4%B8%AA%E5%B0%8F%E6%A5%BC-thread-118554-2-1.html

http://www.devdiv.com/

http://www.devdiv.com/%E5%85%B3%E4%BA%8E%E6%B8%B8%E6%88%8F%E5%BC%80%E5%8F%91%E7%9A%84%E4%B8%80%E4%B8%AA%E5%B0%8F%E6%A5%BC-thread-118554-2-1.html

 

http://www.devdiv.com/iOS_iPhone-iOS_5_Programming_Cookbook%E4%B8%AD%E6%96%87%E7%BF%BB%E8%AF%91%E5%90%84%E7%AB%A0%E8%8A%82%E6%B1%87%E6%80%BB--%E7%BB%93%E6%9D%9F%E6%9B%B4%E6%96%B09%E6%9C%8810%E6%97%A5-thread-122853-1-1.html

 

http://www.devdiv.com/%E5%85%A5%E9%97%A8%E6%B8%B8%E6%88%8F%E4%B9%8B%E4%B8%80_%E2%80%94%E2%80%94_%E6%89%BE%E8%8C%AC_1_-weblog-23234-7380.html

山东省青岛市市南区香港中路30号世奥国际6楼文明盛世

工具下载:

   texturepacker

http://www.codeandweb.com/texturepacker

 

只使用一个层来接受事件和处理事件,这个层通过转发事件来通知其他节点或类。

 

http://cocos2d-central.com/

 

高手博客

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

http://www.cnblogs.com/andyque/articles/1997820.html

http://www.cnblogs.com/andyque/archive/2011/06/09/2074962.html

http://www.otierney.net/objective-c.html#downloading

http://www.ityran.com/portal.php

http://www.cnblogs.com/andyque/archive/2011/06/09/2074962.html

http://www.raywenderlich.com/tutorials

http://t.dianping.com/deal/38751

http://www.xuanyusong.com/archives/950

http://www.xuanyusong.com/archives/1370

http://www.raywenderlich.com/tutorials

http://blog.csdn.net/xhfjiao/article/details/6858270#

高手QQ 4006333186

源码下载

http://www.learn-cocos2d.com/store/book-learn-cocos2d/

 

http://cocos2d-central.com/topic/29-games-made-with-the-books-source-code/

Cocos2d最基本的类是CCNode,拥有坐标,这个是所有类的父类,

CCSence--场景, 是抽象的的容器,只是包容其他

使用方法:

  CCScene * scene = [CCScene node];

  [scene addChild:[GameLayer node];

  [[CCDirector sharedDirector]replaceScene:[CCTransitionSplitRowstransitionWithDuration:1.2f  scene:scene]];

切换场景的2种方式

   1)直接替换场景

      [[CCDirtory sharedDirectory]replaceScene:[GameLayer scene]];

    2)从init 函数开始执行

      CCScene * scene = [CCScene node];

      [scene addChild:[GameLayer node]];树下

      [[CCDirector sharedDirector]replaceScene:[CCTranssitionSplitRows transitionWithDuration:1.2f scene:secne]];//缩放的形式切换场景的方法

 

 

CCLayer--

 

1)CCocos2d推荐对象生成是

其中CCNode 的node生成源码是

+(id)node

{

   return [[[self alloc]init]autorelease];

}

2)

如果需要响应的控件需要添加tag

label.tag = 13

3)CCLayer响应触摸事件

步骤1:

self.isTouchEnabled = true;

步骤2:

   在CCLayer响应消息

   -(void)ccTouchesBegan:(NSSet*)touches withEvent:(UIEvent*)event

   {

CCNode * node = [self getChildByTag:13];

CCLabelTTF * label = (CCLabelTTF*) node;

label.scale = CCRANDOM_0_1();

   }

 

4)CCNode

4.1)CCNode的子类:CCAtlasNode,CCLayer,CCMenuItem,CCMotionStreak,CCParallaxNode,CCParticleSystem,CCProgeressTimer,CCScene,CCSprite,CCSpriteBatchNode,

4.2)   node可以添加,删除,通过tag访问

4.3)node可以有各种动作action,

          action的声明

    CCAction * action = [CCBlink actionWithDuration:10 blinkk:20];

    action.tag =13;

 action的运行,停止;

    [node runAction:action];  [node stopAction:action];  [node stopAllActions];

 4.4)node可以响应各种消息,例如update(刷新消息);

          步骤一:-(void) scheduleUpdateMethod

        {

    [self scheduleUpdate];

         }

           步骤二:响应消息

       -(void)update:(ccTime)delta

{

}

5)CCDiretory 全局对象,配置信息,场景管理(替换,push,pop),决定游戏如何更新状态,UIKit2D和OpenGL3D坐标转换。

  [[CCDirector sharedDirector]runWithScene:[HelloWorld scene]];

  [[CCDirector sharedDirector]replaceScene:[HelloWorld scene]];

  [[CCDirector sharedDirector]pushScene:[Setting scene]];

  [[CCDirector sharedDirector]popScene];

  效果替换

  CCTransitionFade * tran = [CCTransitionFade transitionWithFuration:1 scene:[HelloWorld scene] withColor:ccWHITE];

  [[CCDirector sharedDirector]replaceScene:tran];

6)CCScene 是个抽象类,只是用来做容器,一般就是用来包含CCLayer对象

     游戏一开始肯定有个场景,这个场景的生成,而且这个场景有一个层HelloWorld

     +(id)scene

     {

CCScene * scene = [CCScene node];

CCLayer * layer = [HelloWorld node];

[scene addChild:layer];

return scene;

     }

  7)CCLayer  

       在场景创建的时候添加几个层。注意不要设计太多层,尤其是用户交互的层最好是一个层,

       +(id)scene

       {

           CCScene * scene = [CCScene node];

  

  CCLayer * backgroundLayer = [HelloWorldBackground node];

  [scene addChild: backgroundlayer];

 

  CCLayer * layer = [HelloWorld node];

  [scene addChild:layer];

 

  CCLayer * userInterfaceLayer = [HelloWorldUserInterface node];

  [scene addChild:userInterfaceLayer];

 

           return scene;

 

        }

touch事件:

 步骤一:

   self.isTouchEnabled = YES;

  步骤二:

     -(void)ccTouchesBegan:(NSSet*)touches withEvent:(UIEvent*)event

 

   例子: 坐标转换(OpenGL坐标):

         -(CGPoint)locationFromTouches:(NSSet *)touches

 {

     UITouch * touch = [touches anyObject];

     CGPoint touchLocation = [touch loactionInView:[touch view]];

     return [[CCDirectory sharedDirector]convertToGL:touchLocation];

 }

       CCLayer可以接受touch输入,和Accelerometer(加速器)事件

           步骤一:self.isAccelerometerEnabled = YES;

           步骤二:响应事件

       -(void) accelerometer:(UIAcceleromter *)acceleromter

                      didAccelerate:(UIAcceleration*)acceleration

{

                       CGLOG(@"acceleration: x:%f/ y:%f /z:%f",acceleration.x,acceleration.y,acceleration.z);

}

 

        CCLayer接受键盘事件

  步骤一:self.isKeyBoardEnabled = YES;

  步骤二:-(BOOL) ccKeyDown:(NSEvent*)event

  {

      CCLOG(@"key pressed:%@",[event charaactrers]);

  }

CCLayer接受鼠标事件

   步骤一:self.isMouseEnabled = YES;

   步骤二:响应鼠标事件

   -(BOOL)ccMouseDragged:(NSEvent*)event{}

   -(BOOL)ccScrollWheel:(NSEvent*)event{}

   注意鼠标事件中也需要进行坐标转换

       CGPoint mousePos = [[CCDirector sharedDirector]convertEventToGL:event];

8)CCSprite-- 生成方式一:已经添加到工程中的图片文件

                CCSprite * sprite = [CCSprite spriteWithFile:@"Default.png"];

[self addChild:sprite];

9)CCLableTTF

                CCLabelTTF *label = [CCLabelTTF labelWithString:@"text"

                               fontName:@"AppleGothic"

fontSize:32];

       [self addChild:label];

[label setString:@"new text"];

10)Menus

11)全局唯一对象

        CCActionManager * sharedManager = [CCActionManager sharedManager];

CCDirector * sharedDirector = [CCDirector sharedDirector];

CCSpriteFrameCache * sharedCache = [CCSpriteFrameCache sharedSpriteFrameCache];

CCTextureCache * sharedTexCache = [CCTextureCache sharedTextureCache];

CCTouchDispatcher* sharedDispatcher = [CCTouchDispatcher sharedDispatcher];

 

 

2012-6-29

游戏level的实现有2种思路一种是用不同Scene实现,一种是用CCLayer实现。

 

2012-7-2

如何创建并且运行sprite动画步骤

1.创建NSMutableArray;NSMutableArray* frames = [NSMutableArray arrayWithCapacity:5];

2.遍历每一个动画帧:

          a每个图片创建一个CCTexture2D纹理

CCTexture2D* texture = [[CCTextureCache sharedTextureCache] addImage:file];;

          b用CCTexture纹理创建一个CCSpriteFrame帧,

                 CCSpriteFrame* frame = [CCSpriteFrame frameWithTexture:texture rect:texRect];

          c把每一个CCSpriteFrame添加到NSMutableArray.

                  [frames addObject:frame];

3.利用NSMutableArray来创建 CCAnimation* anim = [CCAnimation animationWithFrames:frames delay:0.08f];

 

2012-7-5

安装cocos2d sudo ./install-templates.sh

 

2012-7-30

通过大图片加载生成 CCSpriteBatchNode 是为了一次绘画多个图片。

而加载加载.plist文件,它里面包含了这张大图里面的所有的小图的位置坐标信息。这样,你以后可以非常方便地使用 spriteWithSpriteFrameName来提取一张张小图片来初使化一些精灵。

 

 

想要在cocos2d里面使用视差滚动效果非常简单。你只需要做3步就ok了:

  1. 创建一个CCParallaxNode,然后把它加到层中去。
  2. 创建你想要滚动的元素,然后通过调用CCParallaxNode的 addChild:parallaxRatio:positionOffset方法把这些元素添加进去。
  3. 移动CCParallaxNode来滚动背景。这样的话,CCParallaxNode就会根据parallaxRatio的不同,或快或慢地移动它里面添加的元素了。

 

       

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics