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);
    }
    

    效果如下:



  • 相关阅读:
    BZOJ-3495 前缀优化建图2-SAT
    洛谷P3979 遥远的国度 树链剖分+分类讨论
    hdu
    hdu
    poj
    poj-1330(暴力写的lca)
    树链剖分
    Dijkstra
    Floyed
    最短路径
  • 原文地址:https://www.cnblogs.com/Anzhongliu/p/6091934.html
Copyright © 2011-2022 走看看