Error: no instance of constructor "cocos2d::Vec2::Vec2 matches the argument list. Argument types are: (float, cocos2d::Size)"
Cocos2d-x v3-
MoseHasLikes 0Problem Description
I am a real beginner of cocos2d from Taiwan and just started learning 3 days ago. My OS is win 8.1 and my IDE is visual studio. In the tutorial about adding a menu font item, I tried to implement the same menu font step by step but failed.
This is my HelloWorldScene.cpp.
#include "HelloWorldScene.h" #include "ui/CocosGUI.h" #include "SimpleAudioEngine.h" USING_NS_CC; Scene* HelloWorld::createScene() { // 'scene' is an autorelease object auto scene = Scene::create(); // 'layer' is an autorelease object auto layer = HelloWorld::create(); // add layer as a child to scene scene->addChild(layer); // return the scene return scene; } // on "init" you need to initialize your instance bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !Layer::init() ) { return false; } Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); ///////////////////////////// // 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)); closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width/2 , origin.y + closeItem->getContentSize().height/2)); // create menu, it's an autorelease object auto menu = Menu::create(closeItem, NULL); menu->setPosition(Vec2::ZERO); this->addChild(menu, 1); ///////////////////////////// // 3. add your codes below... // add a label shows "Hello World" // create and initialize a label auto label = Label::createWithTTF("My First New Game!", "fonts/Marker Felt.ttf", 72); // position the label on the center of the screen label->setPosition(Vec2(origin.x + visibleSize.width/2, origin.y + visibleSize.height - label->getContentSize().height)); // add the label as a child to this layer this->addChild(label, 1); label->enableOutline(Color4B::BLUE, 1); // add "HelloWorld" splash screen" //auto sprite = Sprite::create("HelloWorld.png"); auto elfsprite = Sprite::create("ne.png"); elfsprite->setPosition(Vec2(visibleSize.width / 2 + origin.x + 100, visibleSize.height / 2 + origin.y)); this->addChild(elfsprite, 3); auto menu_item_1 = MenuItemFont::create("Play", CC_CALLBACK_1(HelloWorld::Play,this)); auto menu_item_2 = MenuItemFont::create("Highscores", CC_CALLBACK_1(HelloWorld::HighScores, this)); auto menu_item_3 = MenuItemFont::create("Settings", CC_CALLBACK_1(HelloWorld::Settings, this)); menu_item_1->setPosition(Vec2(visibleSize.width / 2, (visibleSize / 4) * 3)); menu_item_2->setPosition(Point(visibleSize.width / 2, (visibleSize / 4) * 2)); menu_item_3->setPosition(Point(visibleSize.width / 2, (visibleSize / 4) * 1)); auto *menu = Menu::create(menu_item_1, menu_item_2, menu_item_3, nullptr); return true; } void HelloWorld::Play(cocos2d::Ref *pSender) { CCLOG("Play"); } void HelloWorld::HighScores(cocos2d::Ref *pSender) { CCLOG("HighScores"); } void HelloWorld::Settings(cocos2d::Ref *pSender) { CCLOG("Settings"); } void HelloWorld::menuCloseCallback(Ref* pSender) { Director::getInstance()->end(); #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) exit(0); #endif }
And this is my HelloWorldScene.h
#ifndef __HELLOWORLD_SCENE_H__ #define __HELLOWORLD_SCENE_H__ #include "cocos2d.h" class HelloWorld : public cocos2d::Layer { public: // there's no 'id' in cpp, so we recommend returning the class instance pointer static cocos2d::Scene* createScene(); // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone virtual bool init(); // a selector callback void menuCloseCallback(cocos2d::Ref* pSender); // implement the "static create()" method manually CREATE_FUNC(HelloWorld); //adding function, try to move my sprite //bool onTouchBegan(cocos2d::Touch *touch, cocos2d::Event *event); //void onTouchMoved(cocos2d::Touch *touch, cocos2d::Event *event); //void onTouchEnded(cocos2d::Touch *touch, cocos2d::Event *event); void Play(Ref *pSender); void HighScores(Ref *pSender); void Settings(Ref *pSender); }; #endif // __HELLOWORLD_SCENE_H__
I received an error message about both Vec2 and Point Part.
Error: no instance of constructor "cocos2d::Vec2::Vec2 matches the argument list. Argument types are: (float, cocos2d::Size)"Well, could not fully understand what happened. Seems that I could not use Vec2 nor Point here. But you run it successfully. That is really strange. Did I miss-include any header or do anything wrong?Beg for apology because I just started learning. Maybe there will be fool questions. Thanks a lot!
-
Sonar Systems adminLikes 0
Check out this other post and let us know if this is similar to your issue
http://www.sonarlearning.co.uk/questions.php?question-topic=162#714
This reply has been verified.
-
MoseHasLikes 0
Problem solved!
Turns out that I forgot to finish my parameter “visibleSize.height” And that is why the error message kept telling me “Argument types are: (float, cocos2d::Size)"
Sorry that happened on me. No more stupid mistakes should be made.
Thank you very much!
This reply has been verified.
-
Sonar Systems adminLikes 0
Great to hear
Login to reply