效果例如以下图

左边箭头是x方向翻转的。右边箭头有旋转和缩放action。

大概实现方法:用箭头作为遮罩层,底图是一个绘制的矩形,得到一个黄色箭头背景。在用schedule尾随要聚焦箭头动作。这个在电视端用遥控器上下左右选择聚焦有点用。

希望这个是对同学们有帮助,谢谢。

代码

#include "HelloWorldScene.h"

USING_NS_CC;

CCScene* HelloWorld::scene()
{
// 'scene' is an autorelease object
CCScene *scene = CCScene::create(); // 'layer' is an autorelease object
HelloWorld *layer = HelloWorld::create(); // add layer as a child to scene
scene->addChild(layer); // return the scene
return scene;
} // on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !CCLayer::init() )
{
return false;
} CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCSprite *stencil = CCSprite::create("f1.png");
stencil->setFlipX(true); CCClippingNode *clipper = CCClippingNode::create();
clipper->setAlphaThreshold(0.005f);
clipper->setAnchorPoint(ccp(0.5, 0.5));
clipper->setPosition( ccp(visibleSize.width / 2 - 50, visibleSize.height / 2 - 50) );
clipper->setStencil(stencil); this->addChild(clipper,0,cliper_tag); CCNode *content = shape(stencil->getContentSize());
clipper->addChild(content,0,content_tag); CCSprite *updata = CCSprite::create("f1.png");
updata->setFlipX(true);
updata->setPosition( ccp(visibleSize.width / 2 - 50, visibleSize.height / 2 - 50) );
this->addChild(updata,1,spr1_tag); CCSprite *updata2 = CCSprite::create("f2.png");
updata2->setPosition( ccp(visibleSize.width / 2 + 50, visibleSize.height / 2 - 50) );
updata2->runAction(CCRepeatForever::create(CCSequence::create(CCScaleTo::create(0.5, 1.3),CCRotateBy::create(2, 90),CCScaleTo::create(0.5, 1),NULL))); this->addChild(updata2,1,spr2_tag); this->setTouchEnabled(true);
return true;
} CCDrawNode* HelloWorld::shape(CCSize size)
{
CCDrawNode *shape = CCDrawNode::create();
static CCPoint shapedate[4];
shapedate[0] = ccp(-(size.width / 2), -(size.height / 2));
shapedate[1] = ccp((size.width / 2), -(size.height / 2));
shapedate[2] = ccp((size.width / 2), (size.height / 2));
shapedate[3] = ccp(-(size.width / 2), (size.height / 2)); static ccColor4F yellow = {1, 1, 0, 1};
shape->drawPolygon(shapedate, 4, yellow, 0, yellow);
return shape;
} void HelloWorld::setshaper(int tag){ this->unschedule(schedule_selector(HelloWorld::cliperupdate)); current_tag = tag; CCSprite* sp = (CCSprite*) this->getChildByTag(tag);
CCClippingNode *clipper = (CCClippingNode*)this->getChildByTag(cliper_tag); CCSprite *stencil = CCSprite::createWithTexture(sp->getTexture());
stencil->setFlipX(sp->isFlipX());
stencil->setFlipY(sp->isFlipY());
stencil->setScale(sp->getScale());
stencil->setRotation(sp->getRotation());
clipper->setStencil(stencil);
clipper->setPosition(sp->getPosition()); clipper->removeChildByTag(content_tag);
clipper->addChild(shape(sp->getContentSize()),0,content_tag); this->schedule(schedule_selector(HelloWorld::cliperupdate), 0.05); } void HelloWorld::cliperupdate(float dt){ CCSprite* sp = (CCSprite*) this->getChildByTag(current_tag);
CCClippingNode *clipper = (CCClippingNode*)this->getChildByTag(cliper_tag);
clipper->setPosition(sp->getPosition()); CCSprite *stencil = (CCSprite*)clipper->getStencil();
stencil->setFlipX(sp->isFlipX());
stencil->setFlipY(sp->isFlipY());
stencil->setScale(sp->getScale());
stencil->setRotation(sp->getRotation()); CCSprite *content = (CCSprite*)clipper->getChildByTag(content_tag);
content->setScale(sp->getScale());
content->setRotation(sp->getRotation()); } bool HelloWorld::ccTouchBegan(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent){ CCPoint location = this->convertTouchToNodeSpace(pTouch);
if (this->getChildByTag(spr1_tag)->boundingBox().containsPoint(location)) {
setshaper(spr1_tag);
} if (this->getChildByTag(spr2_tag)->boundingBox().containsPoint(location)) {
setshaper(spr2_tag);
} return true; }
void HelloWorld::ccTouchMoved(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent){ }
void HelloWorld::ccTouchEnded(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent){ } void HelloWorld::registerWithTouchDispatcher(void){
CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 0, false);
}
void HelloWorld::onEnter(){
CCLayer::onEnter();
}
void HelloWorld::onExit(){
CCLayer::onExit();
} void HelloWorld::menuCloseCallback(CCObject* pSender)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
CCMessageBox("You pressed the close button. Windows Store Apps do not implement a close button.","Alert");
#else
CCDirector::sharedDirector()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
#endif
#endif
}

demoproject在这里下载 狂点我

cocos2d-x 2.2.0 图片选中聚焦 ,图片描边 CCClippingNode 实现的更多相关文章

  1. android 开发 实现一个进入相机拍照后裁剪图片或者进入相册选中裁剪图片的功能

    实现思维路径: 以进入相机拍照的思维路线为例子: 1.进入app 2.判断之前是否保存头像,如果有就显示历史图像 (下面代码中在getOldAvatar();方法中执行这个逻辑) 3.点击更换图像的B ...

  2. [Swift通天遁地]一、超级工具-(20)图片面部聚焦:使图像视图自动聚焦图片人物的面部位置

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  3. 与众不同 windows phone (43) - 8.0 相机和照片: 镜头的可扩展性, 图片的可扩展性, 图片的自动上传扩展

    [源码下载] 与众不同 windows phone (43) - 8.0 相机和照片: 镜头的可扩展性, 图片的可扩展性, 图片的自动上传扩展 作者:webabcd 介绍与众不同 windows ph ...

  4. jquery点击图片选中特效

    jquery点击图片选中特效 点击在线预览效果

  5. windows聚焦图片文件重命名bash脚本

    win10聚焦路径为: %localappdata%\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalStat ...

  6. 得到windows聚焦图片(windows 10)

    有些Windows聚焦图片确实很漂亮,很希望保留下来,但是Windows聚焦图片总更好,网上有得到聚焦图片的方法,每次都手动去弄真麻烦,于是自己编了一个小程序,自动得到Windows聚焦图片,下面是运 ...

  7. 使用 Python 获取 Windows 聚焦图片

    Windows 聚焦图片会定期更新,拿来做壁纸不错,它的目录是: %localappdata%\Packages\Microsoft.Windows.ContentDeliveryManager_cw ...

  8. ios中摄像头/相册获取图片,压缩图片,上传服务器方法总结

    相册 iphone的相册包含摄像头胶卷+用户计算机同步的部分照片.用户可以通过UIImagePickerController类提供的交互对话框来从相册中选择图像.但是,注意:相册中的图片机器路径无法直 ...

  9. android拍照获得图片及获得图片后剪切设置到ImageView

    ok,这次的项目需要用到设置头像功能,所以做了个总结,直接进入主题吧. 先说说怎么 使用android内置的相机拍照然后获取到这张照片吧 直接上代码: Intent intentFromCapture ...

随机推荐

  1. [poj] 2618 popular cows

    原题 这是一个强连通分量板子题. a thinks b is popular 即为a到b有一条边,要求被所有牛popular的牛的个数. 所求为对图进行强连通分量缩点后,没有出度的强连通分量里的点数( ...

  2. linux启动流程梳理【转】

    接触linux系统运维已经好几年了,常常被问到linux系统启动流程问题,刚好今天有空来梳理下这个过程:一般来说,所有的操作系统的启动流程基本就是: 总的来说,linux系统启动流程可以简单总结为以下 ...

  3. hdu1024 Max Sum Plus Plus的另一种解法

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1024 http://www.51nod.com/onlineJudge/questionCode.htm ...

  4. codevs 1269 匈牙利游戏——次短路(spfa)

    欢迎来到匈牙利游戏!布达佩斯(匈牙利首都)的街道形成了一个弯曲的单向网络. 你被强制要求参加一个赛跑作为一个TV秀的一部分节目,比赛中你需要穿越这些街道,从s开始,到t结束. 很自然的,你想要尽快的完 ...

  5. css样式小框架

    1.如div{...}会给所有的<div></div>增加样式. 2.名前井号“#”:对应html中的标签的id属性,写法为#name.如#p1{...}会给<p id= ...

  6. Linux Mint---更新软件源

    安装完系统之后第一件事情就是更新软件源,为接下来的各种工作作准备,这个也很简单,直接打开software source设置一下, 然后打开software manager更新一下就好了.

  7. V++ MFC CEdit输出数组 UNICODE TO ASCII码

    MFC怎么在静态编辑框中输出数组 //字符转ASCII码void CUTF8Dlg::OnBnClickedButtonCharAscii(){ // TODO: 在此添加控件通知处理程序代码 Upd ...

  8. 免格式化制作老毛桃PE工具

    由于移动硬盘数据很多,格式化制作太麻烦 先去老毛桃官网下载PE,生成ISO文件 将移动硬盘单独划分一个2G的空间用于装老毛桃,并格式化为FAT32格式,这样就避免全盘格式化了,只需要格式化这个分区   ...

  9. UVA 1589:Xiangqi (模拟 Grade D)

    题目: 象棋,黑棋只有将,红棋有帅车马炮.问是否死将. 思路: 对方将四个方向走一步,看看会不会被吃. 代码: 很难看……WA了很多发,还越界等等. #include <cstdio> # ...

  10. 测试 System.SysUtils.TStringHelper

    来自:http://www.cnblogs.com/del/archive/2013/06/14/3135002.html -------------------------------------- ...