2012-04-08 14:16:29 +08:00
|
|
|
#include "RenderTextureTest.h"
|
|
|
|
|
2015-04-09 12:23:47 +08:00
|
|
|
USING_NS_CC;
|
|
|
|
using namespace cocos2d::ui;
|
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
RenderTextureTests::RenderTextureTests()
|
|
|
|
{
|
|
|
|
ADD_TEST_CASE(RenderTextureSave);
|
|
|
|
ADD_TEST_CASE(RenderTextureIssue937);
|
|
|
|
ADD_TEST_CASE(RenderTextureZbuffer);
|
|
|
|
ADD_TEST_CASE(RenderTextureTestDepthStencil);
|
|
|
|
ADD_TEST_CASE(RenderTextureTargetNode);
|
|
|
|
ADD_TEST_CASE(SpriteRenderTextureBug);
|
|
|
|
ADD_TEST_CASE(RenderTexturePartTest);
|
2016-07-21 10:34:04 +08:00
|
|
|
ADD_TEST_CASE(Issue16113Test);
|
2013-02-28 16:35:42 +08:00
|
|
|
};
|
2011-02-25 11:31:49 +08:00
|
|
|
|
2012-04-08 14:16:29 +08:00
|
|
|
/**
|
|
|
|
* Impelmentation of RenderTextureSave
|
|
|
|
*/
|
|
|
|
RenderTextureSave::RenderTextureSave()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// create a render texture, this is what we are going to draw into
|
2013-12-23 17:13:41 +08:00
|
|
|
_target = RenderTexture::create(s.width, s.height, Texture2D::PixelFormat::RGBA8888);
|
2013-06-15 14:03:30 +08:00
|
|
|
_target->retain();
|
2014-05-15 01:07:09 +08:00
|
|
|
_target->setPosition(Vec2(s.width / 2, s.height / 2));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
// note that the render texture is a Node, and contains a sprite of its texture for convience,
|
|
|
|
// so we can just parent it to the scene like any other Node
|
2013-06-15 14:03:30 +08:00
|
|
|
this->addChild(_target, -1);
|
2013-10-23 16:14:03 +08:00
|
|
|
|
|
|
|
auto listener = EventListenerTouchAllAtOnce::create();
|
|
|
|
listener->onTouchesMoved = CC_CALLBACK_2(RenderTextureSave::onTouchesMoved, this);
|
2013-10-26 15:04:01 +08:00
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
2013-10-23 16:14:03 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// Save Image menu
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont::setFontSize(16);
|
2013-08-16 16:05:27 +08:00
|
|
|
auto item1 = MenuItemFont::create("Save Image", CC_CALLBACK_1(RenderTextureSave::saveImage, this));
|
|
|
|
auto item2 = MenuItemFont::create("Clear", CC_CALLBACK_1(RenderTextureSave::clearImage, this));
|
2014-07-10 00:45:27 +08:00
|
|
|
auto menu = Menu::create(item1, item2, nullptr);
|
2012-04-19 14:35:52 +08:00
|
|
|
this->addChild(menu);
|
|
|
|
menu->alignItemsVertically();
|
2014-05-15 01:07:09 +08:00
|
|
|
menu->setPosition(Vec2(VisibleRect::rightTop().x - 80, VisibleRect::rightTop().y - 30));
|
2012-04-08 14:16:29 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string RenderTextureSave::title() const
|
2012-04-08 14:16:29 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Touch the screen";
|
2012-04-08 14:16:29 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string RenderTextureSave::subtitle() const
|
2012-04-08 14:16:29 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Press 'Save Image' to create an snapshot of the render texture";
|
2012-04-08 14:16:29 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void RenderTextureSave::clearImage(cocos2d::Ref *sender)
|
2012-04-08 14:16:29 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_target->clear(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1());
|
2012-04-08 14:16:29 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void RenderTextureSave::saveImage(cocos2d::Ref *sender)
|
2012-04-08 14:16:29 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
static int counter = 0;
|
2012-04-08 14:16:29 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
char png[20];
|
|
|
|
sprintf(png, "image-%d.png", counter);
|
|
|
|
|
2014-08-12 10:50:57 +08:00
|
|
|
auto callback = [&](RenderTexture* rt, const std::string& path)
|
2014-03-07 17:41:51 +08:00
|
|
|
{
|
2014-08-12 10:50:57 +08:00
|
|
|
auto sprite = Sprite::create(path);
|
2014-03-07 17:41:51 +08:00
|
|
|
addChild(sprite);
|
|
|
|
sprite->setScale(0.3f);
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition(Vec2(40, 40));
|
2014-03-07 17:41:51 +08:00
|
|
|
sprite->setRotation(counter * 3);
|
|
|
|
};
|
2014-08-12 10:50:57 +08:00
|
|
|
|
|
|
|
_target->saveToFile(png, Image::Format::PNG, true, callback);
|
2015-03-19 16:39:45 +08:00
|
|
|
//Add this function to avoid crash if we switch to a new scene.
|
|
|
|
Director::getInstance()->getRenderer()->render();
|
2014-08-12 10:50:57 +08:00
|
|
|
CCLOG("Image saved %s", png);
|
2012-04-08 14:16:29 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
counter++;
|
2012-04-08 14:16:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
RenderTextureSave::~RenderTextureSave()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_target->release();
|
2013-11-07 21:48:39 +08:00
|
|
|
Director::getInstance()->getTextureCache()->removeUnusedTextures();
|
2012-04-08 14:16:29 +08:00
|
|
|
}
|
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
void RenderTextureSave::onTouchesMoved(const std::vector<Touch*>& touches, Event* event)
|
2012-04-08 14:16:29 +08:00
|
|
|
{
|
2013-09-03 18:22:03 +08:00
|
|
|
auto touch = touches[0];
|
2013-08-16 16:05:27 +08:00
|
|
|
auto start = touch->getLocation();
|
|
|
|
auto end = touch->getPreviousLocation();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// begin drawing to the render texture
|
2013-06-15 14:03:30 +08:00
|
|
|
_target->begin();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// for extra points, we'll draw this smoothly from the last position and vary the sprite's
|
|
|
|
// scale/rotation/offset
|
2013-07-11 16:38:58 +08:00
|
|
|
float distance = start.getDistance(end);
|
2012-04-19 14:35:52 +08:00
|
|
|
if (distance > 1)
|
|
|
|
{
|
|
|
|
int d = (int)distance;
|
2014-01-06 09:49:04 +08:00
|
|
|
_brushs.clear();
|
|
|
|
for(int i = 0; i < d; ++i)
|
|
|
|
{
|
|
|
|
Sprite * sprite = Sprite::create("Images/fire.png");
|
|
|
|
sprite->setColor(Color3B::RED);
|
|
|
|
sprite->setOpacity(20);
|
|
|
|
_brushs.pushBack(sprite);
|
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
for (int i = 0; i < d; i++)
|
|
|
|
{
|
|
|
|
float difx = end.x - start.x;
|
|
|
|
float dify = end.y - start.y;
|
|
|
|
float delta = (float)i / distance;
|
2014-05-15 01:07:09 +08:00
|
|
|
_brushs.at(i)->setPosition(Vec2(start.x + (difx * delta), start.y + (dify * delta)));
|
2014-01-06 09:49:04 +08:00
|
|
|
_brushs.at(i)->setRotation(rand() % 360);
|
2012-04-19 14:35:52 +08:00
|
|
|
float r = (float)(rand() % 50 / 50.f) + 0.25f;
|
2014-01-06 09:49:04 +08:00
|
|
|
_brushs.at(i)->setScale(r);
|
2013-07-05 16:49:22 +08:00
|
|
|
/*_brush->setColor(Color3B(CCRANDOM_0_1() * 127 + 128, 255, 255));*/
|
2012-04-19 14:35:52 +08:00
|
|
|
// Use CCRANDOM_0_1() will cause error when loading libtests.so on android, I don't know why.
|
2014-01-06 09:49:04 +08:00
|
|
|
_brushs.at(i)->setColor(Color3B(rand() % 127 + 128, 255, 255));
|
2012-04-19 14:35:52 +08:00
|
|
|
// Call visit to draw the brush, don't call draw..
|
2014-01-06 09:49:04 +08:00
|
|
|
_brushs.at(i)->visit();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// finish drawing and return context back to the screen
|
2013-06-15 14:03:30 +08:00
|
|
|
_target->end();
|
2012-04-08 14:16:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Impelmentation of RenderTextureIssue937
|
|
|
|
*/
|
|
|
|
|
|
|
|
RenderTextureIssue937::RenderTextureIssue937()
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* 1 2
|
|
|
|
* A: A1 A2
|
|
|
|
*
|
|
|
|
* B: B1 B2
|
|
|
|
*
|
|
|
|
* A1: premulti sprite
|
|
|
|
* A2: premulti render
|
|
|
|
*
|
|
|
|
* B1: non-premulti sprite
|
|
|
|
* B2: non-premulti render
|
|
|
|
*/
|
2013-08-16 16:05:27 +08:00
|
|
|
auto background = LayerColor::create(Color4B(200,200,200,255));
|
2012-04-08 14:16:29 +08:00
|
|
|
addChild(background);
|
|
|
|
|
2014-04-09 13:40:43 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2013-08-16 16:05:27 +08:00
|
|
|
auto spr_premulti = Sprite::create("Images/fire.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
spr_premulti->setPosition(Vec2(s.width/2-16, s.height/2+16));
|
2012-04-08 14:16:29 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto spr_nonpremulti = Sprite::create("Images/fire.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
spr_nonpremulti->setPosition(Vec2(s.width/2-16, s.height/2-16));
|
2012-04-19 17:01:24 +08:00
|
|
|
|
2012-04-08 14:16:29 +08:00
|
|
|
/* A2 & B2 setup */
|
2013-12-23 17:13:41 +08:00
|
|
|
auto rend = RenderTexture::create(32, 64, Texture2D::PixelFormat::RGBA8888);
|
2012-04-08 14:16:29 +08:00
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
if (nullptr == rend)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2012-04-08 14:16:29 +08:00
|
|
|
|
2014-04-09 13:40:43 +08:00
|
|
|
auto spr_size = spr_premulti->getContentSize();
|
|
|
|
rend->setKeepMatrix(true);
|
|
|
|
Size pixelSize = Director::getInstance()->getWinSizeInPixels();
|
2014-05-15 01:07:09 +08:00
|
|
|
rend->setVirtualViewport(Vec2(s.width/2-32, s.height/2-32),Rect(0,0,s.width,s.height),Rect(0,0,pixelSize.width,pixelSize.height));
|
2014-04-09 13:40:43 +08:00
|
|
|
|
2012-04-08 14:16:29 +08:00
|
|
|
// It's possible to modify the RenderTexture blending function by
|
2013-07-05 16:49:22 +08:00
|
|
|
// [[rend sprite] setBlendFunc:(BlendFunc) {GL_ONE, GL_ONE_MINUS_SRC_ALPHA}];
|
2012-04-08 14:16:29 +08:00
|
|
|
rend->begin();
|
|
|
|
spr_premulti->visit();
|
|
|
|
spr_nonpremulti->visit();
|
2014-04-09 13:40:43 +08:00
|
|
|
rend->end();
|
2012-04-08 14:16:29 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
rend->setPosition(Vec2(s.width/2+16, s.height/2));
|
2012-04-08 14:16:29 +08:00
|
|
|
|
|
|
|
addChild(spr_nonpremulti);
|
|
|
|
addChild(spr_premulti);
|
|
|
|
addChild(rend);
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string RenderTextureIssue937::title() const
|
2012-04-08 14:16:29 +08:00
|
|
|
{
|
|
|
|
return "Testing issue #937";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string RenderTextureIssue937::subtitle() const
|
2012-04-08 14:16:29 +08:00
|
|
|
{
|
|
|
|
return "All images should be equal...";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Impelmentation of RenderTextureZbuffer
|
|
|
|
*/
|
|
|
|
|
|
|
|
RenderTextureZbuffer::RenderTextureZbuffer()
|
|
|
|
{
|
2013-10-23 16:14:03 +08:00
|
|
|
auto listener = EventListenerTouchAllAtOnce::create();
|
|
|
|
listener->onTouchesBegan = CC_CALLBACK_2(RenderTextureZbuffer::onTouchesBegan, this);
|
|
|
|
listener->onTouchesMoved = CC_CALLBACK_2(RenderTextureZbuffer::onTouchesMoved, this);
|
|
|
|
listener->onTouchesEnded = CC_CALLBACK_2(RenderTextureZbuffer::onTouchesEnded, this);
|
2013-10-26 15:04:01 +08:00
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
2013-10-23 16:14:03 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto size = Director::getInstance()->getWinSize();
|
2014-04-09 23:31:05 +08:00
|
|
|
auto label = Label::createWithTTF("vertexZ = 50", "fonts/Marker Felt.ttf", 64);
|
2014-05-15 01:07:09 +08:00
|
|
|
label->setPosition(Vec2(size.width / 2, size.height * 0.25f));
|
2012-04-19 14:35:52 +08:00
|
|
|
this->addChild(label);
|
|
|
|
|
2014-04-09 23:31:05 +08:00
|
|
|
auto label2 = Label::createWithTTF("vertexZ = 0", "fonts/Marker Felt.ttf", 64);
|
2014-05-15 01:07:09 +08:00
|
|
|
label2->setPosition(Vec2(size.width / 2, size.height * 0.5f));
|
2012-04-19 14:35:52 +08:00
|
|
|
this->addChild(label2);
|
|
|
|
|
2014-04-09 23:31:05 +08:00
|
|
|
auto label3 = Label::createWithTTF("vertexZ = -50", "fonts/Marker Felt.ttf", 64);
|
2014-05-15 01:07:09 +08:00
|
|
|
label3->setPosition(Vec2(size.width / 2, size.height * 0.75f));
|
2012-04-19 14:35:52 +08:00
|
|
|
this->addChild(label3);
|
|
|
|
|
2014-03-24 10:12:40 +08:00
|
|
|
label->setPositionZ(50);
|
|
|
|
label2->setPositionZ(0);
|
|
|
|
label3->setPositionZ(-50);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("Images/bugs/circle.plist");
|
2013-06-20 14:17:10 +08:00
|
|
|
mgr = SpriteBatchNode::create("Images/bugs/circle.png", 9);
|
2012-04-19 14:35:52 +08:00
|
|
|
this->addChild(mgr);
|
2013-06-20 14:17:10 +08:00
|
|
|
sp1 = Sprite::createWithSpriteFrameName("circle.png");
|
|
|
|
sp2 = Sprite::createWithSpriteFrameName("circle.png");
|
|
|
|
sp3 = Sprite::createWithSpriteFrameName("circle.png");
|
|
|
|
sp4 = Sprite::createWithSpriteFrameName("circle.png");
|
|
|
|
sp5 = Sprite::createWithSpriteFrameName("circle.png");
|
|
|
|
sp6 = Sprite::createWithSpriteFrameName("circle.png");
|
|
|
|
sp7 = Sprite::createWithSpriteFrameName("circle.png");
|
|
|
|
sp8 = Sprite::createWithSpriteFrameName("circle.png");
|
|
|
|
sp9 = Sprite::createWithSpriteFrameName("circle.png");
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
mgr->addChild(sp1, 9);
|
|
|
|
mgr->addChild(sp2, 8);
|
|
|
|
mgr->addChild(sp3, 7);
|
|
|
|
mgr->addChild(sp4, 6);
|
|
|
|
mgr->addChild(sp5, 5);
|
|
|
|
mgr->addChild(sp6, 4);
|
|
|
|
mgr->addChild(sp7, 3);
|
|
|
|
mgr->addChild(sp8, 2);
|
|
|
|
mgr->addChild(sp9, 1);
|
|
|
|
|
2014-03-24 10:12:40 +08:00
|
|
|
sp1->setPositionZ(400);
|
|
|
|
sp2->setPositionZ(300);
|
|
|
|
sp3->setPositionZ(200);
|
|
|
|
sp4->setPositionZ(100);
|
|
|
|
sp5->setPositionZ(0);
|
|
|
|
sp6->setPositionZ(-100);
|
|
|
|
sp7->setPositionZ(-200);
|
|
|
|
sp8->setPositionZ(-300);
|
|
|
|
sp9->setPositionZ(-400);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
sp9->setScale(2);
|
2013-07-08 18:11:32 +08:00
|
|
|
sp9->setColor(Color3B::YELLOW);
|
2012-04-08 14:16:29 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string RenderTextureZbuffer::title() const
|
2012-04-08 14:16:29 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Testing Z Buffer in Render Texture";
|
2012-04-08 14:16:29 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string RenderTextureZbuffer::subtitle() const
|
2012-04-08 14:16:29 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Touch screen. It should be green";
|
2012-04-08 14:16:29 +08:00
|
|
|
}
|
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
void RenderTextureZbuffer::onTouchesBegan(const std::vector<Touch*>& touches, Event *event)
|
2012-04-08 14:16:29 +08:00
|
|
|
{
|
2013-06-22 11:02:43 +08:00
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
for (auto &item: touches)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto touch = static_cast<Touch*>(item);
|
|
|
|
auto location = touch->getLocation();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
sp1->setPosition(location);
|
|
|
|
sp2->setPosition(location);
|
|
|
|
sp3->setPosition(location);
|
|
|
|
sp4->setPosition(location);
|
|
|
|
sp5->setPosition(location);
|
|
|
|
sp6->setPosition(location);
|
|
|
|
sp7->setPosition(location);
|
|
|
|
sp8->setPosition(location);
|
|
|
|
sp9->setPosition(location);
|
|
|
|
}
|
2012-04-08 14:16:29 +08:00
|
|
|
}
|
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
void RenderTextureZbuffer::onTouchesMoved(const std::vector<Touch*>& touches, Event* event)
|
2012-04-08 14:16:29 +08:00
|
|
|
{
|
2013-09-03 18:22:03 +08:00
|
|
|
for (auto &item: touches)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto touch = static_cast<Touch*>(item);
|
|
|
|
auto location = touch->getLocation();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
sp1->setPosition(location);
|
|
|
|
sp2->setPosition(location);
|
|
|
|
sp3->setPosition(location);
|
|
|
|
sp4->setPosition(location);
|
|
|
|
sp5->setPosition(location);
|
|
|
|
sp6->setPosition(location);
|
|
|
|
sp7->setPosition(location);
|
|
|
|
sp8->setPosition(location);
|
|
|
|
sp9->setPosition(location);
|
|
|
|
}
|
2012-04-08 14:16:29 +08:00
|
|
|
}
|
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
void RenderTextureZbuffer::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
|
2012-04-08 14:16:29 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
this->renderScreenShot();
|
2012-04-08 14:16:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void RenderTextureZbuffer::renderScreenShot()
|
|
|
|
{
|
2013-12-23 17:13:41 +08:00
|
|
|
auto texture = RenderTexture::create(512, 512);
|
2014-07-10 00:45:27 +08:00
|
|
|
if (nullptr == texture)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2014-04-29 15:08:44 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
texture->begin();
|
2012-04-08 14:16:29 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
this->visit();
|
2012-04-08 14:16:29 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
texture->end();
|
2012-04-08 14:16:29 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto sprite = Sprite::createWithTexture(texture->getSprite()->getTexture());
|
2012-04-08 14:16:29 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition(Vec2(256, 256));
|
2012-04-19 14:35:52 +08:00
|
|
|
sprite->setOpacity(182);
|
2013-09-16 20:38:03 +08:00
|
|
|
sprite->setFlippedY(1);
|
2012-04-19 14:35:52 +08:00
|
|
|
this->addChild(sprite, 999999);
|
2013-07-08 18:11:32 +08:00
|
|
|
sprite->setColor(Color3B::GREEN);
|
2012-04-08 14:16:29 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
sprite->runAction(Sequence::create(FadeTo::create(2, 0),
|
|
|
|
Hide::create(),
|
2014-07-10 00:45:27 +08:00
|
|
|
nullptr));
|
2012-04-08 14:16:29 +08:00
|
|
|
}
|
|
|
|
|
2014-03-04 15:07:54 +08:00
|
|
|
RenderTexturePartTest::RenderTexturePartTest()
|
|
|
|
{
|
|
|
|
auto sprite1 = Sprite::create("Images/grossini.png");
|
|
|
|
auto sprite11 = Sprite::create("Images/grossini.png");
|
|
|
|
auto sprite2 = Sprite::create("Images/grossinis_sister1.png");
|
|
|
|
auto sprite22 = Sprite::create("Images/grossinis_sister1.png");
|
|
|
|
Size size = Director::getInstance()->getWinSize();
|
|
|
|
Size sprite1Size = sprite1->getContentSize();
|
|
|
|
sprite1->setPosition((size.width-sprite1Size.width)/2 - 20, (size.height - sprite1Size.height)/2 - 20);
|
|
|
|
sprite11->setPosition(size.width/2 + 20, (size.height - sprite1Size.height)/2 - 20);
|
|
|
|
|
|
|
|
sprite2->setPosition((size.width-sprite1Size.width)/2 - 20, size.height/2 + 20);
|
|
|
|
sprite22->setPosition(size.width/2 + 20, size.height/2 + 20);
|
|
|
|
|
|
|
|
addChild(sprite1);
|
|
|
|
addChild(sprite11);
|
|
|
|
addChild(sprite2);
|
|
|
|
addChild(sprite22);
|
|
|
|
|
|
|
|
_rend = RenderTexture::create(200, 200, Texture2D::PixelFormat::RGBA8888);
|
|
|
|
_rend->retain();
|
|
|
|
_rend->setKeepMatrix(true);
|
|
|
|
Size pixelSize = Director::getInstance()->getWinSizeInPixels();
|
2014-05-15 01:07:09 +08:00
|
|
|
_rend->setVirtualViewport(Vec2(size.width/2-150, size.height/2-150),Rect(0,0,size.width,size.height),Rect(0,0,pixelSize.width,pixelSize.height));
|
2014-03-04 15:07:54 +08:00
|
|
|
|
|
|
|
_rend->beginWithClear(1, 0, 0, 1);
|
|
|
|
sprite1->visit();
|
|
|
|
sprite11->visit();
|
|
|
|
sprite2->visit();
|
|
|
|
sprite22->visit();
|
|
|
|
_rend->end();
|
|
|
|
|
|
|
|
_spriteDraw = Sprite::createWithTexture(_rend->getSprite()->getTexture());
|
2014-05-15 01:07:09 +08:00
|
|
|
FiniteTimeAction* baseAction = MoveBy::create(1, Vec2(size.width,0));
|
2014-03-04 15:07:54 +08:00
|
|
|
_spriteDraw->setPosition(0,size.height/2);
|
2014-03-04 15:24:06 +08:00
|
|
|
_spriteDraw->setScaleY(-1);
|
2014-03-04 15:07:54 +08:00
|
|
|
_spriteDraw->runAction(RepeatForever::create(Sequence::create
|
2014-07-10 00:45:27 +08:00
|
|
|
(baseAction,baseAction->reverse(), nullptr)));
|
2014-03-04 15:07:54 +08:00
|
|
|
addChild(_spriteDraw);
|
|
|
|
}
|
|
|
|
|
|
|
|
RenderTexturePartTest::~RenderTexturePartTest()
|
|
|
|
{
|
|
|
|
CC_SAFE_RELEASE(_rend);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string RenderTexturePartTest::title() const
|
|
|
|
{
|
|
|
|
return "Render Texture Part Test";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string RenderTexturePartTest::subtitle() const
|
|
|
|
{
|
|
|
|
return "Only Grabbing a sub region of fullscreen";
|
|
|
|
}
|
|
|
|
|
2012-06-14 18:37:57 +08:00
|
|
|
// RenderTextureTestDepthStencil
|
|
|
|
|
|
|
|
RenderTextureTestDepthStencil::RenderTextureTestDepthStencil()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-06-14 18:37:57 +08:00
|
|
|
|
2013-12-31 14:48:07 +08:00
|
|
|
_spriteDS = Sprite::create("Images/fire.png");
|
|
|
|
_spriteDS->retain();
|
2014-05-15 01:07:09 +08:00
|
|
|
_spriteDS->setPosition(Vec2(s.width * 0.25f, 0));
|
2013-12-31 14:48:07 +08:00
|
|
|
_spriteDS->setScale(10);
|
|
|
|
|
|
|
|
_spriteDraw = Sprite::create("Images/fire.png");
|
|
|
|
_spriteDraw->retain();
|
2014-05-15 01:07:09 +08:00
|
|
|
_spriteDraw->setPosition(Vec2(s.width * 0.25f, 0));
|
2013-12-31 14:48:07 +08:00
|
|
|
_spriteDraw->setScale(10);
|
|
|
|
//! move sprite half width and height, and draw only where not marked
|
2014-05-15 01:07:09 +08:00
|
|
|
_spriteDraw->setPosition(_spriteDraw->getPosition() + Vec2(_spriteDraw->getContentSize().width * _spriteDraw->getScale() * 0.5, _spriteDraw->getContentSize().height * _spriteDraw->getScale() * 0.5));
|
2013-12-31 14:48:07 +08:00
|
|
|
|
|
|
|
_rend = RenderTexture::create(s.width, s.height, Texture2D::PixelFormat::RGBA4444, GL_DEPTH24_STENCIL8);
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
_rend->setPosition(Vec2(s.width * 0.5f, s.height * 0.5f));
|
2013-12-31 14:48:07 +08:00
|
|
|
|
|
|
|
this->addChild(_rend);
|
|
|
|
}
|
|
|
|
|
|
|
|
RenderTextureTestDepthStencil::~RenderTextureTestDepthStencil()
|
|
|
|
{
|
|
|
|
CC_SAFE_RELEASE(_spriteDraw);
|
|
|
|
CC_SAFE_RELEASE(_spriteDS);
|
|
|
|
}
|
2012-06-14 18:37:57 +08:00
|
|
|
|
2014-05-31 07:42:05 +08:00
|
|
|
void RenderTextureTestDepthStencil::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
|
2013-12-31 14:48:07 +08:00
|
|
|
{
|
2015-01-16 06:00:49 +08:00
|
|
|
_renderCmds[0].init(_globalZOrder, transform, flags);
|
2013-12-31 11:49:46 +08:00
|
|
|
_renderCmds[0].func = CC_CALLBACK_0(RenderTextureTestDepthStencil::onBeforeClear, this);
|
2014-03-01 08:10:48 +08:00
|
|
|
renderer->addCommand(&_renderCmds[0]);
|
|
|
|
|
2013-12-31 14:48:07 +08:00
|
|
|
_rend->beginWithClear(0, 0, 0, 0, 0, 0);
|
2013-12-31 11:49:46 +08:00
|
|
|
|
2015-01-16 06:00:49 +08:00
|
|
|
_renderCmds[1].init(_globalZOrder, transform, flags);
|
2013-12-31 11:49:46 +08:00
|
|
|
_renderCmds[1].func = CC_CALLBACK_0(RenderTextureTestDepthStencil::onBeforeStencil, this);
|
2014-03-01 08:10:48 +08:00
|
|
|
renderer->addCommand(&_renderCmds[1]);
|
|
|
|
|
2013-12-31 14:48:07 +08:00
|
|
|
_spriteDS->visit();
|
|
|
|
|
2015-01-16 06:00:49 +08:00
|
|
|
_renderCmds[2].init(_globalZOrder, transform, flags);
|
2013-12-31 11:49:46 +08:00
|
|
|
_renderCmds[2].func = CC_CALLBACK_0(RenderTextureTestDepthStencil::onBeforDraw, this);
|
2014-03-01 08:10:48 +08:00
|
|
|
renderer->addCommand(&_renderCmds[2]);
|
|
|
|
|
2013-12-31 14:48:07 +08:00
|
|
|
_spriteDraw->visit();
|
|
|
|
|
|
|
|
_rend->end();
|
2013-12-31 11:49:46 +08:00
|
|
|
|
2015-01-16 06:00:49 +08:00
|
|
|
_renderCmds[3].init(_globalZOrder, transform, flags);
|
2013-12-31 11:49:46 +08:00
|
|
|
_renderCmds[3].func = CC_CALLBACK_0(RenderTextureTestDepthStencil::onAfterDraw, this);
|
2014-03-01 08:10:48 +08:00
|
|
|
renderer->addCommand(&_renderCmds[3]);
|
2012-06-14 18:37:57 +08:00
|
|
|
}
|
|
|
|
|
2013-12-31 11:49:46 +08:00
|
|
|
void RenderTextureTestDepthStencil::onBeforeClear()
|
|
|
|
{
|
|
|
|
glStencilMask(0xFF);
|
2015-06-13 06:28:29 +08:00
|
|
|
|
|
|
|
// Since cocos2d-x v3.7, users should avoid calling GL directly because it will break the internal GL state
|
|
|
|
// But if users must call GL directly, they should update the state manually,
|
2015-07-01 14:06:37 +08:00
|
|
|
// RenderState::StateBlock::_defaultState->setStencilWrite(0xFF);
|
2013-12-31 11:49:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void RenderTextureTestDepthStencil::onBeforeStencil()
|
|
|
|
{
|
|
|
|
//! mark sprite quad into stencil buffer
|
2013-12-31 14:48:07 +08:00
|
|
|
glEnable(GL_STENCIL_TEST);
|
2013-12-31 11:49:46 +08:00
|
|
|
glStencilFunc(GL_NEVER, 1, 0xFF);
|
|
|
|
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
|
2015-06-13 06:28:29 +08:00
|
|
|
|
|
|
|
// Since cocos2d-x v3.7, users should avoid calling GL directly because it will break the internal GL state
|
|
|
|
// But if users must call GL directly, they should update the state manually,
|
2015-07-01 14:06:37 +08:00
|
|
|
// RenderState::StateBlock::_defaultState->setStencilTest(true);
|
|
|
|
// RenderState::StateBlock::_defaultState->setStencilFunction(RenderState::STENCIL_NEVER, 1, 0xFF);
|
|
|
|
// RenderState::StateBlock::_defaultState->setStencilOperation(RenderState::STENCIL_OP_REPLACE, RenderState::STENCIL_OP_REPLACE, RenderState::STENCIL_OP_REPLACE);
|
2013-12-31 11:49:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void RenderTextureTestDepthStencil::onBeforDraw()
|
|
|
|
{
|
|
|
|
glStencilFunc(GL_NOTEQUAL, 1, 0xFF);
|
2015-06-13 06:28:29 +08:00
|
|
|
|
|
|
|
// Since cocos2d-x v3.7, users should avoid calling GL directly because it will break the internal GL state
|
|
|
|
// But if users must call GL directly, they should update the state manually,
|
2015-07-01 14:06:37 +08:00
|
|
|
// RenderState::StateBlock::_defaultState->setStencilFunction(RenderState::STENCIL_NOTEQUAL, 1, 0xFF);
|
2013-12-31 11:49:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void RenderTextureTestDepthStencil::onAfterDraw()
|
|
|
|
{
|
2013-12-31 14:48:07 +08:00
|
|
|
glDisable(GL_STENCIL_TEST);
|
2015-06-13 06:28:29 +08:00
|
|
|
|
|
|
|
// Since cocos2d-x v3.7, users should avoid calling GL directly because it will break the internal GL state
|
|
|
|
// But if users must call GL directly, they should update the state manually,
|
2015-07-01 14:06:37 +08:00
|
|
|
// RenderState::StateBlock::_defaultState->setStencilTest(false);
|
2013-12-31 11:49:46 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string RenderTextureTestDepthStencil::title() const
|
2012-06-12 15:55:23 +08:00
|
|
|
{
|
|
|
|
return "Testing depthStencil attachment";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string RenderTextureTestDepthStencil::subtitle() const
|
2012-06-14 18:37:57 +08:00
|
|
|
{
|
|
|
|
return "Circle should be missing 1/4 of its region";
|
|
|
|
}
|
2012-06-12 15:55:23 +08:00
|
|
|
|
2012-11-20 16:45:59 +08:00
|
|
|
// RenderTextureTest
|
|
|
|
RenderTextureTargetNode::RenderTextureTargetNode()
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* 1 2
|
|
|
|
* A: A1 A2
|
|
|
|
*
|
|
|
|
* B: B1 B2
|
|
|
|
*
|
|
|
|
* A1: premulti sprite
|
|
|
|
* A2: premulti render
|
|
|
|
*
|
|
|
|
* B1: non-premulti sprite
|
|
|
|
* B2: non-premulti render
|
|
|
|
*/
|
2013-08-16 16:05:27 +08:00
|
|
|
auto background = LayerColor::create(Color4B(40,40,40,255));
|
2012-11-20 16:45:59 +08:00
|
|
|
addChild(background);
|
|
|
|
|
|
|
|
// sprite 1
|
2013-06-20 14:17:10 +08:00
|
|
|
sprite1 = Sprite::create("Images/fire.png");
|
2012-11-20 16:45:59 +08:00
|
|
|
|
|
|
|
// sprite 2
|
2013-06-20 14:17:10 +08:00
|
|
|
sprite2 = Sprite::create("Images/fire_rgba8888.pvr");
|
2012-11-20 16:45:59 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-11-20 16:45:59 +08:00
|
|
|
|
|
|
|
/* Create the render texture */
|
2013-12-23 17:13:41 +08:00
|
|
|
auto renderTexture = RenderTexture::create(s.width, s.height, Texture2D::PixelFormat::RGBA4444);
|
2012-11-20 16:45:59 +08:00
|
|
|
this->renderTexture = renderTexture;
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
renderTexture->setPosition(Vec2(s.width/2, s.height/2));
|
2014-05-07 16:37:21 +08:00
|
|
|
// renderTexture->setScale(2.0f);
|
2012-11-20 16:45:59 +08:00
|
|
|
|
|
|
|
/* add the sprites to the render texture */
|
|
|
|
renderTexture->addChild(sprite1);
|
|
|
|
renderTexture->addChild(sprite2);
|
2013-07-05 16:49:22 +08:00
|
|
|
renderTexture->setClearColor(Color4F(0, 0, 0, 0));
|
2012-11-20 16:45:59 +08:00
|
|
|
renderTexture->setClearFlags(GL_COLOR_BUFFER_BIT);
|
|
|
|
|
|
|
|
/* add the render texture to the scene */
|
|
|
|
addChild(renderTexture);
|
|
|
|
|
|
|
|
renderTexture->setAutoDraw(true);
|
|
|
|
|
|
|
|
scheduleUpdate();
|
|
|
|
|
|
|
|
// Toggle clear on / off
|
2013-08-16 16:05:27 +08:00
|
|
|
auto item = MenuItemFont::create("Clear On/Off", CC_CALLBACK_1(RenderTextureTargetNode::touched, this));
|
2014-07-10 00:45:27 +08:00
|
|
|
auto menu = Menu::create(item, nullptr);
|
2012-11-20 16:45:59 +08:00
|
|
|
addChild(menu);
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
menu->setPosition(Vec2(s.width/2, s.height/2));
|
2012-11-20 16:45:59 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void RenderTextureTargetNode::touched(Ref* sender)
|
2012-11-20 16:45:59 +08:00
|
|
|
{
|
|
|
|
if (renderTexture->getClearFlags() == 0)
|
|
|
|
{
|
|
|
|
renderTexture->setClearFlags(GL_COLOR_BUFFER_BIT);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
renderTexture->setClearFlags(0);
|
2013-07-05 16:49:22 +08:00
|
|
|
renderTexture->setClearColor(Color4F( CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1));
|
2012-11-20 16:45:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderTextureTargetNode::update(float dt)
|
|
|
|
{
|
|
|
|
static float time = 0;
|
|
|
|
float r = 80;
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite1->setPosition(Vec2(cosf(time * 2) * r, sinf(time * 2) * r));
|
|
|
|
sprite2->setPosition(Vec2(sinf(time * 2) * r, cosf(time * 2) * r));
|
2012-11-20 16:45:59 +08:00
|
|
|
|
|
|
|
time += dt;
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string RenderTextureTargetNode::title() const
|
2012-11-20 16:45:59 +08:00
|
|
|
{
|
|
|
|
return "Testing Render Target Node";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string RenderTextureTargetNode::subtitle() const
|
2012-11-20 16:45:59 +08:00
|
|
|
{
|
|
|
|
return "Sprites should be equal and move with each frame";
|
|
|
|
}
|
|
|
|
|
2013-02-28 16:35:42 +08:00
|
|
|
// SpriteRenderTextureBug
|
|
|
|
|
2013-11-15 08:33:43 +08:00
|
|
|
SpriteRenderTextureBug::SimpleSprite::SimpleSprite() : _rt(nullptr) {}
|
2014-04-11 16:05:22 +08:00
|
|
|
SpriteRenderTextureBug::SimpleSprite::~SimpleSprite()
|
|
|
|
{
|
|
|
|
CC_SAFE_RELEASE(_rt);
|
|
|
|
}
|
2013-02-28 16:35:42 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
SpriteRenderTextureBug::SimpleSprite* SpriteRenderTextureBug::SimpleSprite::create(const char* filename, const Rect &rect)
|
2013-02-28 16:35:42 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
auto sprite = new (std::nothrow) SimpleSprite();
|
2013-02-28 16:35:42 +08:00
|
|
|
if (sprite && sprite->initWithFile(filename, rect))
|
|
|
|
{
|
|
|
|
sprite->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(sprite);
|
|
|
|
}
|
|
|
|
|
|
|
|
return sprite;
|
|
|
|
}
|
|
|
|
|
2014-05-31 07:42:05 +08:00
|
|
|
void SpriteRenderTextureBug::SimpleSprite::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
|
2013-02-28 16:35:42 +08:00
|
|
|
{
|
2013-11-15 08:33:43 +08:00
|
|
|
if (_rt == nullptr)
|
2013-02-28 16:35:42 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2013-12-23 17:13:41 +08:00
|
|
|
_rt = RenderTexture::create(s.width, s.height, Texture2D::PixelFormat::RGBA8888);
|
2013-11-15 08:33:43 +08:00
|
|
|
_rt->retain();
|
2013-02-28 16:35:42 +08:00
|
|
|
}
|
2013-11-15 08:33:43 +08:00
|
|
|
_rt->beginWithClear(0.0f, 0.0f, 0.0f, 1.0f);
|
|
|
|
_rt->end();
|
2014-04-11 16:05:22 +08:00
|
|
|
|
2014-05-31 07:42:05 +08:00
|
|
|
Sprite::draw(renderer, transform, flags);
|
2014-04-11 16:05:22 +08:00
|
|
|
|
2013-02-28 16:35:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SpriteRenderTextureBug::SpriteRenderTextureBug()
|
|
|
|
{
|
2013-10-23 16:14:03 +08:00
|
|
|
auto listener = EventListenerTouchAllAtOnce::create();
|
|
|
|
listener->onTouchesEnded = CC_CALLBACK_2(SpriteRenderTextureBug::onTouchesEnded, this);
|
2013-10-26 15:04:01 +08:00
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
2013-02-28 16:35:42 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2014-05-15 01:07:09 +08:00
|
|
|
addNewSpriteWithCoords(Vec2(s.width/2, s.height/2));
|
2013-02-28 16:35:42 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
SpriteRenderTextureBug::SimpleSprite* SpriteRenderTextureBug::addNewSpriteWithCoords(const Vec2& p)
|
2013-02-28 16:35:42 +08:00
|
|
|
{
|
|
|
|
int idx = CCRANDOM_0_1() * 1400 / 100;
|
|
|
|
int x = (idx%5) * 85;
|
|
|
|
int y = (idx/5) * 121;
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto sprite = SpriteRenderTextureBug::SimpleSprite::create("Images/grossini_dance_atlas.png",
|
2013-07-12 14:30:26 +08:00
|
|
|
Rect(x,y,85,121));
|
2013-02-28 16:35:42 +08:00
|
|
|
addChild(sprite);
|
|
|
|
|
|
|
|
sprite->setPosition(p);
|
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
FiniteTimeAction *action = nullptr;
|
2013-02-28 16:35:42 +08:00
|
|
|
float rd = CCRANDOM_0_1();
|
|
|
|
|
|
|
|
if (rd < 0.20)
|
2013-06-20 14:17:10 +08:00
|
|
|
action = ScaleBy::create(3, 2);
|
2013-02-28 16:35:42 +08:00
|
|
|
else if (rd < 0.40)
|
2013-06-20 14:17:10 +08:00
|
|
|
action = RotateBy::create(3, 360);
|
2013-02-28 16:35:42 +08:00
|
|
|
else if (rd < 0.60)
|
2013-06-20 14:17:10 +08:00
|
|
|
action = Blink::create(1, 3);
|
2013-02-28 16:35:42 +08:00
|
|
|
else if (rd < 0.8 )
|
2013-06-20 14:17:10 +08:00
|
|
|
action = TintBy::create(2, 0, -255, -255);
|
2013-02-28 16:35:42 +08:00
|
|
|
else
|
2013-06-20 14:17:10 +08:00
|
|
|
action = FadeOut::create(2);
|
2013-02-28 16:35:42 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto action_back = action->reverse();
|
2014-07-10 00:45:27 +08:00
|
|
|
auto seq = Sequence::create(action, action_back, nullptr);
|
2013-02-28 16:35:42 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
sprite->runAction(RepeatForever::create(seq));
|
2013-02-28 16:35:42 +08:00
|
|
|
|
|
|
|
//return sprite;
|
2014-07-10 00:45:27 +08:00
|
|
|
return nullptr;
|
2013-02-28 16:35:42 +08:00
|
|
|
}
|
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
void SpriteRenderTextureBug::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
|
2013-02-28 16:35:42 +08:00
|
|
|
{
|
2013-09-03 18:22:03 +08:00
|
|
|
for (auto &touch: touches)
|
2013-02-28 16:35:42 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto location = touch->getLocation();
|
2013-02-28 16:35:42 +08:00
|
|
|
addNewSpriteWithCoords(location);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string SpriteRenderTextureBug::title() const
|
2013-02-28 16:35:42 +08:00
|
|
|
{
|
|
|
|
return "SpriteRenderTextureBug";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string SpriteRenderTextureBug::subtitle() const
|
2013-02-28 16:35:42 +08:00
|
|
|
{
|
|
|
|
return "Touch the screen. Sprite should appear on under the touch";
|
|
|
|
}
|
2016-07-21 10:34:04 +08:00
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Issue16113Test
|
|
|
|
//
|
|
|
|
Issue16113Test::Issue16113Test()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
// Save Image menu
|
|
|
|
MenuItemFont::setFontSize(16);
|
|
|
|
auto item1 = MenuItemFont::create("Save Image", [&](Ref* ref){
|
|
|
|
auto winSize = Director::getInstance()->getVisibleSize();
|
|
|
|
auto text = Label::createWithTTF("hello world", "fonts/Marker Felt.ttf", 40);
|
|
|
|
text->setTextColor(Color4B::RED);
|
|
|
|
auto target = RenderTexture::create(winSize.width, winSize.height, Texture2D::PixelFormat::RGBA8888);
|
|
|
|
target->beginWithClear(0,0,0,0);
|
|
|
|
text->setPosition(winSize.width / 2,winSize.height/2);
|
|
|
|
text->Node::visit();
|
|
|
|
target->end();
|
|
|
|
target->saveToFile("issue16113.png", Image::Format::PNG);
|
|
|
|
});
|
|
|
|
auto menu = Menu::create(item1, nullptr);
|
|
|
|
this->addChild(menu);
|
|
|
|
menu->setPosition(s.width/2, s.height/2);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Issue16113Test::title() const
|
|
|
|
{
|
|
|
|
return "Github Issue 16113";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Issue16113Test::subtitle() const
|
|
|
|
{
|
|
|
|
return "aaa.png file without white border on iOS";
|
|
|
|
}
|