zoukankan      html  css  js  c++  java
  • [Cocos2d-x]代码段记录

    一些零碎的代码,便于以后查找

    1.添加动画

     1 //添加动画帧
     2 CCAnimation* animation = CCAnimation::create();
     3 for(int i = 1; i< 6;i++)
     4 {
     5   char imgsName[100] = {0};
     6   sprinft(imgsName,”img_%d.png”,i);
     7   animation->addSpriteFrameWithFileName(imgsName);
     8 }
     9 animation->setDelayPerUnit(1.0f);
    10 animation->setRestoreOriginalFrame(true);
    11 animation->setLoop(-1);
    12 //使用动画帧创建动画
    13 CCAnimate* animate = CCAnimate::create(animation);
    14 this->runAction(animate);

    2.替换CCSprite的纹理

    setTexture(CCTexture2D)

    3.Touch事件处理

    bool SoundSprite::ccTouchBegan(cocos2d::CCTouch *touch, cocos2d::CCEvent *event)
    {
        CCPoint touchPoint = convertToNodeSpace(touch->getLocation());
        CCRect rect = CCRect(getPositionX() - getContentSize().width * getAnchorPoint().x,
                             getPositionY() - getContentSize().height * getAnchorPoint().y,
                             getContentSize().width, getContentSize().height);
        rect.origin = CCPointZero;
        bool isTouchedIn = rect.containsPoint(touchPoint);
        if (isTouchedIn) {
            CCLog("SoundSprite::ccTouchBegan");
            m_PlaySound = !m_PlaySound;
            this->initWithFile(m_PlaySound?I_FARM_SOUND_ON:I_FARM_SOUND_OFF);
            return true;
        }
        return false;
    }
    人生就是一局不能Again的DOTA
  • 相关阅读:
    元素绑定与非元素绑定
    窗口之间的交互,windows和自定义的窗口集合
    e.which
    prop()和attr()
    web动画
    $.proxy()和$.makeArray()
    匿名自执行函数报错
    页面适配
    gulp
    伪元素和伪类
  • 原文地址:https://www.cnblogs.com/hellenism/p/3462397.html
Copyright © 2011-2022 走看看