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 ...
随机推荐
- 《c程序设计语言》读书笔记-5.6-指针重写getline等函数
#include <stdio.h> #include <math.h> #include <stdlib.h> #include <string.h> ...
- Python学习笔记(Django篇)——4、继续完善视图层
在demo/views.py中添加这些代码: def detail(request, question_id): returnHttpResponse("You're looking at ...
- python和shell对比
python和shell都是我们经常使用的脚本语言,平时python主要用来写一些小型的任务,shell则在使用liunx系统部署任务的时候用的比较多,由于两者有一些相似之处,时间长了容易混掉,所以这 ...
- Gradle for Android(二)全局设置、自定义BuildConfig
全局设置 如果有很多项目,可以设置全局来统一管理版本号或依赖库,根目录下build.gradle下: ext { compileSdkVersion = 23 buildToolsVersion = ...
- [ZJOI2008]树的统计——树链剖分
本题是一个树链剖分裸题,由于比较菜,老是RE,后来发现是因为使用了全局变量. /************************************************************ ...
- MFC 实现打印机打印功能
Visual C++6.0是开发Windows应用程序的强大工具,但是要通过它实现程序的打印功能,一直是初学者的一个难点,经常有朋友询问如何在VC中实现打印功能,他们往往感到在MFC提供的框架内实现这 ...
- AC日记——可能的路径 51nod 1247
可能的路径 思路: 看到题目想到gcd: 仔细一看是更相减损: 而gcd是更相减损的优化版: 所以,对于每组数据判断gcd是否相等就好: 来,上代码: #include <cstdio> ...
- (sql server)玩转-数据库行列转换
虽然开发过程中没用过行列转换,但是听说面试时常常会遇到这个问题,以前在网上也看到过大神的例子,今天自己仔细的玩了下,希望和大家分享一下了. 注意:列转行的方法可能是我独创的了,呵呵,因为在网上找不到哦 ...
- sql 事物 锁 快照(转发的,写的非常好)
隔离级别定义事务处理数据读取操作的隔离程度,在SQL Server中,隔离级别只会影响读操作申请的共享锁(Shared Lock),而不会影响写操作申请的互斥锁(Exclusive Lock),隔离级 ...
- [thinkphp] MD!! 数组构造的好好的,硬是有一个值无法写入数据库
我都要抓狂了,buildsql()方法又用不了,最后决定看runtime里面的文件.先删掉所有的runtime,然后提交一次,就可以在runtime里面看到对应解析后的文件,这样应该可以知道问题在哪. ...