Advertisement
Guest User

Untitled

a guest
Apr 18th, 2015
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.86 KB | None | 0 0
  1. GameObjectPhysics::GameObjectPhysics(
  2.     State* state_,
  3.     CSCore::Vector2 sprite_dimensions_,
  4.     CSCore::Vector2 physics_dimensions_,
  5.     CSCore::Vector2 position_,
  6.     CSCore::Vector2 physics_offset_,
  7.     std::string texture_name_,
  8.     std::string sprite_name_,
  9.     int body_type_) :
  10. state(state_),
  11. sprite_dimensions(sprite_dimensions_),
  12. physics_offset(physics_offset_),
  13. flagged_for_deletion(false)
  14. {
  15.     CSRendering::SpriteComponentSPtr sprite_component;
  16.  
  17.     if (body_type_ != BodyType::KINEMATIC)
  18.     {
  19.         //load the texture and texture atlas.
  20.         CSCore::ResourcePool* resourcePool =
  21.             CSCore::Application::Get()->GetResourcePool();
  22.  
  23.         CSRendering::TextureCSPtr texture =
  24.             resourcePool->LoadResource<CSRendering::Texture>(CSCore::StorageLocation::k_package, texture_name_ + ".csimage");
  25.  
  26.         CSRendering::TextureAtlasCSPtr textureAtlas =
  27.             resourcePool->LoadResource<CSRendering::TextureAtlas>(CSCore::StorageLocation::k_package, texture_name_ + ".csatlas");
  28.  
  29.         //create the material
  30.         CSRendering::MaterialFactory* materialFactory =
  31.             CSCore::Application::Get()->GetSystem<CSRendering::MaterialFactory>();
  32.  
  33.         CSRendering::MaterialSPtr material =
  34.             materialFactory->CreateSprite(texture_name_ + "_material_" + UniqueIntGenerator::getUniqueString(), texture);
  35.  
  36.         material->SetTransparencyEnabled(true);
  37.  
  38.         //Create the sprite component
  39.         sprite_component =
  40.             state->getRenderComponentFactory()->CreateSpriteComponent(
  41.             sprite_dimensions,
  42.             textureAtlas,
  43.             sprite_name_,
  44.             material,
  45.             CSRendering::SpriteComponent::SizePolicy::k_none);
  46.     }
  47.  
  48.     //create the sprite entity and add the sprite component
  49.     entity = CSCore::Entity::Create();
  50.  
  51.     if (body_type_ != BodyType::KINEMATIC)
  52.         entity->AddComponent(sprite_component);
  53.  
  54.     //add the sprite to the scene
  55.     state->GetScene()->Add(entity);
  56.  
  57.  
  58.     // initialise the body
  59.     ...
  60.  
  61.     syncPositioning();
  62.  
  63.     state->addGO(this);
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement