Your SlideShare is downloading. ×
Cocos2d/2d-x/html5 [Objective-C/C++/JavaScript] 好みの言語はどれですか?
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Cocos2d/2d-x/html5 [Objective-C/C++/JavaScript] 好みの言語はどれですか?

2,377
views

Published on

cocos2d_fukuoka 勉強会 第0回

cocos2d_fukuoka 勉強会 第0回

Published in: Self Improvement, Technology

0 Comments
7 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,377
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
0
Comments
0
Likes
7
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. 13年6月10日月曜日
  • 2. 13年6月10日月曜日
  • 3. • twitter ID : @itoKami1123• 仕事はHTML5/CSS3/JavaScriptで業務Webアプリ作ってます。何かお仕事あればご連絡を!• Cocos2d歴は、Cocos2d-xを1ヶ月位...13年6月10日月曜日
  • 4. 趣味アプリの宣伝Cocos2d-xの実績コレダケデス。ゴメンンササイ13年6月10日月曜日
  • 5. 13年6月10日月曜日
  • 6. 13年6月10日月曜日
  • 7. Directorsprite13年6月10日月曜日
  • 8. 13年6月10日月曜日
  • 9. // CatJumpLayer.h cocos2dx-study001#ifndef __cocos2dx_study001__CatJumpLayer__#define __cocos2dx_study001__CatJumpLayer__#include "cocos2d.h"using namespace cocos2d;class CatJumpLayer : public CCLayer{public:bool init();CREATE_FUNC(CatJumpLayer);};#endif /* defined(__cocos2dx_study001__CatJumpLayer__) */13年6月10日月曜日
  • 10. #define CREATE_FUNC(__TYPE__) static __TYPE__* create() { __TYPE__ *pRet = new __TYPE__(); if (pRet && pRet->init()) { pRet->autorelease(); return pRet; } else { delete pRet; pRet = NULL; return NULL; } }13年6月10日月曜日
  • 11. // CatJumpLayer.cpp cocos2dx-study001#include "CatJumpLayer.h"bool CatJumpLayer::init(){if ( !CCLayer::init() ){return false;}CCSize size = CCDirector::sharedDirector()->getWinSize();CCSprite* catSprite = CCSprite::create("cat.png");catSprite->setPosition( ccp(size.width/2, size.height/2) );this->addChild(catSprite, 0);return true;}sprite13年6月10日月曜日
  • 12. // CatJumpScene.h cocos2dx-study001#ifndef __cocos2dx_study001__CatJumpScene__#define __cocos2dx_study001__CatJumpScene__#include "cocos2d.h"using namespace cocos2d;class CatJumpScene : public CCScene{public:bool init();CREATE_FUNC(CatJumpScene);};#endif /* defined(__cocos2dx_study001__CatJumpScene__) */sprite13年6月10日月曜日
  • 13. // CatJumpScene.cpp cocos2dx-study001#include "CatJumpScene.h"#include "CatJumpLayer.h"bool CatJumpScene::init(){if ( !CCScene::init() ){return false;}CatJumpLayer *layer = CatJumpLayer::create();this->addChild(layer);return true;}sprite13年6月10日月曜日
  • 14. // AppDelegate.cpp cocos2dx-study001// (・・・省略・・・)bool AppDelegate::applicationDidFinishLaunching(){CCDirector *pDirector = CCDirector::sharedDirector();// (・・・省略・・・)CCScene *catJumpScene = CatJumpScene::create();pDirector->runWithScene(catJumpScene);return true;}// (・・・省略・・・)Directorsprite13年6月10日月曜日
  • 15. 13年6月10日月曜日
  • 16. // CatJumpLayer.h cocos2d_study001#import "cocos2d.h"@interface CatJumpLayer : CCLayer@end // CatJumpLayer.h cocos2dx-study001#ifndef __cocos2dx_study001__CatJumpLayer__#define __cocos2dx_study001__CatJumpLayer__#include "cocos2d.h"using namespace cocos2d;class CatJumpLayer : public CCLayer{public:bool init();CREATE_FUNC(CatJumpLayer);};#endif /*defined(__cocos2dx_study001__CatJumpLayer__) */13年6月10日月曜日
  • 17. Objective-Cはサブクラスが親クラスのクラスメソッドをサブクラスのものとして使えるみたいです。CatJumpLayer *layer = [CatJumpLayer node];不思議ですね。Cocos2d(Objective-C)とCocos2dx(c++)のちがうとこhttp://qiita.com/items/5ed59ce25be5bb0e5731?fb_action_ids=462829403809503&fb_action_types=og.likes&fb_source=aggregation&fb_aggregation_id=28838148123758213年6月10日月曜日
  • 18. // CatJumpLayer.m cocos2d_study001#import "CatJumpLayer.h"@implementation CatJumpLayer-(id)init{if( !(self=[super init]) ) {return self;}CGSize size = [[CCDirector sharedDirector] winSize];CCSprite* catSprite = [CCSprite spriteWithFile:@"cat.png" ];catSprite.position = ccp(size.width/2, size.height/2);[self addChild:catSprite z:0];return self;}@endCocos2d(Objective-C)で書くCCLayerサブクラス(.m)sprite// CatJumpLayer.cpp cocos2dx-study001#include "CatJumpLayer.h"bool CatJumpLayer::init(){if ( !CCLayer::init() ){return false;}CCSize size = CCDirector::sharedDirector()->getWinSize();CCSprite* catSprite = CCSprite::create("cat.png");catSprite->setPosition( ccp(size.width/2, size.height/2) );this->addChild(catSprite, 0);return true;}13年6月10日月曜日
  • 19. // CatJumpScene.h cocos2d_study001#import "cocos2d.h"#import "CatJumpLayer.h"@interface CatJumpScene : CCScene@endCocos2d(Objective-C)でCCSceneサブクラス(.h)sprite// CatJumpScene.h cocos2dx-study001#ifndef __cocos2dx_study001__CatJumpScene__#define __cocos2dx_study001__CatJumpScene__#include "cocos2d.h"using namespace cocos2d;class CatJumpScene : public CCScene{public:bool init();CREATE_FUNC(CatJumpScene);};#endif /* defined(__cocos2dx_study001__CatJumpScene__) */13年6月10日月曜日
  • 20. // CatJumpScene.m cocos2d_study001#import "CatJumpScene.h"@implementation CatJumpScene-(id)init{if( !(self=[super init])) {return self;}CatJumpLayer *layer = [CatJumpLayer node];[self addChild:layer];return self;}@endCocos2d(Objective-C)でCCSceneサブクラス(.m)sprite// CatJumpScene.cpp cocos2dx-study001#include "CatJumpScene.h"#include "CatJumpLayer.h"bool CatJumpScene::init(){if ( !CCScene::init() ){return false;}CatJumpLayer *layer = CatJumpLayer::create();this->addChild(layer);return true;}13年6月10日月曜日
  • 21. // AppDelegate.m cocos2d_study001#import "cocos2d.h"#import "AppDelegate.h"#import "CatJumpScene.h"@implementation MyNavigationController// ・・・省略・・・-(void) directorDidReshapeProjection:(CCDirector*)director{if(director.runningScene == nil) {[director runWithScene: [CatJumpScene node]];}}@endCocos2d(Objective-C)でCCSceneサブクラス起動Directorsprite// AppDelegate.cpp cocos2dx-study001// (・・・省略・・・)bool AppDelegate::applicationDidFinishLaunching(){CCDirector *pDirector = CCDirector::sharedDirector();// (・・・省略・・・)CCScene *catJumpScene = CatJumpScene::create();pDirector->runWithScene(catJumpScene);return true;}// (・・・省略・・・)13年6月10日月曜日
  • 22. 13年6月10日月曜日
  • 23. var CatJumpLayer = cc.Layer.extend({init:function () {if ( !this._super() ){return false;}var size = cc.Director.getInstance().getWinSize();var catSprite = cc.Sprite.create("res/cat.png");catSprite.setPosition(cc.p(size.width / 2, size.height / 2));this.addChild( catSprite, 0);return true;}}); // CatJumpLayer.cpp cocos2dx-study001#include "CatJumpLayer.h"bool CatJumpLayer::init(){if ( !CCLayer::init() ){return false;}CCSize size = CCDirector::sharedDirector()->getWinSize();CCSprite* catSprite = CCSprite::create("cat.png");catSprite->setPosition( ccp(size.width/2, size.height/2) );this->addChild(catSprite, 0);return true;}sprite13年6月10日月曜日
  • 24. var CatJumpScene = cc.Scene.extend({ctor:function(){this.init();},init:function () {if ( !this._super() ){! return false;}var layer = new CatJumpLayer();layer.init();this.addChild(layer);return true;}});// CatJumpScene.cpp cocos2dx-study001#include "CatJumpScene.h"#include "CatJumpLayer.h"bool CatJumpScene::init(){if ( !CCScene::init() ){return false;}CatJumpLayer *layer = CatJumpLayer::create();this->addChild(layer);return true;}sprite13年6月10日月曜日
  • 25. var cocos2dApp = cc.Application.extend({config:document[ccConfig],ctor:function (scene) {this._super();this.startScene = scene;// ・・・省略・・・},applicationDidFinishLaunching:function () {// ・・・省略・・・var director = cc.Director.getInstance();// ・・・省略・・・cc.LoaderScene.preload(g_ressources, function () {director.replaceScene(new this.startScene());}, this);return true;}});var myApp = new cocos2dApp(CatJumpScene);Director// AppDelegate.cpp cocos2dx-study001// (・・・省略・・・)bool AppDelegate::applicationDidFinishLaunching(){CCDirector *pDirector = CCDirector::sharedDirector();// (・・・省略・・・)CCScene *catJumpScene = CatJumpScene::create();pDirector->runWithScene(catJumpScene);return true;}// (・・・省略・・・)sprite13年6月10日月曜日
  • 26. Directorsprite13年6月10日月曜日
  • 27. // CatSprite.h cocos2dx-study001#ifndef __cocos2dx_study001__CatSprite__#define __cocos2dx_study001__CatSprite__#include "cocos2d.h"typedef enum{CAT_DIRECTION_NONE, CAT_DIRECTION_LEFT, CAT_DIRECTION_RIGHT,}DIRECTION;using namespace cocos2d;class CatSprite : public CCSprite,public CCTargetedTouchDelegate{public:DIRECTION _direction;static CatSprite* create(const char *pszFileName);void onEnter();void onExit();CCRect getRect();void catJump();void toggleDirection();bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent);};#endif /* defined(__cocos2dx_study001__CatSprite__) */13年6月10日月曜日
  • 28. // CatSprite.cpp cocos2dx-study001#include "CatSprite.h"CatSprite* CatSprite::create(const char *pszFileName){CatSprite *sprite = new CatSprite();if (sprite && sprite->initWithFile(pszFileName)){sprite->autorelease();return sprite;}CC_SAFE_DELETE(sprite);return NULL;}void CatSprite::onEnter(){CCSprite::onEnter();this->_direction = CAT_DIRECTION_NONE;CCTouchDispatcher* touchDispatcher = CCDirector::sharedDirector()->getTouchDispatcher();touchDispatcher->addTargetedDelegate(this, 0, true);}void CatSprite::onExit(){CCSprite::onExit();CCTouchDispatcher* touchDispatcher = CCDirector::sharedDirector()->getTouchDispatcher();touchDispatcher->removeDelegate(this);}// ・・・ 後半につづく ・・・13年6月10日月曜日
  • 29. // ・・・ 後半 つづき ・・・CCRect CatSprite::getRect(){float h = this->getContentSize().height;float w = this->getContentSize().width;float x = this->getPosition().x -w/2;float y = this->getPosition().y -h/2;return CCRect(x, y, w, h);}void CatSprite::catJump(){this->stopAllActions();CCSize size = CCDirector::sharedDirector()->getWinSize();float toX = size.width/2;toX += ( this->_direction == CAT_DIRECTION_LEFT )?(-100):+100;CCPoint jumpPosition = ccp( toX, size.height/2);CCFiniteTimeAction *actionMove = CCJumpTo::create( 1.0, jumpPosition, 64.0, 2 );this->runAction( actionMove );}void CatSprite::toggleDirection(){this->_direction = ( this->_direction != CAT_DIRECTION_LEFT )? CAT_DIRECTION_LEFT : CAT_DIRECTION_RIGHT;}bool CatSprite::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent){CCPoint location = pTouch->getLocation();CCRect rect = this->getRect();if ( rect.containsPoint(location) ){this->catJump();this->toggleDirection();return true;}return false;};13年6月10日月曜日
  • 30. // CatSprite.h cocos2d_study001#import "cocos2d.h"typedef enum{CAT_DIRECTION_NONE,CAT_DIRECTION_LEFT,CAT_DIRECTION_RIGHT,}DIRECTION;@interface CatSprite : CCSprite <CCTouchOneByOneDelegate>@property (nonatomic,assign) DIRECTION direction;-(CGRect)getRect;-(void)catJump;-(void)toggleDirection;@end13年6月10日月曜日
  • 31. // CatSprite.m cocos2d_study001#import "CatSprite.h"@implementation CatSprite-(void)onEnter{[super onEnter];self.direction = CAT_DIRECTION_NONE;[[[CCDirector sharedDirector]touchDispatcher]addTargetedDelegate:selfpriority:0swallowsTouches:YES];}-(void)onExit{[super onExit];[[[CCDirector sharedDirector]touchDispatcher] removeDelegate:self];}-(CGRect)getRect{float h = self.contentSize.height;float w = self.contentSize.width;float x = self.position.x -w/2;float y = self.position.y -h/2;return CGRectMake(x, y, w, h);}// 後半につづく・・・13年6月10日月曜日
  • 32. // つづき・・・-(void)catJump{[self stopAllActions];CGSize size = [[CCDirector sharedDirector] winSize];float toX = size.width/2;toX += ( self.direction == CAT_DIRECTION_LEFT )?(-100):(+100);CGPoint jumpPosition = ccp( toX, size.height/2);CCFiniteTimeAction *actionMove =[CCJumpTo actionWithDuration:1.0position:jumpPositionheight:64.0jumps:2];[self runAction:actionMove];}-(void)toggleDirection{self.direction = ( self.direction != CAT_DIRECTION_LEFT )? CAT_DIRECTION_LEFT :CAT_DIRECTION_RIGHT;}-(BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event{CGPoint touchPotision = [touch locationInView:touch.view];CGPoint position = [[CCDirector sharedDirector] convertToGL:touchPotision];if( CGRectContainsPoint( self.boundingBox , position) ){[self catJump];[self toggleDirection];return YES;}return NO;}@end13年6月10日月曜日
  • 33. var CAT_DIRECTION = { NONE : 0, LEFT : 1, RIGHT : 2,};var CatSprite = cc.Sprite.extend({direction:null, // :CAT_DIRECTIONctor:function(){ this._super(); },onEnter:function(){this._super();this.direction = CAT_DIRECTION.NONE,cc.Director.getInstance().getTouchDispatcher().addTargetedDelegate(this, 1,true);},onExit:function () {this._super();cc.Director.getInstance().getTouchDispatcher().removeDelegate(this);},getRect:function(){var h = this._rect.size.height;var w = this._rect.size.width;var x = this.getPosition().x - (w/2);var y = this.getPosition().y - (h/2);return cc.rect( x, y, w, h );},13年6月10日月曜日
  • 34. catJump:function(){this.stopAllActions();var size = cc.Director.getInstance().getWinSize();var toX = size.width/2;toX += (this.direction == CAT_DIRECTION.LEFT)?(-100):(+100);var jumpPosition = cc.p( toX, size.height/2);var actionMove = cc.JumpTo.create( 1.0, jumpPosition, 64.0, 2);this.runAction( actionMove);},toggleDirection: function(){this.direction = (this.direction!==CAT_DIRECTION.LEFT)? CAT_DIRECTION.LEFT : CAT_DIRECTION.RIGHT;},onTouchBegan:function (touch, event) {var getPoint = touch.getLocation();var myRect = this.getRect();if ( cc.Rect.CCRectContainsPoint( myRect, getPoint) ){this.catJump();this.toggleDirection();return true;}return false;}});13年6月10日月曜日
  • 35. CatSprite.create=function( imgFile){var sprite = new CatSprite( imgFile);if ( sprite && sprite.initWithFile(imgFile) ){return sprite;}return null;};13年6月10日月曜日
  • 36. おしまい13年6月10日月曜日