Using cocos2d-x V3.17, I want to make my button move up when it’s clicked, in the following code is two separate button codes, I have asterisk-coated the line which I assume the action should occur to, but expectedly, the name of the button isn’t recognised in the section. How do I make it recognised within the curly braces?
void DEL1::DEL1HEL(cocos2d::Ref *pSender)
{
CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("Button clicked (2).mp3");
DEL1H = Sprite::create("HelpDClick.png");
this->addChild(DEL1H);
DEL1H->setPosition(Point(730, 1200));
DEL1H->setScale(1.5);
auto DL1HMM = MoveBy::create(1.4, Point(0, -740));
DEL1H->runAction(DL1HMM);
CCLOG("Help");
auto DEL1ExitHelpMenu1 = MenuItemImage::create("GOTIT.png", "GOTIT.png", CC_CALLBACK_1(DEL1::DEL1HELEXI, this));
DEL1ExitHelpMenu1->setPosition(Point(820, 1200));
DEL1ExitHelpMenu1->setScale(0.8);
auto DL1HEE = MoveBy::create(1.4, Point(0, -1060));
DEL1ExitHelpMenu1->runAction(DL1HEE);
auto *DEL1Hmenu = Menu::create(DEL1ExitHelpMenu1, NULL);
DEL1Hmenu->setPosition(Point(0, 0));
this->addChild(DEL1Hmenu);
}
void DEL1::DEL1HELEXI(cocos2d::Ref *pSender)
{
CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("Button clicked (7).mp3");
***auto DL1HUE = MoveBy::create(1.4, Point(0, 1060));***
***DEL1ExitHelpMenu1->runAction(DL1HUE);***
auto DL1HLL = MoveBy::create(1, Point(0, 1200));
DEL1H->runAction(DL1HLL);
CCLOG("Remove advice");
}```
Look at where those objects defined… you define them out of scope of where you try to act upon them.
I have attempted severed definitition combinations but this hasn’t worked, where should I define it? I am guessing within the init method, but the way I am doing it proves innefective
your header file, perhaps?
anon97208230:
DEL1::DEL1HELEXI
apologies for not specifying, this was already in the header
That’s not defining. Post the whole header please.
DEL1 is short for destruction level 1
#pragma once
#include "cocos2d.h"
class DEL1 : public cocos2d::Scene
{
public:
static cocos2d::Scene* createScene();
virtual bool init();
// a selector callback
void menuCloseCallback(cocos2d::Ref* pSender);
// implement the "static create()" method manually
CREATE_FUNC(DEL1);
cocos2d::Sprite *DEL1B;
cocos2d::Sprite *DEL1P;
cocos2d::Sprite *DEL1H;
void DEL1HELEXI(Ref *pSender);
void DEL1HEL(Ref *pSender);
void DEL1EXI(Ref *pSender);
void DEL1RES(Ref *pSender);
void DEL1PAU(Ref *pSender);
void DEL1PLA(Ref *pSender);
};
I suggest you name classes, methods, variables more clearly.
For me DEL
means delete.
Better name it DestructionLevel1
Or it’s hard for you type so much?
If someone else will help you with coding it will understand code more fast and easily.
Yeah, he PM’d me so I helped him out with a couple of problems. I suggested him to cover the basics of c++ before diving into cocos2d-x.
anon97208230:
auto DEL1ExitHelp
There are a lot of free books: http://iacs-courses.seas.harvard.edu/courses/cs207/resources/TIC2Vone.pdf
Not to mention videos all over the place.
I have a lot of c++ books. If you are in the U.S.A, I will ship you one.
in our PMing I thoroughly went over proof I have done so.