Home > other >  Why turn the lambda cannot use references to catch here? An error!
Why turn the lambda cannot use references to catch here? An error!

Time:09-18

In figure 3 values passed no problem, references will be an error, crooked?







 # include "HelloWorldScene. H" 
# include "SimpleAudioEngine. H"
# include "UI/CocosGUI. H"
USING_NS_CC;

Scene * HelloWorld: : createScene ()
{
Return the HelloWorld: : create ();
}

//Print useful error message home segfaulting when files are not there.
The static void problemLoading (const char * filename)
{
Printf (" Error while loading: % s \ n ", filename);
Printf (" Depending on how you compiled as you took have to add 'Resources/' in front of filenames in HelloWorldScene. CPP \ n ");
}

//on "init" you need to initialize your instance
Bool HelloWorld: : init ()
{
//////////////////////////////
//1. Super init first
if ( ! Scene: : init ())
{
return false;
}

Auto visibleSize=Director: : getInstance () - & gt; GetVisibleSize ();
Vec2 origin=Director: : getInstance () - & gt; GetVisibleOrigin ();
//add "HelloWorld" splash screen "
Sprite=Sprite: : create (" HelloWorld. PNG ");
If (Sprite==nullptr)
{
ProblemLoading (" 'the HelloWorld. PNG ");
}
The else
{
//the position the Sprite on the center of the screen
Sprite - & gt; SetPosition (Vec2 (visibleSize. Width/2 + origin. X, visibleSize. Height/2 + origin. Y));
//add the Sprite as a child to this layer
This - & gt; AddChild (Sprite, 0);
}
/////////////////////////////
//2. Add a menu item with "X" image, which is clicked to quit the program
//you may modify it.

//add a "close" icon to exit the progress. It 's an autorelease object
Auto closeItem=MenuItemImage: : create (
"CloseNormal. PNG,"
"CloseSelected. PNG,"
CC_CALLBACK_1 (HelloWorld: : menuCloseCallback, this, Sprite));

If (closeItem==nullptr | |
CloseItem - & gt; GetContentSize (). The width & lt;=0 | |
CloseItem - & gt; GetContentSize (). The height & lt;=0)
{
ProblemLoading (" 'CloseNormal. PNG' and 'CloseSelected. PNG ");
}
The else
{
Float x=origin. X + visibleSize. Width - closeItem - & gt; GetContentSize (). The width/2;
Float y=origin. Y + closeItem - & gt; GetContentSize (). The height/2;
CloseItem - & gt; SetPosition (Vec2 (x, y));
}

//create the menu, it 's an autorelease object
Auto menu=menu: : create (closeItem, NULL);
Menu - & gt; SetPosition (Vec2: : ZERO);
This - & gt; AddChild (menu, 1);

/////////////////////////////
//3. Add your codes below...

//add a label shows "Hello World"
//create and initialize a label

Auto label=label: : createWithTTF (" Hello World ", "fonts/Marker Felt. The vera.ttf", 24).
If (label==nullptr)
{
ProblemLoading (" 'fonts/Marker Felt. The vera.ttf' ");
}
The else
{
//the position the label on the center of the screen
The label - & gt; SetPosition (Vec2 (origin. X + visibleSize. Width/2,
Origin. Y + visibleSize. Height - label - & gt; GetContentSize (), height));
This - & gt; AddChild (label, 1);
}
Auto pBut1=UI: : Button: : create (" CloseNormal. PNG ", "CloseSelected. PNG");
PBut1 - & gt; SetAnchorPoint (Vec2: : ZERO);
PBut1 - & gt; AddTouchEventListener (CC_CALLBACK_2 (HelloWorld: : ContralMoveTest, this, Sprite));
This - & gt; AddChild (pBut1);

Return true;
}
Void the HelloWorld: : ContralMoveTest (Ref * sender, UI: : Widget: : TouchEventType controlEvent, Sprite * pSprite) {
if (! IsScheduled (" HelloWorld: : ContralMoveTest ")) {
This - & gt; The schedule ([=] {float (dt)
PSprite - & gt; SetPositionX (pSprite - & gt; GetPositionX () + 1.0 f);
}, 0, 1, 0, "HelloWorld: : ContralMoveTest");
}
//leave end state timer
If (controlEvent==UI: : Widget: : TouchEventType: : ENDED) {
This - & gt; Unschedule (" HelloWorld: : ContralMoveTest ");
}
}

Void the HelloWorld: : menuCloseCallback (Ref * pSender, Sprite * pSprite)
{

}

Void the HelloWorld: : SchedulerTest (float dt, Sprite * pSprite)
{
PSprite - & gt; SetVisible (! PSprite - & gt; IsVisible ());
}

CodePudding user response:

=is a value type, & amp; Is a reference type
  • Related