b2Fixture* b2Body::CreateFixture(const b2Shape* shape, float32 density) { b2FixtureDef def; def.shape = shape; def.density = density; return CreateFixture(&def); }
STARTDECL(ph_createcircle) (Value &position, Value &radius, Value &offset, Value &other_id) { auto &body = GetBody(other_id, position); b2CircleShape shape; auto off = OptionalOffset(offset); shape.m_p.Set(off.x, off.y); shape.m_radius = radius.fval; return CreateFixture(body, shape); }
STARTDECL(ph_createbox) (Value &position, Value &size, Value &offset, Value &rot, Value &other_id) { auto &body = GetBody(other_id, position); auto sz = ValueDecTo<float2>(size); auto r = rot.True() ? rot.fval : 0; b2PolygonShape shape; shape.SetAsBox(sz.x(), sz.y(), OptionalOffset(offset), r * RAD); return CreateFixture(body, shape); }
void CollisionEdge2D::RecreateFixture() { ReleaseFixture(); Vector2 worldScale(cachedWorldScale_.x_, cachedWorldScale_.y_); edgeShape_.Set(ToB2Vec2(vertex1_ * worldScale), ToB2Vec2(vertex2_ * worldScale)); CreateFixture(); }
//void demography :: add() //{ //// if(false) // { // b2CircleShape Shape; // Shape.m_radius = radius; // auto position = // Vec2(wsize.x*getrangerand(.1,.9), // wsize.y*getrangerand(.1,.9)); // // auto Body = makebody(World,&Shape,conv(position),b2_dynamicBody,0,0.01,0,.9); // // Body->SetLinearVelocity( // b2Vec2(5*getrangerand(-1,1), // 5*getrangerand(-1,1))); // cellbodies.push_back(Body); // pos.push_back(b2Vec2()); // //// cells.push_back(CircleShape(0,4)); //// cells.back().setFillColor(Color(255,80,160)); //// cells.back().setRadius(SCALE*radius*GR_PH_COEFF); //// cells.back().setOrigin(cells.back().getRadius(), cells.back().getRadius()); // vbunk.add(); // // cells.back().setPosition(conv(position)); // } // if(false) // { // pos.push_back(b2Vec2()); // // pos_sf.push_back(Vec2()); // // b2BodyDef BodyDef; // BodyDef.position = b2Vec2 // ((getrand(0.3)+0.2)*wsize.x/SCALE, // (getrand(0.3)+0.2)*wsize.y/SCALE); // BodyDef.type = b2_dynamicBody; // // BodyDef.linearDamping=dampen; // b2Body* Body = World.CreateBody(&BodyDef); // // b2CircleShape Shape; // Shape.m_radius = radius; // //Body->setv // b2FixtureDef FixtureDef; // FixtureDef.density = 4.f; // FixtureDef.restitution = .9f; // FixtureDef.shape = &Shape; // Body->CreateFixture(&FixtureDef); // Body->SetLinearVelocity(b2Vec2 // (5*getrangerand(-1,1), // 5*getrangerand(-1,1))); // cellbodies.push_back(Body); // // cells.push_back(CircleShape(SCALE,4)); // cells.back().setFillColor(Color(255,80,160)); // cells.back().setRadius(SCALE*radius); // cells.back().setOrigin(cells.back().getRadius(), cells.back().getRadius()); // } // lb2(cells.size()); //} void demography :: add_agent(Vec2 position, int is_enemy) { b2CircleShape shape,shape_s,shape_s_e; shape .m_radius = radius; shape_s .m_radius = sensor_radius; shape_s_e .m_radius = sensor_radius_e; auto Body = make_body(World,conv(position),b2_dynamicBody,dampen); b2FixtureDef fixdef, fixdef_s, fixdef_s_e; if(use_masks) { fixdef = make_fixture(static_cast<b2Shape*>(&shape), false, &filters[is_enemy][0],.1,4); //fixdef_s = make_fixture(static_cast<b2Shape*>(&shape_s), true, &filters[is_enemy][1] ); //fixdef_s_e = make_fixture(static_cast<b2Shape*>(&shape_s_e),true, &filters[is_enemy][2]); } else { fixdef = make_fixture (static_cast<b2Shape*>(&shape),false); fixdef.density=4; //fixdef_s = make_fixture(static_cast<b2Shape*>(&shape_s),true); //fixdef_s_e = make_fixture(static_cast<b2Shape*>(&shape_s_e),true); } Body->CreateFixture(&fixdef); //Body->CreateFixture(&fixdef_s); //Body->CreateFixture(&fixdef_s_e); if(!is_enemy)cellbodies.insert(Body); //if(draw_sensors) //{ // sensors[Body]=(CircleShape(SCALE*shape_s.m_radius,16)); // sensors[Body].setFillColor(Color(0,0,0,0)); // sensors[Body].setOutlineColor(Color(64,64,64)); // //sensors[Body].setOutlineColor(Color(0,64,0)); // sensors[Body].setOutlineThickness(0.5); // sensors[Body].setOrigin(sensors[Body].getRadius(), sensors[Body].getRadius()); // sensors2[Body]=(CircleShape(SCALE*shape_s_e.m_radius,16)); // sensors2[Body].setFillColor(Color(0,0,0,0)); // //sensors2[Body].setOutlineColor(Color(96,0,0)); // sensors2[Body].setOutlineColor(Color(64,64,64)); // sensors2[Body].setOutlineThickness(0.5); // sensors2[Body].setOrigin(sensors2[Body].getRadius(), sensors2[Body].getRadius()); //} #define USE_SHAPES #ifdef USE_SHAPES cells[Body]=CircleShape(SCALE,getrangerand(3,6)); cells[Body].setFillColor(rgb_from_hue(getrand(1))); cells[Body].setRadius(SCALE*radius); cells[Body].setOrigin(cells[Body].getRadius(), cells[Body].getRadius()); #else vbunk.add(); #endif nears[Body]=unordered_set<b2Body*>(); pos.push_back(b2Vec2()); }
void CollisionCircle2D::RecreateFixture() { ReleaseFixture(); // Only use scale in x axis for circle float worldScale = cachedWorldScale_.x_; circleShape_.m_radius = radius_ * worldScale; circleShape_.m_p = ToB2Vec2(center_ * worldScale); CreateFixture(); }
void CollisionShape2D::OnSetEnabled() { if (IsEnabledEffective()) { CreateFixture(); if (rigidBody_) rigidBody_->AddCollisionShape2D(this); } else { if (rigidBody_) rigidBody_->RemoveCollisionShape2D(this); ReleaseFixture(); } }
void CollisionShape2D::OnNodeSet(Node* node) { Component::OnNodeSet(node); if (node) { node->AddListener(this); rigidBody_ = node->GetComponent<RigidBody2D>(); if (rigidBody_) { CreateFixture(); rigidBody_->AddCollisionShape2D(this); } } }
STARTDECL(ph_createpolygon) (Value &position, Value &vertices, Value &other_id) { auto &body = GetBody(other_id, position); b2PolygonShape shape; auto verts = new b2Vec2[vertices.vval->len]; for (int i = 0; i < vertices.vval->len; i++) { auto vert = ValueTo<float2>(vertices.vval->at(i)); verts[i] = *(b2Vec2 *)| } shape.Set(verts, vertices.vval->len); delete[] verts; vertices.DECRT(); return CreateFixture(body, shape); }
Pointer<GroundPuppeteer> Ground::CreatePuppeteer(PhysicsEngine* engine) { b2BodyDef def; def.type = b2BodyType::b2_staticBody; float ptmRatio = engine->getPtmRatio(); def.position.Set(getPositionX() / ptmRatio, getPositionY() / ptmRatio); auto res = GroundPuppeteer::create(this, def, engine); auto body = res->getBody(); b2PolygonShape rect; rect.SetAsBox(this->getContentSize().width / (2.0 * ptmRatio), this->getContentSize().height / (2.0 * ptmRatio)); b2FixtureDef fdef; fdef.shape = ▭ body->CreateFixture(&fdef); return Pointer<GroundPuppeteer>(res); }
void CollisionShape2D::OnNodeSet(Node* node) { Component::OnNodeSet(node); if (node) { node->AddListener(this); rigidBody_ = node->GetComponent<RigidBody2D>(); if (rigidBody_) { CreateFixture(); rigidBody_->AddCollisionShape2D(this); } else LOGERROR("No right body component in node, can not create collision shape"); } }
void CollisionBox2D::RecreateFixture() { ReleaseFixture(); float worlsScaleX = cachedWorldScale_.x_; float worldScaleY = cachedWorldScale_.y_; float halfWidth = size_.x_ * 0.5f * worlsScaleX; float halfHeight = size_.y_ * 0.5f * worldScaleY; Vector2 scaledCenter = center_ * Vector2(worlsScaleX, worldScaleY); if (scaledCenter == Vector2::ZERO && angle_ == 0.0f) boxShape_.SetAsBox(halfWidth, halfHeight); else boxShape_.SetAsBox(halfWidth, halfHeight, ToB2Vec2(scaledCenter), angle_ * M_DEGTORAD); CreateFixture(); }
void Pipe2::MakePipeBody(cocos2d::Layer *layer, b2World *world, cocos2d::Rect rect){ auto Pipe = Sprite::create("pipe.png", rect); Pipe->setPosition(rect.getMidX(),rect.getMidY()); layer->addChild(Pipe); //Pipe->setScale(0.5); b2BodyDef PipeBodyDef; PipeBodyDef.type = b2_kinematicBody; //gravitity is not for pipes PipeBodyDef.position.Set(rect.getMidX()/SCALE_RATIO, rect.getMidY()/SCALE_RATIO); PipeBodyDef.userData = Pipe; auto PipeBody = world->CreateBody(&PipeBodyDef); float a = Pipe->getContentSize().width;//*0.7; float b = Pipe->getContentSize().height;//*0.9; float sizeX = a/(2*SCALE_RATIO); float sizeY = b/(2*SCALE_RATIO); b2PolygonShape polygon; polygon.SetAsBox(sizeX, sizeY); //a 4x2 rectangle !!может округлять в большую сторону; ORIGINY слишком большой OrigiinX маленький( //polygon.SetAsBox(1, sizeY); b2FixtureDef PipeShapeDef; PipeShapeDef.shape = &polygon; PipeShapeDef.density = 0; PipeShapeDef.friction = 0; PipeShapeDef.restitution = 0; PipeBody->CreateFixture(&PipeShapeDef); PipeBody->SetLinearVelocity( b2Vec2(-3,0)); }
b2Body* TiledBodyCreator::initCollisionMap(TMXTiledMap* map, b2World* world, std::string groupname) { auto collisionGroup = map->getObjectGroup(groupname); cocos2d::ValueVector collisionObjects = collisionGroup->getObjects(); b2BodyDef bd; bd.position.Set(map->getPositionX() / 32, map->getPositionY() / 32); auto collisionBody = world->CreateBody(&bd); for(cocos2d::Value objectValue : collisionObjects) { auto fixtureShape = createFixture(objectValue.asValueMap()); if(fixtureShape != NULL) { collisionBody->CreateFixture(&fixtureShape->fixture); } } return collisionBody; }
void CollisionChain2D::RecreateFixture() { ReleaseFixture(); PODVector<b2Vec2> b2Vertices; unsigned count = vertices_.Size(); b2Vertices.Resize(count); Vector2 worldScale(cachedWorldScale_.x_, cachedWorldScale_.y_); for (unsigned i = 0; i < count; ++i) b2Vertices[i] = ToB2Vec2(vertices_[i] * worldScale); if (loop_) chainShape_.CreateLoop(&b2Vertices[0], count); else chainShape_.CreateChain(&b2Vertices[0], count); CreateFixture(); }
void CollisionPolygon2D::RecreateFixture() { ReleaseFixture(); if (vertices_.Size() < 3) return; PODVector<b2Vec2> b2Vertices; unsigned count = vertices_.Size(); b2Vertices.Resize(count); Vector2 worldScale(cachedWorldScale_.x_, cachedWorldScale_.y_); for (unsigned i = 0; i < count; ++i) b2Vertices[i] = ToB2Vec2(vertices_[i] * worldScale); polygonShape_.Set(&b2Vertices[0], count); CreateFixture(); }
void CollisionChain2D::RecreateFixture() { ReleaseFixture(); std::vector<b2Vec2> b2Vertices; size_t count = vertices_.size(); b2Vertices.resize(count); Vector2 worldScale(cachedWorldScale_.x_, cachedWorldScale_.y_); for (size_t i = 0; i < count; ++i) b2Vertices[i] = ToB2Vec2(vertices_[i] * worldScale); chainShape_.Clear(); if (loop_) chainShape_.CreateLoop(&b2Vertices[0], count); else chainShape_.CreateChain(&b2Vertices[0], count); CreateFixture(); }
avalon::io::TiledMapLoader::Callback shapeLoader(int filterCategory, bool isSensor) { return [filterCategory, isSensor](const avalon::io::TiledMapLoader::Configuration& config) { const float x = boost::any_cast<float>(config.settings.at("x")); const float y = boost::any_cast<float>(config.settings.at("y")); const float width = boost::any_cast<float>(config.settings.at("width")); const float height = boost::any_cast<float>(config.settings.at("height")); const float pixelsInMeter = config.box2dContainer->pixelsInMeter; const auto pos = config.box2dContainer->convertToBox2d({x, y}); auto fixtureDef = config.box2dContainer->defaultFixtureDef; fixtureDef.isSensor = isSensor; fixtureDef.filter.categoryBits = filterCategory; std::string bodytype = "static"; if (config.settings.count("friction")) fixtureDef.friction = boost::any_cast<float>(config.settings.at("friction")); if (config.settings.count("density")) fixtureDef.density = boost::any_cast<float>(config.settings.at("density")); if (config.settings.count("restitution")) fixtureDef.restitution = boost::any_cast<float>(config.settings.at("restitution")); if (config.settings.count("bodytype")) bodytype = boost::any_cast<std::string>(config.settings.at("bodytype")); std::shared_ptr<b2Shape> shape; if (config.settings.count("polylinePoints")) { auto points = boost::any_cast<std::list<cocos2d::Point>>(config.settings.at("polylinePoints")); shape = initShapeFromPoints(points, pixelsInMeter); } else if (config.settings.count("points") > 0) { auto points = boost::any_cast<std::list<cocos2d::Point>>(config.settings.at("points")); shape = initShapeFromPoints(points, pixelsInMeter, true); } else { shape = initRectangleShape(width, height, pixelsInMeter); } fixtureDef.shape = shape.get(); b2BodyDef bodyDef; bodyDef.type = getBodyTypeFromString(bodytype); bodyDef.position.Set(pos.x, pos.y); auto body = config.box2dContainer->getWorld().CreateBody(&bodyDef); body->CreateFixture(&fixtureDef); }; }
void BaseScene::addEdge(Vec2 startpoint, Vec2 endpoint){ startpoint = startpoint / RTM_RATIO; endpoint = endpoint / RTM_RATIO; Vec2 middlepoint = (startpoint + endpoint) / 2; b2BodyDef bodydef; bodydef.position.Set(middlepoint.x, middlepoint.y); auto ground = world->CreateBody(&bodydef); b2EdgeShape shape; shape.Set(b2Vec2(startpoint.x - middlepoint.x, startpoint.y - middlepoint.y), b2Vec2(endpoint.x - middlepoint.x, endpoint.y - middlepoint.y)); b2FixtureDef fixtureDef; fixtureDef.shape = &shape; b2Filter filter; filter.categoryBits = 0x0001; filter.maskBits = 0xffff; fixtureDef.filter = filter; ground->CreateFixture(&fixtureDef); MyUserData* mytype = new MyUserData(); mytype->bd_type = bd_ground; ground->SetUserData(mytype); }
App::App() : world(b2Vec2(0, -9.8)), playerBodiesPoints(playerBodiesCount), playerBodies(playerBodiesCount), playerBodiesShapes(playerBodiesCount), playerEyesBodiesPoints(playerEyesCount), playerEyesBodies(playerEyesCount), playerEyesBodiesShapes(playerEyesCount), borderShapes(4), borderBodies(4) { world.SetDebugDraw(new graphics::DebugDraw); for (auto i = 0; i < 4; ++i) { const auto shape = new b2PolygonShape; shape->SetAsBox(100, 3); b2BodyDef bdef; bdef.awake = false; bdef.allowSleep = true; bdef.active = true; bdef.type = b2_staticBody; const auto body = world.CreateBody(&bdef); b2FixtureDef fdef; fdef.shape = shape; fdef.friction = borderFriction; fdef.restitution = borderRestitution; fdef.filter.categoryBits = borderCategory; const auto fixt = body->CreateFixture(&fdef); borderShapes[i].reset(shape); borderBodies[i] = body; } for (auto i = 0; i < playerBodiesCount; ++i) { const auto shape = new b2PolygonShape; shape->SetAsBox(playerBodySize, playerBodySize); b2BodyDef bdef; bdef.position.x = 0 + rand() % 50; bdef.position.y = 15 + rand() % 30; bdef.type = b2_dynamicBody; const auto body = world.CreateBody(&bdef); b2FixtureDef fdef; fdef.shape = shape; fdef.density = playerBodyDencity; fdef.friction = playerBodyFriction; fdef.restitution = playerBodyRestitution; fdef.filter.categoryBits = playerBodyCategory; const auto fixt = body->CreateFixture(&fdef); playerBodiesShapes[i].reset(shape); playerBodies[i] = body; playerBodiesPoints[i] = bdef.position; playerBodiesFallen[body] = false; } for (auto i = 0; i < playerEyesCount; ++i) { const auto shape = new b2CircleShape; shape->m_radius = playerEyeSize; b2BodyDef bdef; bdef.position.x = 0 + rand() % 50; bdef.position.y = 15 + rand() % 30; bdef.type = b2_dynamicBody; const auto body = world.CreateBody(&bdef); b2FixtureDef fdef; fdef.shape = shape; fdef.density = playerEyeDencity; fdef.friction = playerEyeFriction; fdef.restitution = playerEyeRestitution; fdef.filter.categoryBits = playerEyeCategory; const auto fixt = body->CreateFixture(&fdef); playerEyesBodiesShapes[i].reset(shape); playerEyesBodies[i] = body; playerEyesBodiesPoints[i] = bdef.position; } { const auto shape = new b2PolygonShape; shape->SetAsBox(2, 13); b2BodyDef bdef; bdef.awake = false; bdef.allowSleep = true; bdef.active = true; bdef.type = b2_staticBody; const auto body = world.CreateBody(&bdef); b2FixtureDef fdef; fdef.shape = shape; fdef.friction = borderFriction; fdef.restitution = borderRestitution; fdef.filter.categoryBits = borderCategory; const auto fixt = body->CreateFixture(&fdef); topObstacleShape.reset(shape); topObstacle = body; } { const auto shape = new b2PolygonShape; shape->SetAsBox(2, 5); b2BodyDef bdef; bdef.awake = false; bdef.allowSleep = true; bdef.active = true; bdef.type = b2_staticBody; const auto body = world.CreateBody(&bdef); b2FixtureDef fdef; fdef.shape = shape; fdef.friction = borderFriction; fdef.restitution = borderRestitution; fdef.filter.categoryBits = borderCategory; const auto fixt = body->CreateFixture(&fdef); bottomObstacleShape.reset(shape); bottomObstacle = body; } { const auto shape = new b2PolygonShape; shape->SetAsBox(2, 7); b2BodyDef bdef; bdef.awake = false; bdef.allowSleep = true; bdef.active = true; bdef.type = b2_staticBody; const auto body = world.CreateBody(&bdef); b2FixtureDef fdef; fdef.shape = shape; fdef.friction = borderFriction; fdef.restitution = borderRestitution; fdef.filter.categoryBits = borderCategory; const auto fixt = body->CreateFixture(&fdef); bottomHighObstacleShape.reset(shape); bottomHighObstacle = body; } { const auto shape = new b2PolygonShape; shape->SetAsBox(12.5, 2); b2BodyDef bdef; bdef.awake = false; bdef.allowSleep = true; bdef.active = true; bdef.type = b2_staticBody; bdef.position.x = -100.0f; const auto body = world.CreateBody(&bdef); b2FixtureDef fdef; fdef.shape = shape; fdef.friction = borderFriction; fdef.restitution = borderRestitution; fdef.filter.categoryBits = holeCategory; const auto fixt = body->CreateFixture(&fdef); holeTopShape.reset(shape); holeTopBody = body; } { const auto shape = new b2PolygonShape; shape->SetAsBox(12.5, 2); b2BodyDef bdef; bdef.awake = false; bdef.allowSleep = true; bdef.active = true; bdef.type = b2_staticBody; bdef.position.x = -100.0f; const auto body = world.CreateBody(&bdef); b2FixtureDef fdef; fdef.shape = shape; fdef.friction = borderFriction; fdef.restitution = borderRestitution; fdef.filter.categoryBits = holeCategory; const auto fixt = body->CreateFixture(&fdef); holeBottomShape.reset(shape); holeBottomBody = body; } ComputePoints(); RespawnBorders(true); }
basic_spaceship::basic_spaceship(phys_agent_specification const& spec, phys_system* system): simple_rigid_body(spec, system), m_t_cfg(new thruster_config< WorldDimensionality::dim2D >(thruster_presets::square_complete())), m_t_system(m_t_cfg) { m_half_width = spec.spec_acc["size"].as< double >() * 0.5; m_mass = spec.spec_acc["mass"].as< double >(); m_rotational_inertia = spec.spec_acc["rotational_inertia"].as< double >(); m_thruster_strength = spec.spec_acc["thruster_strength"].as< double >(); m_sensor_range = spec.spec_acc["sensor_range"].as< double >(); auto world = system->get_world(); b2BodyDef bd; bd.type = b2_dynamicBody; bd.position.Set(0.0f, 0.0f); bd.angle = 0.0f; auto body = world->CreateBody(&bd); b2PolygonShape shape; shape.SetAsBox(m_half_width, m_half_width); b2FixtureDef fd; fd.shape = &shape; fd.density = 1.0f; body->CreateFixture(&fd); // Override mass and rotational inertia // TODO: should be optional parameters, and if unspecified, left as auto b2d defaults b2MassData md; md.center = b2Vec2(0, 0); md.mass = m_mass; md.I = m_rotational_inertia; body->SetMassData(&md); set_body(body); /* phys_sensor_defn sdef(SensorType::Fan); sdef.body = body; sdef.pos = b2Vec2(0, 0); sdef.orientation = 0; sdef.range = m_sensor_range; sdef.type_specific = fan_sensor_data{ b2_pi / 3 }; m_front_sensor = create_sensor(sdef); sdef.orientation = b2_pi; m_rear_sensor = create_sensor(sdef); sdef.orientation = b2_pi / 2; m_left_sensor = create_sensor(sdef); sdef.orientation = -b2_pi / 2; m_right_sensor = create_sensor(sdef); */ phys_sensor_defn sdef(SensorType::Directional); sdef.body = body; sdef.pos = b2Vec2(0, 0); sdef.orientation = 0; sdef.range = m_sensor_range; sdef.type_specific = directional_sensor_data{}; m_front_sensor = create_sensor(sdef); sdef.orientation = b2_pi; m_rear_sensor = create_sensor(sdef); sdef.orientation = b2_pi / 2; m_left_sensor = create_sensor(sdef); sdef.orientation = -b2_pi / 2; m_right_sensor = create_sensor(sdef); m_collisions = 0; m_damage = 0.0; }
/////////////////////////BLOB LAYER bool BlobLayer::init() { if (!Layer::init()) return false; Entity::Game = this; setContentSize(Size(DESIGN_X, DESIGN_Y)); b2Vec2 gravity; gravity.Set(0.0f, -10.0f); world = new b2World(gravity); world->SetContinuousPhysics(true); world->SetContactListener(this); // Create edges around the entire screen // Define the ground body. b2BodyDef groundBodyDef; groundBodyDef.position.Set(0, 0); // bottom-left corner // Call the body factory which allocates memory for the ground body // from a pool and creates the ground box shape (also from a pool). // The body is also added to the world. auto _groundBody = world->CreateBody(&groundBodyDef); // Define the ground box shape. b2EdgeShape groundBox; // bottom groundBox.Set(b2Vec2(0, 0), b2Vec2(DESIGN_X / PTM_RATIO, 0)); _groundBody->CreateFixture(&groundBox, 0); // top //groundBox.Set(b2Vec2(0, DESIGN_Y / PTM_RATIO), b2Vec2(DESIGN_X / PTM_RATIO, DESIGN_Y / PTM_RATIO)); //_groundBody->CreateFixture(&groundBox, 0); // left groundBox.Set(b2Vec2(0, DESIGN_Y * 1.1f / PTM_RATIO), b2Vec2(0, 0)); _groundBody->CreateFixture(&groundBox, 0); // right groundBox.Set(b2Vec2(DESIGN_X / PTM_RATIO, 0), b2Vec2(DESIGN_X / PTM_RATIO, DESIGN_Y * 1.1f / PTM_RATIO)); _groundBody->CreateFixture(&groundBox, 0); state = GameStates::Playing; scheduleUpdate(); //schedule(schedule_selector(BlobLayer::generate), 2.3f); bigText = Label::createWithTTF("", NORMAL_TTF, 200.0f); bigText->setHorizontalAlignment(TextHAlignment::CENTER); bigText->setVerticalAlignment(TextVAlignment::CENTER); bigText->setPosition(CP(0.5f, 0.45f)); addChild(bigText, 10); auto touchListener = EventListenerTouchOneByOne::create(); touchListener->onTouchBegan = CC_CALLBACK_2(BlobLayer::onTouchBegan, this); touchListener->onTouchMoved = CC_CALLBACK_2(BlobLayer::onTouchMoved, this); touchListener->onTouchEnded = CC_CALLBACK_2(BlobLayer::onTouchEnded, this); touchListener->onTouchCancelled = CC_CALLBACK_2(BlobLayer::onTouchEnded, this); getEventDispatcher()->addEventListenerWithSceneGraphPriority(touchListener, this); auto tilt = EventListenerAcceleration::create(CC_CALLBACK_2(BlobLayer::onAcceleration, this)); getEventDispatcher()->addEventListenerWithSceneGraphPriority(tilt, this); ambientForce = b2Vec2_zero; regenPeriod = 1.5f; minRegenPeriod = regenPeriod * 0.5f; regenTime = 0; lastObservedScore = BlobScene::LastScore; schedule(schedule_selector(BlobLayer::checkCombo), 1.5f); /* auto ringParticle = ParticleGalaxy::create(); ringParticle->setPositionType(ParticleSystem::PositionType::RELATIVE); ring->addChild(ringParticle);*/ return true; }