Hi, I got a error when i add ccTouchesEnded to HelloWorldScene(the demo). Before this operate, that can run without any problem. Anyone can help me??? Thanks!~
Can you provide some source to check the problem…May be cocos2d namespace has not been declared so try with cocos2d::CCSet and cocos2d::CCEvent…
Viraj Dasondi wrote:
Can you provide some source to check the problem…May be cocos2d namespace has not been declared so try with cocos2d::CCSet and cocos2d::CCEvent…
just add a function declared and empty realize to cpp like this:
#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__
#include "cocos2d.h"
class HelloWorld : public cocos2d::CCLayer
{
public:
...
void ccTouchesEnded(CCSet * touches,CCEvent * event);
// a selector callback
void menuCloseCallback(CCObject* pSender);
// implement the "static node()" method manually
CREATE_FUNC(HelloWorld);
};
#endif // __HELLOWORLD_SCENE_H__
#include "HelloWorldScene.h"
#include "SimpleAudioEngine.h"
using namespace cocos2d;
using namespace CocosDenshion;
...
void HelloWorld::ccTouchesEnded(CCSet * touches,CCEvent * event) {
}
void HelloWorld::menuCloseCallback(CCObject* pSender)
{
CCDirector::sharedDirector()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
#endif
}
In your Header file, you should declare ccTouchesEnded
as virtual void
Lance Gray wrote:
In your Header file, you should declare
ccTouchesEnded
asvirtual void
doesnt’ work…
In .h file in ccTouchesEnded replace it with void ccTouchesEnded(cocos2d::CCSet * touches,cocos2d::CCEvent * event);
You also need to implement ccTouchesBegin
// HEADER
virtual bool ccTouchesBegin( cocos2d::CCSet * touches, cocos2d::CCEvent * event );
virtual void ccTouchesEnded( cocos2d::CCSet * touches, cocos2d::CCEvent * event);
// CPP
bool ccTouchesBegin( cocos2d::CCSet * touches, cocos2d::CCEvent * event ) {
return true;
}
void ccTouchesEnded( cocos2d::CCSet * touches, cocos2d::CCEvent * event) {
// do something
}
Viraj Dasondi wrote:
In .h file in ccTouchesEnded replace it with void ccTouchesEnded(cocos2d::CCSet * touches,cocos2d::CCEvent * event);
It’s work Thandk you so much~~
But why CCNode and CCObject doesn’t need this, them are in the same path?
As per my understanding CCNode and CCObject are part of base nodes as described hete:
http://www.cocos2d-x.org/embedded/cocos2d-x/d9/d1f/groupbasenodes.html
I have not checked it but if you want to make sure try with other base nodes with not preceding cocos2d::….
CCSprite* img = CCSprite::create(“r1.png”);
CCMenuItemImage item1 = CCMenuItemImage::create );
CCMenumenu = CCMenu::create(item1, NULL);
menu->setPosition(CCPointZero);
my CCMenuItemImage doesn’t work
my version is cocos2dx- 2.0.4
Try with this
cocos2d::CCMenuItemImage *playGameButton = cocos2d::CCMenuItemImage::itemWithNormalImage(“PlayGameButtonNormal.png”,
“PlayGameButtonSelected.png”,
this,
menu_selector(MainMenuLayer::displaySceneSelection) );
cocos2d::CCMenu mainMenu = cocos2d::CCMenu::menuWithItems(playGameButton,NULL);
mainMenu->setPosition(ccp(screenSize.width*2,screenSize.height/2)); //can be as your requirement.
Thnx…… it works. But I try this in a different way.
cocos2d::CCMenuItemImage playGameButton = cocos2d::CCMenuItemImage::create );
CCMenumenu = CCMenu::create(playGameButton, NULL);
menu->setPosition(ccp(1000,200));
addChild(menu, 1);
Yes…. you are right…. I used the image by the reference.
The right solution is:
using namespace cocos2d;
on your HelloWorldScene.h file
Is it possible to flip a sprite with child?
I try this….
body->runAction(CCFlipX::create(true));
body flips but its child head, legs doesn’t flip…… is There any solution?
Mahmudul Shuvo wrote:
Is it possible to flip a sprite with child?
>
I try this….
>
body->runAction(CCFlipX::create(true));
>
body flips but its child head, legs doesn’t flip…… is There any solution?
Plz open a new thread for this issue.
here is what i do
body~~>runAction),
body~~>setScaleX( -.5f),
CCMoveTo::create(2,ccp(2000,800)),
NULL) ) // Here I got the error…
) );