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


C++ Sprite::ApplyChange方法代码示例

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


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

示例1: CheckForSpriteScaling

void LevelEditor::CheckForSpriteScaling()
{
	if (mSelectedObject)
	{
		static bool pressingScale = false;
		static Vector2 mouseStartPos = Vector2(0,0);
		static Vector2 originalDimensions = Vector2(0,0);
		if (!pressingScale && GetAsyncKeyState('X') < 0 && GetAsyncKeyState(VK_LBUTTON) < 0 && GetAsyncKeyState(VK_CONTROL) >= 0)
		{
			pressingScale = true;

			POINT currentMouse;
			GetCursorPos(&currentMouse);
			ScreenToClient(DXWindow::GetInstance()->Hwnd(), &currentMouse);
			mouseStartPos = Vector2(currentMouse.x, currentMouse.y);

			originalDimensions = Vector2(mSelectedObject->Dimensions().X, mSelectedObject->Dimensions().Y);
		}
		else if (pressingScale && GetAsyncKeyState(VK_LBUTTON) < 0)
		{
			// get the initial distance between the game object and the mouse
			Vector2 origDistance = mouseStartPos - Vector2(mSelectedObject->X(), mSelectedObject->Y());
			// origDistance = Vector2(abs(origDistance.X), abs(origDistance.Y));

			float origLength = origDistance.Length();

			// now get the distance between the current mouse position
			POINT currentMouse;
			GetCursorPos(&currentMouse);
			ScreenToClient(DXWindow::GetInstance()->Hwnd(), &currentMouse);
			Vector2 newDistance = Vector2(currentMouse.x, currentMouse.y) - Vector2(mSelectedObject->X(), mSelectedObject->Y());

			float newLength = newDistance.Length();

			float scale = newLength / origLength;

			if (scale != 0)
			{
				mSelectedObject->SetDimensionsXYZ(originalDimensions.X * scale, originalDimensions.Y * scale, mSelectedObject->Dimensions().Z);

				Sprite * s = GetAsSprite(mSelectedObject);
				if (s)
				{
					s->ScaleSpriteOnly(scale, scale);
					s->SetIsNativeDimensions(false);
					s->ApplyChange(Graphics::GetInstance()->Device());
				}
			}
		}

		if (GetAsyncKeyState('X') >= 0)
		{
			pressingScale = false;
			mouseStartPos = Vector2(0,0);
			originalDimensions = Vector2(0,0);
		}
	}
}
开发者ID:jeromebyrne,项目名称:2DPlatformer,代码行数:58,代码来源:LevelEditor.cpp

示例2: CheckForSettingNativeRes

void LevelEditor::CheckForSettingNativeRes()
{
	if (mSelectedObject)
	{
		if (GetAsyncKeyState('N') < 0 && GetAsyncKeyState(VK_CONTROL) < 0)
		{
			Sprite * s = GetAsSprite(mSelectedObject);

			if (s)
			{
				s->SetIsNativeDimensions(true);
				s->ScaleSpriteOnly(1,1); // resets vertices and debug bounding box
				s->ApplyChange(Graphics::GetInstance()->Device());
			}
		}
	}
}
开发者ID:jeromebyrne,项目名称:2DPlatformer,代码行数:17,代码来源:LevelEditor.cpp

示例3: CheckInput_Regular

void LevelEditor::CheckInput_Regular()
{
	list<shared_ptr<GameObject> > & gameObjects = GameObjectManager::Instance()->GetGameObjectList();

	static bool pressingSelect = false;
	static bool pressingPlace = false;

	if (mSelectedObject)
	{
		if (!pressingSelect && GetAsyncKeyState(VK_RBUTTON) < 0 && GetAsyncKeyState('R') >= 0)
		{
			GameObject * obj = GetGameObjectClickedOn(gameObjects);

			if (obj)
			{
				if (obj == mSelectedObject)
				{
					// deselect
					mSelectedObject->ShowDebugText(false);
					mSelectedObject->SetLevelEditShowSelected(false);
					mSelectedObject = nullptr;
				}
				else
				{
					mSelectedObject->ShowDebugText(false);
					mSelectedObject->SetLevelEditShowSelected(false);
					mSelectedObject = obj;
					mSelectedObject->ShowDebugText(true);
					mSelectedObject->SetLevelEditShowSelected(true);
				}
			}

			pressingSelect = true;
		}

		if (mSelectedObject)
		{
			if (GetAsyncKeyState(VK_LBUTTON) < 0 && GetAsyncKeyState('X') >= 0 && GetAsyncKeyState('C') >= 0 && GetAsyncKeyState('R') >= 0)
			{
				// drag
				// get the mouse in world coordinates and set the game objects position
				POINT currentMouse;
				GetCursorPos(&currentMouse);
				ScreenToClient(DXWindow::GetInstance()->Hwnd(), &currentMouse);

				// the backbuffer may be larger in size than the the window (Windows scaling) so scale accordingly
				float scaleX = Graphics::GetInstance()->BackBufferWidth() / DXWindow::GetInstance()->GetWindowDimensions().X;
				float scaleY = Graphics::GetInstance()->BackBufferHeight() / DXWindow::GetInstance()->GetWindowDimensions().Y;

				Vector2 worldPos = Utilities::ScreenToWorld(Vector2(currentMouse.x * scaleX, currentMouse.y * scaleY));

				mSelectedObject->SetX(worldPos.X);
				mSelectedObject->SetY(worldPos.Y);

				Sprite * sprite = GetAsSprite(mSelectedObject);
				if (sprite)
				{
					sprite->ApplyChange(Graphics::GetInstance()->Device());
					sprite->Update(0);
				}
				MovingSprite * movingSprite = GetAsMovingSprite(mSelectedObject);
				if (movingSprite)
				{
					movingSprite->SetVelocityXYZ(0, 0, 0);
				}

				ScrollingSprite * scrollingSprite = GetAsScrollingSprite(mSelectedObject);
				if (scrollingSprite)
				{
					scrollingSprite->SetLerpStartPos(worldPos);
				}

				SolidLineStrip * solidLineStrip = GetAsSolidLineStrip(mSelectedObject);
				if (solidLineStrip)
				{
					vector<SolidLineStrip::SolidLinePoint> points = solidLineStrip->GetLinePoints();
					solidLineStrip->RecalculateLines(points);
				}

				ParticleSpray * particleSpray = GetAsParticleSpray(mSelectedObject);
				if (particleSpray)
				{
					particleSpray->Reset();
				}

				pressingPlace = true;
			}
		}
	}
	else
	{
		if (!pressingSelect && GetAsyncKeyState(VK_RBUTTON) < 0 && GetAsyncKeyState('R') >= 0)
		{
			mSelectedObject = GetGameObjectClickedOn(gameObjects);

			if (mSelectedObject)
			{
				mSelectedObject->ShowDebugText(true);
				mSelectedObject->SetLevelEditShowSelected(true);
			}
//.........这里部分代码省略.........
开发者ID:jeromebyrne,项目名称:2DPlatformer,代码行数:101,代码来源:LevelEditor.cpp


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