search

Home  >  Q&A  >  body text

objective-c - 用Box2D创建世界时,出现报错怎么办?

目前,我用的是cocos2d Box2D的模板做项目,但是,当我创建世界(world)的时候,会采用:

world =newb2World(gravity,doSleep);

然后就会报错:No matching constructor for initialization of 'b2World'
文件格式为.mm,这种报错是与相关的数据库有关吗?如果我用xCode 4,怎么才能对相关的数据库进行检测呢?

原问题:Xcode: Cocos2d: Can't create world with Box2D

阿神阿神2763 days ago519

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-04-21 11:21:12

    Answer: LearnCocos2D
    You should be using Box2D v2.2 or newer version, among which, b2World constructor
    There is only one parameter related to gravity, instead of two parameters as before. Therefore, you must set the doSleep related variables separately:

    world = new b2World(gravity);
    world->SetAllowSleeping(doSleep);
    

    Of course, this is not the only way. In Kobold2D, there is a sample item for Box2D 2.2.1, so that even if you don't use Kobold2D, you can get updates on the basic data of Box2D. This method can be used especially when you need to set the GLESDebugDraw class, or when you need to use different shapes of bodies to set the bounding box of the screen.

    reply
    0
  • Cancelreply