c++ - Crossed physics bodies issue in cocos2dxv3.4 -


i new cocos2dx v3.x.i developing basic car racing game in car can move within continuous scrolling track straight , small curvy "road fighter" game in google play store.for moving car,i using device accelerometer , adjusts velocity of car body acc. that.for path body,i using edgechain shape of 5 points have shown below makes bound area car motion , car should not go beyond that.but setvelocity function,my car body goes outside boundary.i have set collisionbitmask , contacttestbitmask,collision detected,even physics body of car crossed on edge chain body of path.

auto *sprite = sprite::create("road.jpg"); sprite->setposition(vec2(winsize.width/2,winsize.height/2)); sprite->setscalex(rx); sprite->setscaley(ry); this->addchild(sprite, 0);  auto edge_body=physicsbody::createedgechain(vec ,5 ,physicsbody_material_default,3); edge_body->setdynamic(false); edge_body->addshape(physicsshapeedgechain::create(vec3, 5)); sprite->setphysicsbody(edge_body); edge_body->setcollisionbitmask(1); edge_body->setcontacttestbitmask(true); //where vec , vec3 vectors of 5 points acc track boundary.   auto *mycar=sprite::create(car_png_name); mycar->setposition(point(winsize.width/2,winsize.height*0.35)); addchild(mycar,2); mycar_body=physicsbody::createbox(mycar->getcontentsize(),physicsmaterial(0,1,0)); mycar->setphysicsbody(mycar_body); mycar_body->setrotationenable(false); mycar_body->setcollisionbitmask(2); mycar_body->setcontacttestbitmask(true);   // device accelerometer device::setaccelerometerenabled(true); auto listener= eventlisteneracceleration::create (cc_callback_2(helloworld::onacceleration,this)); _eventdispatcher->addeventlistenerwithscenegraphpriority(listener, this);   auto contact_listener=eventlistenerphysicscontact::create(); contact_listener->oncontactbegin=cc_callback_1(helloworld::oncontactbegin, this); this->geteventdispatcher()->addeventlistenerwithscenegraphpriority(contact_listener, this);    void helloworld::onacceleration(cocos2d::acceleration *acc, cocos2d::event *event) {   #define kfilteringfactor 0.7   #define krestaccelx 0   #define ksquirrelmaxpointspersec (winsize.width*0.5)   #define kmaxdiffx 0.15    double rollingx=0;     acc->y = acc->x;     rollingx = (acc->y * kfilteringfactor) + (rollingx * (1.0 - kfilteringfactor));     float accelx = acc->y - rollingx;     float acceldiff = accelx - krestaccelx;     float accelfraction = acceldiff / kmaxdiffx;     carspeed = ksquirrelmaxpointspersec * accelfraction*1.5;       if(mycar_body!=null)     mycar_body->setvelocity(vec2(carspeed*1.5,0));  } 

i have faced issue in cocos2dxv3.4.the same logic works fine in cocos2dxv2.2.6 box2d b2body.i not getting wrong or how in other way,i can move car accelerometer within scrolling boundary.can suggest?

thanks in advance.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -