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];
CCSprite各种动作介绍和使用博客分类:?- iPhone
?
?
C代码??
- //?触摸屏??
- -(void)?ccTouchesEnded:(NSSet?*)touches?withEvent:(UIEvent?*)event??
- {??
- ??
- ????for(?UITouch?*touch?in?touches?)?{??
- ????????CGPoint?location?=?[touch?locationInView:?[touch?view]];??
- ????????location?=?[[CCDirector?sharedDirector]?convertToGL:?location];??
- ??
- ????????//?各种动作??
- ??????????
- ????????//?瞬时动作??
- ????????//?设置坐标??
- ????????id?action0?=?[CCPlace?actionWithPosition:ccp(240,160)];??
- ????????//?隐藏??
- ????????id?action1?=?[CCHide?action];??
- ????????//?显示??
- ????????id?action2?=?[CCShow?action];??
- ????????//?隐藏/显示??
- ????????id?action3?=?[CCToggleVisibility?action];??
- ??????????
- ????????//?延时动作??
- ????????//?移动??
- ????????id?action4?=?[CCMoveTo?actionWithDuration:2?position:ccp(0,0)];??
- ????????id?action5?=?[CCMoveBy?actionWithDuration:2?position:ccp(100,100)];??
- ????????//?弹跳??
- ????????id?action6?=?[CCJumpTo?actionWithDuration:2?position:ccp(0,200)?height:30?jumps:5];??
- ????????id?action7?=?[CCJumpBy?actionWithDuration:2?position:ccp(100,?0)?height:30?jumps:5];??
- ????????//?贝塞尔移动??
- ????????ccBezierConfig?bezier;??
- ????????bezier.controlPoint_1?=?ccp(0,?0);??
- ????????bezier.controlPoint_2?=?ccp(100,?300);??
- ????????bezier.endPosition?=?ccp(0,100);??
- ????????id?action8?=?[CCBezierTo?actionWithDuration:3?bezier:bezier];??
- ????????id?action9?=?[CCBezierBy?actionWithDuration:3?bezier:bezier];??
- ????????//?缩放??
- ????????id?action10?=?[CCScaleTo?actionWithDuration:2?scale:4];??
- ????????id?action11?=?[CCScaleBy?actionWithDuration:2?scale:0.5];??
- ????????//?旋转??
- ????????id?action12?=?[CCRotateTo?actionWithDuration:2?angle:180];??
- ????????id?action13?=?[CCRotateBy?actionWithDuration:2?angle:-180];??
- ????????//?闪烁??
- ????????id?action14?=?[CCBlink?actionWithDuration:3?blinks:5];??
- ????????//?色调变化??
- ????????id?action15?=?[CCTintTo?actionWithDuration:2?red:255?green:0?blue:0];??
- ????????id?action16?=?[CCTintBy?actionWithDuration:0.5?red:0?green:255?blue:255];??
- ????????//?淡化到/淡入/淡出??
- ????????id?action17?=?[CCFadeTo?actionWithDuration:?1?opacity:80];??
- ????????id?action18?=?[CCFadeIn?actionWithDuration:1.0f];??
- ????????id?action19?=?[CCFadeOut?actionWithDuration:1.0f];??
- ??????????
- ????????//?动画顺序播放??
- ????????CCAnimation?*animation?=?[CCAnimation?animation];??
- ????????[animation?setDelay:2];??
- ????????//?这里就添加两帧,需要自己添加??
- ????????[animation?addFrameWithTexture:sprTest.texture?rect:CGRectMake(0,?0,?44,?34)];??
- ????????[animation?addFrameWithTexture:sprTest.texture?rect:CGRectMake(0,?34,?44,?34)];???
- ????????id?action20?=?[CCAnimate?actionWithAnimation:?animation];??
- ??????????
- ????????//?组合动作??
- ????????//?动画序列??
- ????????id?action21?=?[CCSequence?actions:action19,?action18,?nil];??
- ????????//?重复动作??
- ????????id?action22?=?[CCRepeat?actionWithAction:action21?times:10];??
- ????????//?延时动作??
- ????????id?action23?=?[CCDelayTime?actionWithDuration:1];??
- ????????//?同时动作??
- ????????id?action24?=?[CCSpawn?actions:action0,?action4,?action21,?nil];??
- ????????//?无限循环动作??
- ????????id?action25?=?[CCRepeatForever?actionWithAction:action21];??
- ??????????
- ????????//?扩展动作??
- ????????//?回调动作??
- ????????id?acf0?=?[CCCallFunc?actionWithTarget:self?selector:@selector(CallBack1)];??
- ????????//?回调动作,传递动画自身指针??
- ????????id?acf1?=?[CCCallFuncN?actionWithTarget:self?selector:@selector(CallBack2:)];????
- ????????//?回调动作,传递动画自身指针已经一个参数??
- ????????id?acf2?=?[CCCallFuncND?actionWithTarget:self?selector:@selector(CallBack3:data:)?data:(void*)2];??
- ????????id?action26?=?[CCSequence?actions:action19,?action18,?acf0,?action23,?action0,?nil];??
- ????????//?反转动作,只能用在有方向有顺序的动作上??
- ????????id?action27?=?[action9?reverse];??
- ??
- ????????//?速度变化??
- ????????//id?ac?=?[CCSequence?actions:action9,action27,nil];??
- ????????id?actiontest?=?[CCMoveBy?actionWithDuration:0.5?position:ccp(200,0)];??
- ????????id??ac?=?[CCSequence?actions:actiontest,actiontest,?nil];??
- ????????//?渐快??
- ????????id?action28?=?[CCEaseIn?actionWithAction:ac?rate:3];??
- ????????//?渐慢??
- ????????id?action29?=?[CCEaseOut?actionWithAction:ac?rate:3];??
- ????????//?先渐快再渐慢??
- ????????id?action30?=?[CCEaseInOut?actionWithAction:ac?rate:3];??
- ????????//?正弦波移动??
- ????????id?action31?=?[CCEaseSineIn?actionWithAction:ac];??
- ????????id?action32?=?[CCEaseSineOut?actionWithAction:ac];??
- ????????id?action33?=?[CCEaseSineInOut?actionWithAction:ac];??
- ????????//?由极慢至极快??
- ????????id?action34?=?[CCEaseExponentialIn?actionWithAction:ac];??
- ????????//?由极快到极慢??
- ????????id?action35?=?[CCEaseExponentialOut?actionWithAction:ac];??
- ????????//?由极慢至极快?再由极快到慢??
- ????????id?action36?=?[CCEaseExponentialInOut?actionWithAction:ac];??
- ????????//?手动设定速度,可通过SetSpeed不断调整??
- ????????id?action37?=?[CCSpeed?actionWithAction:ac?speed:(CCRANDOM_0_1()?*?5)];??
- ??
- ????????[sprTest?runAction:action37];??
- ??????
- ????}????
- }??
- //?回调函数1??
- -?(void)?CallBack1??
- {??
- ????[sprTest?runAction:[CCTintBy?actionWithDuration:2?red:255?green:0?blue:255]];?????
- }??
- ??
- //?回调函数2??
- -?(void)?CallBack2:(id)sender??
- {??
- ????[sender?runAction:[CCTintBy?actionWithDuration:1?red:255?green:0?blue:255]];??
- }??
- ??
- //?回调函数3??
- -(void)?CallBack3:(id)sender?data:(void*)data??
- {??
- ????[sender?runAction:[CCTintBy?actionWithDuration:(NSInteger)data?red:255?green:0?blue:255]];????
- } ?
?
?
?
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
?
?
C代码??
- //?触摸屏??
- -(void)?ccTouchesEnded:(NSSet?*)touches?withEvent:(UIEvent?*)event??
- {??
- ??
- ????for(?UITouch?*touch?in?touches?)?{??
- ????????CGPoint?location?=?[touch?locationInView:?[touch?view]];??
- ????????location?=?[[CCDirector?sharedDirector]?convertToGL:?location];??
- ??
- ????????//?各种动作??
- ??????????
- ????????//?瞬时动作??
- ????????//?设置坐标??
- ????????id?action0?=?[CCPlace?actionWithPosition:ccp(240,160)];??
- ????????//?隐藏??
- ????????id?action1?=?[CCHide?action];??
- ????????//?显示??
- ????????id?action2?=?[CCShow?action];??
- ????????//?隐藏/显示??
- ????????id?action3?=?[CCToggleVisibility?action];??
- ??????????
- ????????//?延时动作??
- ????????//?移动??
- ????????id?action4?=?[CCMoveTo?actionWithDuration:2?position:ccp(0,0)];??
- ????????id?action5?=?[CCMoveBy?actionWithDuration:2?position:ccp(100,100)];??
- ????????//?弹跳??
- ????????id?action6?=?[CCJumpTo?actionWithDuration:2?position:ccp(0,200)?height:30?jumps:5];??
- ????????id?action7?=?[CCJumpBy?actionWithDuration:2?position:ccp(100,?0)?height:30?jumps:5];??
- ????????//?贝塞尔移动??
- ????????ccBezierConfig?bezier;??
- ????????bezier.controlPoint_1?=?ccp(0,?0);??
- ????????bezier.controlPoint_2?=?ccp(100,?300);??
- ????????bezier.endPosition?=?ccp(0,100);??
- ????????id?action8?=?[CCBezierTo?actionWithDuration:3?bezier:bezier];??
- ????????id?action9?=?[CCBezierBy?actionWithDuration:3?bezier:bezier];??
- ????????//?缩放??
- ????????id?action10?=?[CCScaleTo?actionWithDuration:2?scale:4];??
- ????????id?action11?=?[CCScaleBy?actionWithDuration:2?scale:0.5];??
- ????????//?旋转??
- ????????id?action12?=?[CCRotateTo?actionWithDuration:2?angle:180];??
- ????????id?action13?=?[CCRotateBy?actionWithDuration:2?angle:-180];??
- ????????//?闪烁??
- ????????id?action14?=?[CCBlink?actionWithDuration:3?blinks:5];??
- ????????//?色调变化??
- ????????id?action15?=?[CCTintTo?actionWithDuration:2?red:255?green:0?blue:0];??
- ????????id?action16?=?[CCTintBy?actionWithDuration:0.5?red:0?green:255?blue:255];??
- ????????//?淡化到/淡入/淡出??
- ????????id?action17?=?[CCFadeTo?actionWithDuration:?1?opacity:80];??
- ????????id?action18?=?[CCFadeIn?actionWithDuration:1.0f];??
- ????????id?action19?=?[CCFadeOut?actionWithDuration:1.0f];??
- ??????????
- ????????//?动画顺序播放??
- ????????CCAnimation?*animation?=?[CCAnimation?animation];??
- ????????[animation?setDelay:2];??
- ????????//?这里就添加两帧,需要自己添加??
- ????????[animation?addFrameWithTexture:sprTest.texture?rect:CGRectMake(0,?0,?44,?34)];??
- ????????[animation?addFrameWithTexture:sprTest.texture?rect:CGRectMake(0,?34,?44,?34)];???
- ????????id?action20?=?[CCAnimate?actionWithAnimation:?animation];??
- ??????????
- ????????//?组合动作??
- ????????//?动画序列??
- ????????id?action21?=?[CCSequence?actions:action19,?action18,?nil];??
- ????????//?重复动作??
- ????????id?action22?=?[CCRepeat?actionWithAction:action21?times:10];??
- ????????//?延时动作??
- ????????id?action23?=?[CCDelayTime?actionWithDuration:1];??
- ????????//?同时动作??
- ????????id?action24?=?[CCSpawn?actions:action0,?action4,?action21,?nil];??
- ????????//?无限循环动作??
- ????????id?action25?=?[CCRepeatForever?actionWithAction:action21];??
- ??????????
- ????????//?扩展动作??
- ????????//?回调动作??
- ????????id?acf0?=?[CCCallFunc?actionWithTarget:self?selector:@selector(CallBack1)];??
- ????????//?回调动作,传递动画自身指针??
- ????????id?acf1?=?[CCCallFuncN?actionWithTarget:self?selector:@selector(CallBack2:)];????
- ????????//?回调动作,传递动画自身指针已经一个参数??
- ????????id?acf2?=?[CCCallFuncND?actionWithTarget:self?selector:@selector(CallBack3:data:)?data:(void*)2];??
- ????????id?action26?=?[CCSequence?actions:action19,?action18,?acf0,?action23,?action0,?nil];??
- ????????//?反转动作,只能用在有方向有顺序的动作上??
- ????????id?action27?=?[action9?reverse];??
- ??
- ????????//?速度变化??
- ????????//id?ac?=?[CCSequence?actions:action9,action27,nil];??
- ????????id?actiontest?=?[CCMoveBy?actionWithDuration:0.5?position:ccp(200,0)];??
- ????????id??ac?=?[CCSequence?actions:actiontest,actiontest,?nil];??
- ????????//?渐快??
- ????????id?action28?=?[CCEaseIn?actionWithAction:ac?rate:3];??
- ????????//?渐慢??
- ????????id?action29?=?[CCEaseOut?actionWithAction:ac?rate:3];??
- ????????//?先渐快再渐慢??
- ????????id?action30?=?[CCEaseInOut?actionWithAction:ac?rate:3];??
- ????????//?正弦波移动??
- ????????id?action31?=?[CCEaseSineIn?actionWithAction:ac];??
- ????????id?action32?=?[CCEaseSineOut?actionWithAction:ac];??
- ????????id?action33?=?[CCEaseSineInOut?actionWithAction:ac];??
- ????????//?由极慢至极快??
- ????????id?action34?=?[CCEaseExponentialIn?actionWithAction:ac];??
- ????????//?由极快到极慢??
- ????????id?action35?=?[CCEaseExponentialOut?actionWithAction:ac];??
- ????????//?由极慢至极快?再由极快到慢??
- ????????id?action36?=?[CCEaseExponentialInOut?actionWithAction:ac];??
- ????????//?手动设定速度,可通过SetSpeed不断调整??
- ????????id?action37?=?[CCSpeed?actionWithAction:ac?speed:(CCRANDOM_0_1()?*?5)];??
- ??
- ????????[sprTest?runAction:action37];??
- ??????
- ????}????
- }??
- //?回调函数1??
- -?(void)?CallBack1??
- {??
- ????[sprTest?runAction:[CCTintBy?actionWithDuration:2?red:255?green:0?blue:255]];?????
- }??
- ??
- //?回调函数2??
- -?(void)?CallBack2:(id)sender??
- {??
- ????[sender?runAction:[CCTintBy?actionWithDuration:1?red:255?green:0?blue:255]];??
- }??
- ??
- //?回调函数3??
- -(void)?CallBack3:(id)sender?data:(void*)data??
- {??
- ????[sender?runAction:[CCTintBy?actionWithDuration:(NSInteger)data?red:255?green:0?blue:255]];????
- } ?
?
?
?
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