码迷,mamicode.com
首页 > 其他好文 > 详细

cocos2d-x3.0 RenderTexture(二)

时间:2014-05-02 21:27:20      阅读:367      评论:0      收藏:0      [点我收藏+]

标签:cocos2d-x   cocostudio   ui   extension   rendertexture   


.h

#include "cocos-ext.h"
#include "ui/CocosGUI.h"
#include "cocostudio/CocoStudio.h"
USING_NS_CC;

USING_NS_CC_EXT;
using namespace ui;

.cpp

   auto background = LayerColor::create(Color4B(200,200,200,255));
        addChild(background);
        
        
        auto s = Director::getInstance()->getWinSize();
        auto spr_premulti = Sprite::create("fire.png");
        spr_premulti->setPosition(Point(s.width/2-16, s.height/2+36));
        
        
        
        
        
        
        auto spr_nonpremulti = Sprite::create("fire.png");
        spr_nonpremulti->setPosition(Point(s.width/2-16, s.height/2-16));
//
//        /* A2 & B2 setup */
        //着色文理     create参数1、着色的宽 2、着色的高  3、颜色
        auto rend = RenderTexture::create(s.width, s.height, Texture2D::PixelFormat::RGBA8888);
        
        auto spr_size = spr_premulti->getContentSize();
        rend->setKeepMatrix(true);
        Size pixelSize = Director::getInstance()->getWinSizeInPixels();
        
        rend->setVirtualViewport(Point(0, 0), Rect(0, 0, s.width, s.height), Rect(0, 0, pixelSize.width, pixelSize.height));
        
        
        // It‘s possible to modify the RenderTexture blending function by
        //        [[rend sprite] setBlendFunc:(BlendFunc) {GL_ONE, GL_ONE_MINUS_SRC_ALPHA}];

        rend->begin();
        
        spr_premulti->visit();
        spr_nonpremulti->visit();
        rend->end();
        rend->setPosition(Point(s.width / 2 + 56, s.height / 2));
       
        addChild(spr_premulti);
        addChild(spr_nonpremulti);
       
        addChild(rend);
        
bubuko.com,布布扣

cocos2d-x3.0 RenderTexture(二),布布扣,bubuko.com

cocos2d-x3.0 RenderTexture(二)

标签:cocos2d-x   cocostudio   ui   extension   rendertexture   

原文地址:http://blog.csdn.net/qqmcy/article/details/24850451

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!