当前位置: 首页>>代码示例>>C++>>正文


C++ CCSpriteBatchNode::createSpriteWithRect方法代码示例

本文整理汇总了C++中CCSpriteBatchNode::createSpriteWithRect方法的典型用法代码示例。如果您正苦于以下问题:C++ CCSpriteBatchNode::createSpriteWithRect方法的具体用法?C++ CCSpriteBatchNode::createSpriteWithRect怎么用?C++ CCSpriteBatchNode::createSpriteWithRect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CCSpriteBatchNode的用法示例。


在下文中一共展示了CCSpriteBatchNode::createSpriteWithRect方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CCRectMake

void Box2DTestLayer::addNewSpriteWithCoords(CCPoint p)
{
	//UXLOG(L"Add sprite %0.2f x %02.f",p.x,p.y);
	CCSpriteBatchNode* sheet = (CCSpriteBatchNode*)getChildByTag(kTagSpriteManager);
	
	//We have a 64x64 sprite sheet with 4 different 32x32 images.  The following code is
	//just randomly picking one of the images
	int idx = (CCRANDOM_0_1() > .5 ? 0:1);
	int idy = (CCRANDOM_0_1() > .5 ? 0:1);
	CCSprite *sprite = sheet->createSpriteWithRect( CCRectMake(32 * idx,32 * idy,32,32));
	sheet->addChild(sprite);
	
	sprite->setPosition( CCPointMake( p.x, p.y) );
	
	// Define the dynamic body.
	//Set up a 1m squared box in the physics world
	b2BodyDef bodyDef;
	bodyDef.type = b2_dynamicBody;
	bodyDef.position.Set(p.x/PTM_RATIO, p.y/PTM_RATIO);
	bodyDef.userData = sprite;
	b2Body *body = world->CreateBody(&bodyDef);
	
	// Define another box shape for our dynamic body.
	b2PolygonShape dynamicBox;
	dynamicBox.SetAsBox(.5f, .5f);//These are mid points for our 1m box
	
	// Define the dynamic body fixture.
	b2FixtureDef fixtureDef;
	fixtureDef.shape = &dynamicBox;	
	fixtureDef.density = 1.0f;
	fixtureDef.friction = 0.3f;
	body->CreateFixture(&fixtureDef);
}
开发者ID:BigHand,项目名称:cocos2d-x,代码行数:33,代码来源:Box2dTest.cpp


注:本文中的CCSpriteBatchNode::createSpriteWithRect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。