• 射击小游戏一01(子弹添加添加)


    void HelloWorld::ccTouchesEnded(CCSet *touches,cocos2d::CCEvent *event)
    
    {
    
        CCTouch *touch = (CCTouch*)(touches->anyObject());
    
        CCPoint location = touch->getLocationInView();
    
        location = CCDirector::sharedDirector()->convertToGL(location);
    
        
    
        CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    
        CCSprite *projectile = CCSprite::create("Projectile.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;
    
        
    
        if (offX <= 0) return;
    
        
    
        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::create(this, callfuncN_selector(HelloWorld::spriteMoveFinished)),NULL));
    
        
    
        
    
    }
  • 相关阅读:
    docker学习笔记3:镜像操作(查找和下载)
    docker学习笔记2:容器操作
    docker学习笔记1:docke环境的查看
    CSS鼠标样式
    Ubuntu下安装和配置mysql
    HR函数学习01——创建组织单位
    SAP模块常用增强总结{转载}
    SAP物料批次管理配置及操作手册(轉載)
    交货单开票
    ABAP之PINYING拼音
  • 原文地址:https://www.cnblogs.com/jiackyan/p/3017899.html
Copyright © 2020-2023  润新知