Пример #1
0
/**
* 处理touch 事件
* \param touchType 点击类型
* \param touchPoint 点击的点
*/
bool  UICenterItem::onTouch(int touchType,const CCPoint &touchPoint)
{
	if (disable) return false;
	if (!this->isVisible()) return false;
	switch(touchType)
	{
		case UICenterItem::TOUCH_DOWN:
		{
			if (checkIn(touchPoint))
			{
				inTouch = true;
				nowTouchPoint = touchPoint;
				initWithSpriteFrame(downShow);
			}
		}break;
		case UICenterItem::TOUCH_END:
		{
			if (inTouch)
			{
				initWithSpriteFrame(upShow);
				if (checkIn(touchPoint))
					onClick();
			}

			inTouch = false;
		}break;
	}
	return inTouch;
}
Пример #2
0
bool Sprite::initWithSpriteFrameName(const std::string& spriteFrameName)
{
    CCASSERT(spriteFrameName.size() > 0, "Invalid spriteFrameName");

    SpriteFrame *frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(spriteFrameName);
    return initWithSpriteFrame(frame);
}
bool CC3DSprite::initWithSpriteFrameName(const char *pszSpriteFrameName)
{
	CCAssert(pszSpriteFrameName != NULL, "");

	CCSpriteFrame *pFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(pszSpriteFrameName);
	return initWithSpriteFrame(pFrame);
}
Пример #4
0
bool DropLife::init(){
	if (!Drop::init()){
		return false;
	}
	auto DropLife_path = PATH_DROP_ADDLIFE_PICTURE;
	auto spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(DropLife_path);
	initWithSpriteFrame(spriteFrame);
	dropType = addLife;
	return true;
}
Пример #5
0
PlayerItem *PlayerItem::createWithSpriteFrame(cocos2d::SpriteFrame *spriteFrame)
{
    auto sprite = new PlayerItem();
    if (spriteFrame && sprite && sprite->initWithSpriteFrame(spriteFrame))
    {
        sprite->autorelease();
        return sprite;
    }
    CC_SAFE_DELETE(sprite);
    return nullptr;
}
Пример #6
0
EffectSprite *EffectSprite::createWithSpriteFrame(cocos2d::SpriteFrame *spriteFrame)
{
    auto ret = new (std::nothrow) EffectSprite;
    if(ret && ret->initWithSpriteFrame(spriteFrame)) {
        ret->autorelease();
        return ret;
    }
    CC_SAFE_RELEASE(ret);
    return nullptr;
    
}
Пример #7
0
Hunter* Hunter::create(){
    auto obj = new Hunter();
    obj->batchNode= SpriteBatchNode::create("soldier.png");
    obj->frmCache= SpriteFrameCache::getInstance();
    obj->frmCache->addSpriteFramesWithFile("soldier.plist");
    auto frm = obj->frmCache->getSpriteFrameByName("soldier14.png");
    obj->initWithSpriteFrame(frm);
    obj->posBulletInParent=Vect(obj->getContentSize().width/2-10,obj->getContentSize().height/2+12);
    
    return obj;
}
Пример #8
0
bool Sprite::initWithSpriteFrameName(const std::string& spriteFrameName)
{
    CCASSERT(!spriteFrameName.empty(), "Invalid spriteFrameName");

    if (spriteFrameName.empty()) {
        return false;
    }

    SpriteFrame *frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(spriteFrameName);
    return initWithSpriteFrame(frame);
}
Пример #9
0
AnimationFrame* AnimationFrame::clone() const
{
    // no copy constructor
    auto frame = new (std::nothrow) AnimationFrame();
    frame->initWithSpriteFrame(_spriteFrame->clone(),
                               _delayUnits,
                               _userInfo);

    frame->autorelease();
    return frame;
}
Пример #10
0
bool UICenterItem::doTouchCanMove(int touchType,const CCPoint &touchPoint)
{
	if (!this->isVisible()) return false;
	switch(touchType)
	{
		case UICenterItem::TOUCH_DOWN:
		{
			if (checkIn(touchPoint))
			{
				inTouch = true;
				nowTouchPoint = touchPoint;
				initWithSpriteFrame(downShow);
				return  true;
			}
		}break;
		case UICenterItem::TOUCH_MOVE:
		{
			if (inTouch && canMove)
			{
				CCPoint nowPoint = getPosition();
				setPosition(ccp(nowPoint.x + touchPoint.x - nowTouchPoint.x,
                                  nowPoint.y + touchPoint.y - nowTouchPoint.y));
				nowTouchPoint = touchPoint;
				return true;
			}
		}break;
		case UICenterItem::TOUCH_END:
		{
			if (inTouch)
			{
				initWithSpriteFrame(upShow);
				if (checkIn(touchPoint))
					onClick();
			}

			inTouch = false;
			
		}break;
	}
	return false;
}
Пример #11
0
Player* Player::create() {
    auto spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName("catBody1.png");
    
    auto player = new (std::nothrow) Player;
    if (player && spriteFrame && player->initWithSpriteFrame(spriteFrame))
    {
        player->autorelease();
        return player;
    }
    CC_SAFE_DELETE(player);
    return nullptr;
}
Пример #12
0
RepeatableSprite* RepeatableSprite::createWithSpriteFrame(cocos2d::SpriteFrame *spriteFrame)
{
    auto sprite = new RepeatableSprite();
    if (spriteFrame && sprite && sprite->initWithSpriteFrame(spriteFrame))
    {
        sprite->autorelease();
        sprite->initTextureRectAndPosition();
        return sprite;
    }
    CC_SAFE_DELETE(sprite);
    return NULL;
}
void FilteredSpriteWithMulti::clearFilter()
{
    //CCLOG("FilteredSpriteWithMulti::clearFilter");
    _pFilters.clear();
    if (_pTexture)
    {
        initWithTexture(_pTexture, _rect);
    }
    else if (_pFrame)
    {
        initWithSpriteFrame(_pFrame);
    }
}
Пример #14
0
NS_CC_BEGIN

AnimationFrame* AnimationFrame::create(SpriteFrame* spriteFrame, float delayUnits, const ValueMap& userInfo)
{
    auto ret = new (std::nothrow) AnimationFrame();
    if (ret && ret->initWithSpriteFrame(spriteFrame, delayUnits, userInfo))
    {
        ret->autorelease();
    }
    else
    {
        CC_SAFE_DELETE(ret);
    }
    return ret;
}
Пример #15
0
 bool Scale9Sprite::initWithSpriteFrameName(const std::string& spriteFrameName,
                                            const Rect& capInsets)
 {
     bool ret = false;
     do {
         auto spriteFrameCache = SpriteFrameCache::getInstance();
         CCASSERT(spriteFrameCache != nullptr,
                  "SpriteFrameCache::getInstance() must be non-NULL");
         if(spriteFrameCache == nullptr) break;
         
         SpriteFrame *frame = spriteFrameCache->getSpriteFrameByName(spriteFrameName);
         CCASSERT(frame != nullptr, "CCSpriteFrame must be non-NULL");
         if (frame == nullptr) break;
         
         ret = initWithSpriteFrame(frame, capInsets);
     } while (false);
     
     return ret;
 }
Пример #16
0
bool Skin::initWithSpriteFrameName(const std::string& spriteFrameName)
{
    CCAssert(spriteFrameName != "", "");

    SpriteFrame *pFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(spriteFrameName);
    bool ret = true;

    if (pFrame != nullptr)
    {
        ret = initWithSpriteFrame(pFrame);
    }
    else
    {
        CCLOG("Cann't find CCSpriteFrame with %s. Please check your .plist file", spriteFrameName.c_str());
        ret = false;
    }
    _displayName = spriteFrameName;

    return ret;
}
Пример #17
0
bool CCSpriteButton::init(CCSpriteFrame *pNormalFrame,CCSpriteFrame *pSelectedFrame)
{
    if (pNormalFrame)
    {
        m_pNormalSprite = CCSprite::createWithSpriteFrame(pNormalFrame);
        CC_SAFE_RETAIN(m_pNormalSprite);
    }
    if (pSelectedFrame)
    {
        m_pSelectedSprite = CCSprite::createWithSpriteFrame(pSelectedFrame);
        CC_SAFE_RETAIN(m_pSelectedSprite);
    }

    if (pNormalFrame)
    {
        return initWithSpriteFrame(pNormalFrame);
    }
    else
    {
        return CCSprite::init();
    }
}
Пример #18
0
bool ShaderEffectSprite::initShaderSprite(cocos2d::CCSpriteFrame *frame, const string &shaderType) {
    return initWithSpriteFrame(frame);
}
Пример #19
0
bool Bullet::initBullet(Attacker attacker,int type,int level)
{
    bool ret = false;

    _attacker = attacker;
    _level = level;
    _type = type;

    char fileName[30];

    switch (attacker)
    {
        case Attacker::ENEMY:
            sprintf(fileName,"e_bullet_%d_%d.png",type + 1,level + 1);
            _attack = s_enemyConfigs[type][level].attack;
            break;
        case Attacker::BOSS:
            sprintf(fileName,"e_bullet_%d_%d.png",type + 1,level + 1);
            _attack = s_bossConfig[level].attack;
            break;
        case Attacker::TOWER:
            sprintf(fileName,"e_bullet_%d_%d.png",type + 1,level + 1);
            _attack = s_towerConfig[level].attack;
            break;
        case Attacker::PLAIN:
            sprintf(fileName,"p_bullet_%d_%d.png",type + 1,level + 1);
            _attack = s_plainConfigs[type][level].attack;
            switch (type)
        {
            case 0:
                _trace = false;
                _attackMode = AttackMode::SINGLE;
                break;
            case 1:
                _trace = false;
                _attackMode = AttackMode::SINGLE;
                break;
            case 2:
                _trace = true;
                _attackMode = AttackMode::RANG;
                break;
            case 3:
                _trace = false;
                _attackMode = AttackMode::SINGLE;
                break;
            case 4:
                _trace = false;
                _attackMode = AttackMode::DIFFUSION;
                break;
            case 5:
                _trace = true;
                _attackMode = AttackMode::SINGLE;
                break;
            default:
                break;
        }
            break;
        default:
            break;
    }
    
    auto frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(fileName);
    ret = initWithSpriteFrame(frame);

    if (ret)
    {
        auto listener = EventListenerCustom::create(GameConfig::eventPlayerDestroy, [=](EventCustom* event){
            if (_attTarget == event->getUserData())
            {
                _attTarget = nullptr;
            }
        });

        _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
    }

    return ret;
}
Пример #20
0
bool BaseSprite::initWithSpriteFrameFile(string file)
{
	return initWithSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(file));
}