zoukankan      html  css  js  c++  java
  • 物理引擎

    bool HelloWorld::init()
    {
        //////////////////////////////
        // 1. super init first
        if ( !Layer::init() )
        {
            return false;
        }
        
        Size visibleSize = Director::getInstance()->getVisibleSize();
        Vec2 origin = Director::getInstance()->getVisibleOrigin();
    	//定义世界的边界
    	auto body = PhysicsBody::createEdgeBox(visibleSize,PHYSICSBODY_MATERIAL_DEFAULT,5.0f);
    	auto edgeNode = Node::create();
    	edgeNode->setPosition(Vec2(visibleSize.width/2,visibleSize.height/2));
    	edgeNode->setPhysicsBody(body);
    	this->addChild(edgeNode);
    
    	setTouchEnabled(true);
    	//设置为单点触摸
    	setTouchMode(Touch::DispatchMode::ONE_BY_ONE);
    
        return true;
    }
    
    bool HelloWorld::onTouchBegan(Touch* touch, Event* event)
    {
    	Vec2 location = touch->getLocation();
    	addNewSpriteAtPosition(location);
    	return false;
    }	
    
    void HelloWorld::addNewSpriteAtPosition(Vec2 p)
    {    
        auto sp = Sprite::create("Ball.png");
    	sp->setTag(1);
    	
    	auto body = PhysicsBody::createCircle(sp->getContentSize().width / 2);
        sp->setPhysicsBody(body);	
        sp->setPosition(p);
    	this->addChild(sp);
    }
    

    效果如下:



  • 相关阅读:
    GlusterFS安装部署
    glusterfs peer失败
    GlusterFs 启动报错
    利用idea反编译jar包
    hive 错误记录 之moveing 失败
    节点不可用,显示noReady
    kafka 配置认证与授权
    flink (2) 读取kafka数据
    Flink (1) 安装部署
    redis the cluster is down
  • 原文地址:https://www.cnblogs.com/Anzhongliu/p/6091934.html
Copyright © 2011-2022 走看看