cocos2d-x 2.2.0 图片选中聚焦 ,图片描边 CCClippingNode 实现
效果例如以下图
左边箭头是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 实现的更多相关文章
- android 开发 实现一个进入相机拍照后裁剪图片或者进入相册选中裁剪图片的功能
实现思维路径: 以进入相机拍照的思维路线为例子: 1.进入app 2.判断之前是否保存头像,如果有就显示历史图像 (下面代码中在getOldAvatar();方法中执行这个逻辑) 3.点击更换图像的B ...
- [Swift通天遁地]一、超级工具-(20)图片面部聚焦:使图像视图自动聚焦图片人物的面部位置
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- 与众不同 windows phone (43) - 8.0 相机和照片: 镜头的可扩展性, 图片的可扩展性, 图片的自动上传扩展
[源码下载] 与众不同 windows phone (43) - 8.0 相机和照片: 镜头的可扩展性, 图片的可扩展性, 图片的自动上传扩展 作者:webabcd 介绍与众不同 windows ph ...
- jquery点击图片选中特效
jquery点击图片选中特效 点击在线预览效果
- windows聚焦图片文件重命名bash脚本
win10聚焦路径为: %localappdata%\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalStat ...
- 得到windows聚焦图片(windows 10)
有些Windows聚焦图片确实很漂亮,很希望保留下来,但是Windows聚焦图片总更好,网上有得到聚焦图片的方法,每次都手动去弄真麻烦,于是自己编了一个小程序,自动得到Windows聚焦图片,下面是运 ...
- 使用 Python 获取 Windows 聚焦图片
Windows 聚焦图片会定期更新,拿来做壁纸不错,它的目录是: %localappdata%\Packages\Microsoft.Windows.ContentDeliveryManager_cw ...
- ios中摄像头/相册获取图片,压缩图片,上传服务器方法总结
相册 iphone的相册包含摄像头胶卷+用户计算机同步的部分照片.用户可以通过UIImagePickerController类提供的交互对话框来从相册中选择图像.但是,注意:相册中的图片机器路径无法直 ...
- android拍照获得图片及获得图片后剪切设置到ImageView
ok,这次的项目需要用到设置头像功能,所以做了个总结,直接进入主题吧. 先说说怎么 使用android内置的相机拍照然后获取到这张照片吧 直接上代码: Intent intentFromCapture ...
随机推荐
- hihoCoder 1403 后缀数组一·重复旋律(后缀数组+单调队列)
#1403 : 后缀数组一·重复旋律 时间限制:5000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi平时的一大兴趣爱好就是演奏钢琴.我们知道一个音乐旋律被表示为长度为 N 的数构成 ...
- uoj185 [ZJOI2016]小星星 【dp + 容斥】
题目链接 uoj185 题解 设\(f[i][j]\)表示\(i\)为根的子树,\(i\)号点对应图上\(j\)号点时的方案数 显然这样\(dp\)会使一些节点使用同一个节点,此时总的节点数就不满\( ...
- transform perspective的层级问题
如上图,在积分的数字元素上,使用了transform perspective,其层级就穿透了上面的遮罩层,关键代码如下: .mask { position: fixed; z-index:; } .f ...
- Codeforces Round #359 (Div. 2) C
C. Robbers' watch time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- linux总结shell
一.Shell脚本常用的头部格式: 头部的作用就是告知linux此脚本的类型: 常用的头部格式如下:(/bin/bash,是bash的路径,如果不知道路径可以通过which bash进行查看,其它命令 ...
- Html5学习进阶三 Input 类型
HTML5 新的 Input 类型 HTML5 拥有多个新的表单输入类型.这些新特性提供了更好的输入控制和验证. 本章全面介绍这些新的输入类型: email url number range Date ...
- VMWare虚拟机如何与主机共享文件夹(最容易看懂的讲解)附图~
http://wenku.baidu.com/view/54ab9e19227916888486d776.html 新建好虚拟机并安装好系统后,在编辑虚拟机设置--选项进行以下设置: 点添加 选择你要 ...
- Linux系统调用--getrlimit()与setrlimit()函数详解【转】
转自:http://www.cnblogs.com/niocai/archive/2012/04/01/2428128.html 功能描述:获取或设定资源使用限制.每种资源都有相关的软硬限制,软限制是 ...
- xen hypercall 的应用层实现
一句话描述: xen hypercall 在应用层的实现,最终都变成对 /proc/xen/privcmd 的 ioctl 系统调用 我们知道,xen 在应用层最上层的接口是 libxl , 基本上 ...
- C++ 采集音频流(PCM裸流)实现录音功能
与上一篇的“C++ 播放音频流(PCM裸流)” 点击打开链接 相对应,本篇是关于用C++实现录音功能的.同样是直接建一个win32控制台程序然后将代码拷过去改个文件名就可以用,也可以下载本人上传的相关 ...