Cocos2d-x3.0 RenderTexture (3)

Source: Internet
Author: User


. H

#include "cocos2d.h"#include "cocos-ext.h"#include "ui/CocosGUI.h"#include "cocostudio/CocoStudio.h"USING_NS_CC;USING_NS_CC_EXT;using namespace ui;

private:    cocos2d::SpriteBatchNode *mgr;;        cocos2d::Sprite *sp1;    cocos2d::Sprite *sp2;    cocos2d::Sprite *sp3;    cocos2d::Sprite *sp4;    cocos2d::Sprite *sp5;    cocos2d::Sprite *sp6;    cocos2d::Sprite *sp7;    cocos2d::Sprite *sp8;    cocos2d::Sprite *sp9;

. Cpp

Auto listener = EventListenerTouchAllAtOnce: create (); auto label = Label: createWithTTF ("vertexZ = 50", "Marker Felt. ttf ", 64); label-> setPosition (Point (size. width/2, size. height * 0.25f); this-> addChild (label); auto label2 = Label: createWithTTF ("vertexZ = 0", "Marker Felt. ttf ", 64); label2-> setPosition (Point (size. width/2, size. height * 0.5f); this-> addChild (label2); auto label3 = Label: createWithTTF ("vertexZ =-50", "Marker Felt. ttf ", 64); label3-> setPosition (Point (size. width/2, size. height * 0.75f); this-> addChild (label3); label-> setPositionZ (50); label2-> setPositionZ (0); label3-> setPositionZ (-50 ); spriteFrameCache: getInstance ()-> addSpriteFramesWithFile ("circle. plist "); mgr = SpriteBatchNode: create (" circle.png ", 9); this-> addChild (mgr); auto sp1 = Sprite: createWithSpriteFrameName (" circle.png "); sp2 = Sprite: Upper ("circle.png"); sp3 = Sprite: Upper ("circle.png"); sp4 = Sprite: createWithSpriteFrameName ("circle.png"); sp5 = Sprite:: crop ("circle.png"); sp6 = Sprite: createWithSpriteFrameName ("circle.png"); sp7 = Sprite: createWithSpriteFrameName ("circle.png"); sp8 = Sprite :: createWithSpriteFrameName ("circle.png"); sp9 = Sprite: createWithSpriteFrameName ("circle.png"); 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); 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 ); sp9-> setScale (2); sp9-> setColor (Color3B: YELLOW ); // [=] You can drop the external variable listener-> onTouchesBegan = [=] (const std: vector
 
  
& Touches, cocos2d: Event * unused_event) {for (auto & item: touches) {auto touch = static_cast
  
   
(Item); auto location = touch-> getLocation (); 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) ;}}; listener-> onTouchesMoved = [=] (const std: vector
   
    
& Touches, Event * unused_event) {for (auto & item: touches) {auto touch = static_cast
    
     
(Item); auto location = touch-> getLocation (); 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) ;}}; listener-> onTouchesEnded = [=] (const std: vector
     
      
& Touches, cocos2d: Event * unused_event) {auto texture = RenderTexture: create (512,512); if (NULL = texture) {return ;} texture-> setAnchorPoint (Point (0, 0); texture-> setKeepMatrix (true); texture-> begin (); this-> visit (); texture-> end (); auto sprite = Sprite: createWithTexture (texture-> getSprite ()-> getTexture (); sprite-> setPosition (Point (256,256 )); sprite-> setOpacity (182); sprite-> setFlippedY (1); this-> addChild (sprite, 999999); sprite-> setColor (Color3B: GREEN ); sprite-> runAction (Sequence: create (FadeTo: create (2, 0), Hide: create (), NULL ));}; _ eventDispatcher-> addEventListenerWithSceneGraphPriority (listener, this );
     
    
   
  
 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.