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


C++ VisualServer::texture_create_from_image方法代码示例

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


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

示例1: _create_body_shape_data

	void _create_body_shape_data() {
		VisualServer *vs = VisualServer::get_singleton();
		Physics2DServer *ps = Physics2DServer::get_singleton();

		// SEGMENT

		{

			DVector<uint8_t> pixels;
			pixels.resize(32*2*2);
			for(int i=0;i<2;i++) {

				for(int j=0;j<32;j++) {

					pixels.set(i*32*2+j*2+0,(j==0)?255:0);
					pixels.set(i*32*2+j*2+1,255);
				}
			}

			Image image(32,2,0,Image::FORMAT_LA8,pixels);

			body_shape_data[Physics2DServer::SHAPE_SEGMENT].image=vs->texture_create_from_image(image);

			RID segment_shape = ps->shape_create(Physics2DServer::SHAPE_SEGMENT);
			Rect2 sg(Point2(-16,0),Point2(16,0));
			ps->shape_set_data(segment_shape,sg);

			body_shape_data[Physics2DServer::SHAPE_SEGMENT].shape = segment_shape;

		}
		// CIRCLE

		{

			DVector<uint8_t> pixels;
			pixels.resize(32*32*2);
			for(int i=0;i<32;i++) {

				for(int j=0;j<32;j++) {

					bool black=Vector2(i-16,j-16).length_squared() < 16*16;

					pixels.set(i*32*2+j*2+0,(i==16 || j==16)?255:0);
					pixels.set(i*32*2+j*2+1,black?255:0);
				}
			}

			Image image(32,32,0,Image::FORMAT_LA8,pixels);

			body_shape_data[Physics2DServer::SHAPE_CIRCLE].image=vs->texture_create_from_image(image);

			RID circle_shape = ps->shape_create(Physics2DServer::SHAPE_CIRCLE);
			ps->shape_set_data(circle_shape,16);

			body_shape_data[Physics2DServer::SHAPE_CIRCLE].shape = circle_shape;

		}

		// BOX

		{

			DVector<uint8_t> pixels;
			pixels.resize(32*32*2);
			for(int i=0;i<32;i++) {

				for(int j=0;j<32;j++) {

					bool black=i>0 && i<31 && j>0 && j<31;

					pixels.set(i*32*2+j*2+0,black?0:255);
					pixels.set(i*32*2+j*2+1,255);
				}
			}

			Image image(32,32,0,Image::FORMAT_LA8,pixels);

			body_shape_data[Physics2DServer::SHAPE_RECTANGLE].image=vs->texture_create_from_image(image);

			RID rectangle_shape = ps->shape_create(Physics2DServer::SHAPE_RECTANGLE);
			ps->shape_set_data(rectangle_shape,Vector2(16,16));

			body_shape_data[Physics2DServer::SHAPE_RECTANGLE].shape = rectangle_shape;

		}


		// CAPSULE

		{

			DVector<uint8_t> pixels;
			pixels.resize(32*64*2);
			for(int i=0;i<64;i++) {

				for(int j=0;j<32;j++) {


					int si = i>48 ? i - 32 : (i<16 ? i : 16);
					bool black=Vector2(si-16,j-16).length_squared() < 16*16;
//.........这里部分代码省略.........
开发者ID:lonesurvivor,项目名称:godot,代码行数:101,代码来源:test_physics_2d.cpp


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