Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create a tank with cocos2dx
    primarykey
    data
    text
    <p>Me and a friend of mine are trying to make a tank with cocos2dx. we are so far that the tank is on the screen and the barrel is attached to the tank <img src="https://i.stack.imgur.com/LhTmx.png" alt="enter image description here"></p> <p>but now we want to try to the rotate the barrel but nothing is happening, the joint is at the center where the barrel start en de dome ends. both the tank and the barrel are dynamic bodies and we are using a friction joint (see code)</p> <pre><code>// Create sprite and add it to the layer CCSprite *tank = CCSprite::create(); //tank-&gt;initWithFile("../Resources/tanks/001/tank.png"); tank-&gt;setPosition(pos); tank-&gt;setTag(1); this-&gt;addChild(tank); // Create ball body b2BodyDef tankBodyDef; tankBodyDef.type = b2_dynamicBody; tankBodyDef.position = toMeters(&amp;pos); tankBodyDef.userData = tank; tankBody = _world-&gt;CreateBody(&amp;tankBodyDef); // Create shape definition and add body shapeCache-&gt;addFixturesToBody(tankBody, "001/tank"); pos = CCPointMake(580, 450); // Create sprite and add it to the layer CCSprite *barrel = CCSprite::create(); //barrel-&gt;initWithFile("Tanks/001/barrel.png"); barrel-&gt;setPosition(pos); barrel-&gt;setTag(2); this-&gt;addChild(barrel); // Create ball body b2BodyDef barrelBodyDef; barrelBodyDef.type = b2_dynamicBody; barrelBodyDef.position = toMeters(&amp;pos); barrelBodyDef.userData = barrel; barrelBody = _world-&gt;CreateBody(&amp;barrelBodyDef); tankBarrelAnchor = CreateRevoluteJoint(tankBody, barrelBody, -85.f, 180.f, 2000000.f, 0.f, true, false); tankBarrelAnchor-&gt;localAnchorA = b2Vec2(0, 0); tankBarrelAnchor-&gt;localAnchorB = b2Vec2(0, 0); tankBarrelAnchor-&gt;referenceAngle = 0; joint = (b2RevoluteJoint*)_world-&gt;CreateJoint(tankBarrelAnchor); b2RevoluteJointDef* Level::CreateRevoluteJoint(b2Body* A, b2Body* B, float lowerAngle, float upperAngle, float maxMotorTorque, float motorSpeed, boolean enableMotor, boolean collideConnect){ b2RevoluteJointDef *revoluteJointDef = new b2RevoluteJointDef(); revoluteJointDef-&gt;bodyA = A; revoluteJointDef-&gt;bodyB = B; revoluteJointDef-&gt;collideConnected = collideConnect; revoluteJointDef-&gt;lowerAngle = CC_DEGREES_TO_RADIANS(lowerAngle); revoluteJointDef-&gt;upperAngle = CC_DEGREES_TO_RADIANS(upperAngle); revoluteJointDef-&gt;enableLimit = true; revoluteJointDef-&gt;enableMotor = enableMotor; revoluteJointDef-&gt;maxMotorTorque = maxMotorTorque; revoluteJointDef-&gt;motorSpeed = CC_DEGREES_TO_RADIANS(motorSpeed); //1 turn per second counter-clockwise return revoluteJointDef; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload