效果例如以下图

左边箭头是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. java中的UDP总结

    先说一下关于InetAddress类,用一个小例子: import java.net.InetAddress; import java.net.UnknownHostException; public ...

  2. 倒置函数reverse的用法

    倒置字符串函数reverse:用于倒置字符串s中的各个字符的位置,如原来字符串中如果初始值为123456,则通过reverse函数可将其倒置为654321,程序如下:#include<stdio ...

  3. YYH的营救计划(NOIP模拟赛Round 6)

    题目描述 “咚咚咚……”“查水表!”原来是查水表来了,现在哪里找这么热心上门的查表员啊!YYH感动的热泪盈眶,开起了门…… YYH的父亲下班回家,街坊邻居说YYH被一群陌生人强行押上了警车!YYH的父 ...

  4. VIM使用技巧1

    .命令是vim中很重要的一个命令,用法如下: 加入有一个文件vimtest.txt,内容如下: 1 Line one  2 Line two                               ...

  5. kubernetes节点安装配置

    #环境安装,要与控制节点一致Centos 7 Linux release 7.3.1611网络: 互通配置主机名设置各个服务器的主机名hosts#查找kubernetes支持的docker版本Kube ...

  6. itatis中的数据库配置

    <!--com.microsoft.sqlserver.jdbc.SQLServerDriver --> <property name="JDBC.Driver" ...

  7. php7简短而安全的数组遍历方法

    在写 PHP 的数组遍历的时候,我们通常会这样写: foreach ($definition['keys'] as $id => $val) { // ... } 但是其实这样会引起一个重要的问 ...

  8. Google Chrome默认字体设置(Win)

    宋体·新宋体·仿宋字体.rar 下载地址:http://pan.baidu.com/s/1nt0l8FZ 或者:http://yunpan.cn/Qzv3UTTngbsID

  9. AC日记——The Meeting Place Cannot Be Changed codeforces 780b

    780B - The Meeting Place Cannot Be Changed 思路: 二分答案: 代码: #include <cstdio> #include <cstrin ...

  10. asp.net 网站模板怎么用,就是16aspx上面下下来的模板,里面有个sln文件,其他全是文件夹的东西

    .net写的程序模板一般都被写死了.那样只有通过程序改了.