cocos2d-x2.0

  • y3_588363
    了解作者
  • 1.3MB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-04-15 09:46
    上传日期
cocos2d-x2.0
1.zip
  • 1
  • proj.win32
  • res
  • 4.png
    592KB
  • 1.ico
    46.5KB
  • Debug.win32
  • 1.win32.exe.intermediate.manifest
    381B
  • link.15888.read.1.tlog
    2B
  • cl.command.1.tlog
    6.5KB
  • 1.win32_manifest.rc
    216B
  • rc.command.1.tlog
    1.3KB
  • CL.read.1.tlog
    151.8KB
  • 3.tmx
    703B
  • vc100.idb
    1.5MB
  • mt.read.1.tlog
    530B
  • 1.res
    47.3KB
  • link.14984-cvtres.read.1.tlog
    2B
  • link.7664-cvtres.read.1.tlog
    2B
  • 1.win32.log
    4.6KB
  • link-cvtres.read.1.tlog
    2B
  • link.read.1.tlog
    5.3KB
  • 1.win32.lastbuildstate
    76B
  • rc.read.1.tlog
    3.3KB
  • link.write.1.tlog
    1.5KB
  • CL.write.1.tlog
    2.6KB
  • link.15888-cvtres.write.1.tlog
    2B
  • vc100.pdb
    716KB
  • link.14984.write.1.tlog
    2B
  • 1.win32.exe.embed.manifest.res
    472B
  • link.7664.write.1.tlog
    2B
  • main.obj
    73.3KB
  • link.14984-cvtres.write.1.tlog
    2B
  • link.command.1.tlog
    2.7KB
  • link.7664.read.1.tlog
    2B
  • link.15888-cvtres.read.1.tlog
    2B
  • link.14984.read.1.tlog
    2B
  • link.7664-cvtres.write.1.tlog
    2B
  • mt.write.1.tlog
    426B
  • link.15888.write.1.tlog
    2B
  • HelloWorldScene.obj
    155.8KB
  • 1.win32.exe.embed.manifest
    406B
  • mt.command.1.tlog
    462B
  • rc.write.1.tlog
    706B
  • AppDelegate.obj
    101.9KB
  • link-cvtres.write.1.tlog
    2B
  • 1.win32.vcxproj
    8KB
  • resource.h
    484B
  • 1.rc
    2.2KB
  • main.cpp
    863B
  • 1.win32.vcxproj.filters
    2KB
  • 1.win32.vcxproj.user
    763B
  • main.h
    270B
  • Classes
  • AppDelegate.cpp
    1.3KB
  • HelloWorldScene.h
    1KB
  • HelloWorldScene.cpp
    7.1KB
  • AppDelegate.h
    960B
  • Resources
  • 4.png
    34.6KB
  • 3.tmx
    703B
  • HelloWorld.png
    141.5KB
  • 1.png
    435B
  • 2.png
    353B
  • 0.png
    647B
  • CloseNormal.png
    6.2KB
  • CloseSelected.png
    5.4KB
内容介绍
#include "HelloWorldScene.h" using namespace cocos2d; CCScene* HelloWorld::scene() { CCScene * scene = NULL; do { // 'scene' is an autorelease object scene = CCScene::create(); CC_BREAK_IF(! scene); // 'layer' is an autorelease object HelloWorld *layer = HelloWorld::create(); CC_BREAK_IF(! layer); // add layer as a child to scene scene->addChild(layer); } while (0); // return the scene return scene; } // on "init" you need to initialize your instance bool HelloWorld::init() { bool bRet = false; do { ////////////////////////////////////////////////////////////////////////// // super init first ////////////////////////////////////////////////////////////////////////// CC_BREAK_IF(! CCLayer::init()); ////////////////////////////////////////////////////////////////////////// // add your codes below... ////////////////////////////////////////////////////////////////////////// // 1. Add a menu item with "X" image, which is clicked to quit the program. // Create a "close" menu item with close icon, it's an auto release object. CCMenuItemImage *pCloseItem = CCMenuItemImage::create( "CloseNormal.png", "CloseSelected.png", this, menu_selector(HelloWorld::menuCloseCallback)); CC_BREAK_IF(! pCloseItem); // Place the menu item bottom-right conner. pCloseItem->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20)); // Create a menu with the "close" menu item, it's an auto release object. CCMenu* pMenu = CCMenu::create(pCloseItem, NULL); pMenu->setPosition(CCPointZero); CC_BREAK_IF(! pMenu); // Add the menu to HelloWorld layer as a child layer. this->addChild(pMenu, 1); // 2. Add a label shows "Hello World". // Create a label and initialize with string "Hello World". CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Arial", 24); CC_BREAK_IF(! pLabel); // Get window size and place the label upper. CCSize size = CCDirector::sharedDirector()->getWinSize(); pLabel->setPosition(ccp(size.width / 2, size.height - 50)); // Add the label to HelloWorld layer as a child layer. this->addChild(pLabel, 1); // 3. Add add a splash screen, show the cocos2d splash image. CCSprite* pSprite = CCSprite::create("4.png"); CC_BREAK_IF(! pSprite); pSprite->setPosition(ccp(size.width/2, size.height/2)); this->addChild(pSprite, 0); m_pSprite = CCSprite::create("1.png"); // 把精灵放在正中间。 m_pSprite->setPosition(ccp(10, size.height/2)); // 将精灵放在场景中,设Z顺序为1 this->addChild(m_pSprite, 1); _targets = new CCArray; _projectiles = new CCArray; /* m_map = CCTMXTiledMap::tiledMapWithTMXFile("3.tmx"); m_map->retain(); m_map->setPosition(CCPointZero); addChild(m_map, 3); */ this->schedule( schedule_selector(HelloWorld::gameLogic), 0.5); //this->setIsTouchEnabled(true); setTouchEnabled(true); bRet = true; } while (0); return bRet; } void HelloWorld::menuCloseCallback(CCObject* pSender) { // "close" menu item clicked CCDirector::sharedDirector()->end(); } void HelloWorld::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent) { //获取触点指针容器中第一个元素 CCSetIterator it = pTouches->begin(); //将其转化为触点信息 CCTouch* touch = (CCTouch*)(*it); //取得触点位置 CCPoint touchLocation = touch->getLocation(); //设置精灵位置为触点位置。 //m_pSprite->setPosition(touchLocation); } HelloWorld::~HelloWorld(){ if (_targets){ _targets->release(); _targets = NULL; } if (_projectiles){ _projectiles->release(); _projectiles = NULL; } } HelloWorld::HelloWorld():_targets(NULL),_projectiles(NULL){ } void HelloWorld::addTarget(){ CCSprite *target = CCSprite::create("0.png", CCRectMake(0,0,27,40) ); CCSize winSize = CCDirector::sharedDirector()->getWinSize(); int minY = target->getContentSize().height/2; int maxY = winSize.height- target->getContentSize().height/2; int rangeY = maxY - minY; // srand( TimGetTicks() ); int actualY = ( rand() % rangeY ) + minY; // Create the target slightly off-screen along the right edge, // and along a random position along the Y axis as calculated target->setPosition( ccp(winSize.width + (target->getContentSize().width/2), actualY) ); this->addChild(target); // Determine speed of the target int minDuration = (int)1.0; int maxDuration = (int)10.0; int rangeDuration = maxDuration - minDuration; // srand( TimGetTicks() ); int actualDuration = ( rand() % rangeDuration )+ minDuration; // Create the actions CCFiniteTimeAction* actionMove = CCMoveTo::create( (float)actualDuration, ccp(0 - target->getContentSize().width/2, actualY) ); CCFiniteTimeAction* actionMoveDone = CCCallFuncN::create( this, callfuncN_selector(HelloWorld::spriteMoveFinished)); target->runAction( CCSequence::actions(actionMove, actionMoveDone, NULL) ); } void HelloWorld::spriteMoveFinished(CCNode* sender){ CCSprite *sprite = (CCSprite *)sender; this->removeChild(sprite, true); } void HelloWorld::gameLogic(float dt) { this->addTarget(); } void HelloWorld::ccTouchesEnded(CCSet* touches, CCEvent* event){ CCTouch* touch = (CCTouch*)( touches->anyObject() ); CCPoint location = touch->locationInView(); location = CCDirector::sharedDirector()->convertToGL(location); // Set up initial location of projectile CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCSprite *projectile = CCSprite::spriteWithFile("2.png", CCRectMake(0, 0, 20, 20)); projectile->setPosition( ccp(20, winSize.height/2) ); // Determinie offset of location to projectile int offX = location.x - projectile->getPosition().x; int offY = location.y - projectile->getPosition().y; // Bail out if we are shooting down or backwards if (offX <= 0) return; // Ok to add now - we've double checked position this->addChild(projectile); // Determine where we wish to shoot the projectile to int realX = winSize.width+ (projectile->getContentSize().width/2); float ratio = (float)offY / (float)offX; int realY = (realX * ratio) + projectile->getPosition().y; CCPoint realDest = ccp(realX, realY); // Determine the length of how far we're shooting int offRealX = realX - projectile->getPosition().x; int offRealY = realY - projectile->getPosition().y; float length = sqrtf((offRealX * offRealX)+ (offRealY*offRealY)); float velocity = 480/1; // 480pixels/1sec float realMoveDuration = length/velocity; // Move projectile to actual endpoint projectile->runAction( CCSequence::create(CCMoveTo::create(realMoveDuration, realDest),CCCallFuncN::actionWithTarget(this,callfuncN_selector(HelloWorld::spriteMoveFinished)), NULL) ); }
评论
    相关推荐
    • Cocos2d Game
      I create a Cocos2d game
    • cocos2d富文本
      cocos2d 富文本实现 格式 [i:图片路径|-] [s:22|c:00ff00ff]***[-] [s:22]***[-] [l:item/1001]...[-] 随意组合嵌套
    • Cocos2d学习文档
      Cocos2d学习文档 适合新手 第1章-介绍cocos2d.pdf 第2章-开始学习.pdf 。。。。 第4章-你的第一个游戏(修正错误).pdf 。。。。
    • Cocos2d学习资料
      Cocos2D目录: 第一章:介绍Cocos2d 第二章: 开始学习 第三章: 基础知识 第四章: 你的第一个游戏(修正错误) 第五章: 游戏构成要素 第六章: 深入了解精灵(Sprite) 第七章: 横向滚屏射击游戏 第八章: 完成滚屏射击游戏...
    • cocos2d demo
      本资源是一个小的经典的cocos2d-x的demo,后续每周更新增加功能的版本
    • cocos2d精灵教程
      (译)cocos2d精灵教程:第一部分.pdf (译)cocos2d精灵教程:第三部分.pdf (译)cocos2d精灵教程:第二部分.pdf (译)cocos2d菜单教程:第一部分.pdf (译)cocos2d菜单教程:第三部分(完).pdf (译)...
    • cocos2d模板
      cocos2d-template-updated
    • Cocos2d手势
      为实现Cocos2d手势支持,改写的CCLayer、CCNode、CCGestureRecognizer三个源码类,可以参考我博客使用!
    • Cocos2D文档
      Cocos2D开发参考文档 Cocos2D帮助文档
    • cocos2d实例
      cocos的一些实例代码,有助于初学者。