物理场景关节Chipmunk

这篇博客详细介绍了在Cocos2d-x游戏引擎中使用Chipmunk物理引擎实现不同类型的关节,包括固定关节、距离关节、旋转限制关节、弹簧关节等,展示了如何创建和配置这些关节来实现物体间的交互效果。
摘要由CSDN通过智能技术生成

//

//  PhysicsJoints2.hpp

//  day01

//

//  Created by MAC on 16/7/14.

//

//


#ifndef PhysicsJoints2_hpp

#define PhysicsJoints2_hpp


#include <stdio.h>

#include <iostream>

using namespace std;

#include "cocos2d.h"

using namespace cocos2d;

#include "ui/CocosGUI.h"

using namespace cocos2d::ui;


const int DRAG_BODYS_TAG =1;

class PhysicsJoints2:public Layer{

public:

    static Scene* createScene();

    bool init();

    CREATE_FUNC(PhysicsJoints2);

    void onEnter();

    void onExit();

    PhysicsWorld* getPhysicsWorld();

    Sprite* makeBall(Vec2 point, float radius, PhysicsMaterial material = PHYSICSSHAPE_MATERIAL_DEFAULT);

    Sprite* makeBox(Vec2 point, Size size, int color=0, PhysicsMaterial material = PHYSICSSHAPE_MATERIAL_DEFAULT);

private:

    Size visiableSize;

    Vec2 center;

    PhysicsBody* _touchBody;

};



#endif /* PhysicsJoints2_hpp */



//

//  PhysicsJoints2.cpp

//  day01

//

//  Created by MAC on 16/7/14.

//

//


#include "PhysicsJoints2.hpp"




Scene* PhysicsJoints2::createScene(){

    auto scene = Scene::createWithPhysics();

    //set the debug

    scene->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);

    //设置重力(xy

    scene->getPhysicsWorld()->setGravity(Vec2(0, 0));

    auto layer = PhysicsJoints2::create();

    scene->addChild(layer);

    return scene;

}

bool PhysicsJoints2::init(){

    if (!Layer::init()) {

        return false;

    }

    visiableSize = Director::getInstance()->getVisibleSize();

    center = Vec2(visiableSize.width/2,visiableSize.height/2);//

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值