本文整理汇总了C++中Sprite::GetWidth方法的典型用法代码示例。如果您正苦于以下问题:C++ Sprite::GetWidth方法的具体用法?C++ Sprite::GetWidth怎么用?C++ Sprite::GetWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sprite
的用法示例。
在下文中一共展示了Sprite::GetWidth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Explosion
void
Game::SpawnExplosion(int x, int y)
{
Sprite* aS = m_pBackBuffer->CreateSprite("assets\\explosion.png");
// create an explosion object
Explosion* explosion = new Explosion();
// initialize the texture
if (!explosion->Initialise(*aS->GetTexture())) {
LogManager::GetInstance().Log("Explosion Init Fail!");
return;
}
// set the width and speed of the animation
int fw = aS->GetWidth() / 5;
explosion->SetFrameWidth(fw); // 5 frames in the animation
explosion->SetFrameSpeed(0.1f);
for (int i = 0; i < 5; i++) {
explosion->AddFrame(i * fw);
}
// set the center points for visual alignment
explosion->SetCenter(fw / 2, aS->GetHeight() / 2);
// set the x and y
explosion->SetX(x - explosion->GetCenterX() / 2);
explosion->SetY(y - explosion->GetCenterY() / 2);
// add to the explosion container
m_explosion.push_back(explosion);
}
示例2: GetWidth
uint16 WorkerActor::GetWidth(void) const
{
Assert(m_unitSpriteGroup != NULL);
if (m_unitSpriteGroup == NULL) return 0;
Sprite * theSprite = m_unitSpriteGroup->GetGroupSprite((GAME_ACTION)m_curUnitAction);
return (theSprite) ? theSprite->GetWidth() : 0;
}
示例3: GetSize
Vector2 Animation::GetSize()
{
// To get the size of the animation, we'll just get the size of the first frame.
// If other frames are different sizes, then the concept of a size for the animation itself
// is meaningless, so we don't really care about that part.
Sprite *pFirstFrameSprite = frameList[0]->GetSprite();
return Vector2(pFirstFrameSprite->GetWidth(), pFirstFrameSprite->GetHeight());
}
示例4: DrawBulletsRemaining
void DrawBulletsRemaining(Weapon* DrawMe, int timediff)
{
Sprite* BulletSprite;
Sprite* MySprite;
Bullet* TheBullet;
char* Name = "INVALID BULLETS";
RECT Client;
GetClientRect(TheDisplay.GetHWnd(), &Client);
TheBullet = GetGlobalBulletData(DrawMe->mBulletID);
if(!TheBullet)
return;
Name = TheBullet->mName;
BulletSprite = GetGlobalSpriteData(TheBullet->mFullBulletSpriteID);
if(!BulletSprite)
return;
MySprite = new Sprite;
MySprite->InitializeSpriteCopy(BulletSprite);
POINT FontOrigin;
FontOrigin.x = Client.right - DrawMe->mMaxRounds * BulletSprite->GetWidth();
int StrWidth = GetFontBySizeIndex(WEAPONSELECTOR_BULLET_FONT_ID)->GetStringWidth(Name);
if(FontOrigin.x + StrWidth > Client.right)
FontOrigin.x -= (FontOrigin.x + StrWidth) - Client.right + 20;
FontOrigin.y = Client.bottom - BulletSprite->GetHeight() - GetFontBySizeIndex(WEAPONSELECTOR_BULLET_FONT_ID)->GetCharHeight() - 5;
int FullWidth = DrawMe->mCurrentRounds * BulletSprite->GetWidth();
if(FullWidth > Client.right - Client.left)
return;
GameWeaponSelector.BulletName->SetLoc(FontOrigin);
GameWeaponSelector.BulletName->SetWidth(Client.right - Client.left);
int FullHeight = BulletSprite->GetHeight();
POINT Loc;
Loc.x = Client.right - FullWidth;
Loc.y = Client.bottom - FullHeight;
for(int i = 0; i < DrawMe->mCurrentRounds; i++)
{
MySprite->SetLoc(Loc);
MySprite->Draw(TheDisplay);
Loc.x += BulletSprite->GetWidth();
}
GameWeaponSelector.BulletName->Update(timediff);
GameWeaponSelector.BulletName->Draw(TheDisplay);
delete MySprite;
}
示例5: DrawSprite
void BackBuffer::DrawSprite(Sprite& sprite)
{
SDL_Rect dest;
dest.x = sprite.GetX();
dest.y = sprite.GetY();
dest.w = sprite.GetWidth();
dest.h = sprite.GetHeight();
SDL_RenderCopy(m_pRenderer, sprite.GetTexture()->GetTexture(), 0, &dest);
}
示例6: SetScrollbar
void ControlsFactory::SetScrollbar(DAVA::UIHierarchy *h)
{
Rect fr = h->GetRect();
Sprite *scrollSpr = Sprite::Create("~res:/Gfx/UI/scroll");
UIScrollBar *scrollBar = new UIScrollBar(Rect(fr.dx - scrollSpr->GetWidth(), 0, scrollSpr->GetWidth(), fr.dy),
UIScrollBar::ORIENTATION_VERTICAL);
scrollBar->GetSlider()->SetSprite(scrollSpr, 0);
scrollBar->GetSlider()->GetBackground()->SetDrawType(UIControlBackground::DRAW_STRETCH_VERTICAL);
scrollBar->GetSlider()->GetBackground()->SetTopBottomStretchCap(10);
scrollBar->SetDelegate(h);
scrollBar->SetInputEnabled(false);
h->AddControl(scrollBar);
SafeRelease(scrollSpr);
SafeRelease(scrollBar);
}
示例7: GetWidth
uint16 EffectActor::GetWidth(void) const
{
Assert(m_effectSpriteGroup);
if (!m_effectSpriteGroup) return 0;
Sprite * theSprite = m_effectSpriteGroup->GetGroupSprite((GAME_ACTION)m_curEffectAction);
if (!theSprite && (m_curEffectAction != EFFECTACTION_PLAY))
{
theSprite = m_effectSpriteGroup->GetGroupSprite((GAME_ACTION)EFFECTACTION_PLAY);
}
return theSprite ? theSprite->GetWidth() : 0;
}
示例8: GetWidth
uint16 TradeActor::GetWidth(void)
{
Assert(m_goodSpriteGroup != NULL);
if (m_goodSpriteGroup == NULL) return 0;
Sprite *theSprite;
theSprite = m_goodSpriteGroup->GetGroupSprite((GAME_ACTION)m_curGoodAction);
if (theSprite != NULL) {
return theSprite->GetWidth();
} else {
return 0;
}
}
示例9: Redo
void ActionSetVisibilityPoint::Redo()
{
Sprite* visibilityToolSprite = visibilityToolProxy->GetSprite();
RenderManager::Instance()->SetRenderTarget(visibilityToolSprite);
RenderManager::Instance()->ClearWithColor(0.f, 0.f, 0.f, 0.f);
cursorSprite->SetPosition(redoVisibilityPoint - cursorSprite->GetSize() / 2.f);
cursorSprite->Draw();
RenderManager::Instance()->RestoreRenderTarget();
visibilityToolProxy->UpdateVisibilityPointSet(true);
visibilityToolProxy->UpdateRect(Rect(0.f, 0.f, visibilityToolSprite->GetWidth(), visibilityToolSprite->GetHeight()));
visibilityToolProxy->SetVisibilityPoint(redoVisibilityPoint);
}
示例10: ApplyAjustedSize
ControlsPositionData ControlsAdjustSizeCommand::ApplyAjustedSize(HierarchyTreeController::SELECTEDCONTROLNODES& controls)
{
ControlsPositionData resultData;
for (HierarchyTreeController::SELECTEDCONTROLNODES::iterator iter = controls.begin(); iter != controls.end(); ++iter)
{
HierarchyTreeControlNode* control = (*iter);
UIControl* uiControl = control->GetUIObject();
int32 nodeId = control->GetId();
if (uiControl)
{
// Get sprite
Sprite* sprite = uiControl->GetSprite();
Rect prevRect = uiControl->GetRect();
Rect updatedRect = prevRect;
if (sprite)
{
// Save control size data for undo
resultData.AddControl(uiControl);
// Set new size of updated rect
updatedRect.dx = sprite->GetWidth();
updatedRect.dy = sprite->GetHeight();
BaseMetadata* baseMetadata = GetMetadataForTreeNode(nodeId);
// This command is NOT state-aware and contains one and only param.
baseMetadata->SetActiveParamID(0);
baseMetadata->ApplyResize(prevRect, updatedRect);
SAFE_DELETE(baseMetadata);
}
}
}
return resultData;
}
示例11: SetStretchCapMaxValues
void BackGroundPropertyGridWidget::SetStretchCapMaxValues()
{
WidgetSignalsBlocker blocker(ui->drawTypeComboBox);
// Get current drawType combo value
int selectedIndex = ui->drawTypeComboBox->currentIndex();
UIControlBackground::eDrawType drawType = BackgroundGridWidgetHelper::GetDrawType(selectedIndex);
// Set default values
int horizontalStretchMax = 999;
int verticalStretchMax = 999;
// For DRAW_TILED option we should set horizontal and vertical stretch maximum values
// Tiling the sprite to more than half of its size have no sence
if (drawType == UIControlBackground::DRAW_TILED)
{
QString spriteName = ui->spriteLineEdit->text();
if (!spriteName.isEmpty())
{
Sprite* sprite = Sprite::Create(spriteName.toStdString());
if (sprite)
{
// Get sprite's active size
float32 texDx = sprite->GetWidth();
float32 texDy = sprite->GetHeight();
// Calculate maximum stretch values
horizontalStretchMax = texDx / 2 - 1;
verticalStretchMax = texDy / 2 - 1;
}
SafeRelease(sprite);
}
}
ui->lrSpinBox->setMaximum(horizontalStretchMax);
ui->tbSpinBox->setMaximum(verticalStretchMax);
}
示例12: if
Character::Character(int aNumberOfLimbs, glm::vec2 aRangeOfLimbSize, glm::vec2 aRangeOfStats, glm::vec2 aPosition, bool aIsPlayer)
{
m_SwingLeft = false;
m_Timer = nullptr;
m_DamageTimer = nullptr;
m_Destroyed = false;
m_DestroyPlayer = false;
m_SlatedForDestruction = false;
m_Health = DEFAULT_HEALTH;
m_Strength = DEFAULT_STRENGTH;
m_Speed = DEFAULT_SPEED;
m_IsPlayer = aIsPlayer;
m_NumberOfLimbs = aNumberOfLimbs;
bool leftArm = true;
bool leftLeg = true;
string limbType;
Random* random = new Random();
for(float i = 0; i < m_NumberOfLimbs; i++)
{
//TODO: Fine tune the positioning based off of image size
//Assume all characters face the same direction on spawn
vec2 position = aPosition;
random->RandomizeSeed();
//TODO: Make a local variable, give it a 1% chance of becoming a second head. If it is, set the local variable to i, i to 1 (for head), make the head, then set i to the local variable
if (i == 0)
{
//Torso, do nothing
if(m_IsPlayer == true)
limbType = "CharTorso"; //TODO: Make these constants
else
limbType = "DemonTorso";
}
else if (i == 1)
{
//Gives visibility to the body better. Decide if we want to do this
position.y -= 2;
if(m_IsPlayer == true)
limbType = "CharHead";
else
limbType = "DemonHead";
}
else
{
if ((int)i % 2 == 0)
{
if (leftArm == true)
{
position.x -= 16;
if(m_IsPlayer == true)
limbType = "CharArmLeft";
else
limbType = "DemonArmLeft";
}
else
{
position.x += 16;
if(m_IsPlayer == true)
limbType = "CharArmRight";
else
limbType = "DemonArmRight";
}
position.y += i;// / m_NumberOfLimbs;
leftArm = !leftArm;
}
else
{
if (leftLeg == true)
{
position.x -= 8; //TODO: Change this to be based on the image width of m_Limbs.at(0)
if(m_IsPlayer == true)
limbType = "CharLegLeft";
else
limbType = "DemonLegLeft";
}
else
{
position.x += 8;
if(m_IsPlayer == true)
limbType = "CharLegRight";
else
limbType = "DemonLegRight";
}
position.y -= 16;
leftLeg = !leftLeg;
}
}
Sprite* sprite = new Sprite(limbType);
glm::vec2 size = glm::vec2(sprite->GetWidth(), sprite->GetHeight());
//.........这里部分代码省略.........
示例13: Loop
void Game::Loop()
{
// Splash screen
SDL_Surface* sdl_surface = m_screen->GetSDLSurface();
SDL_FillRect(sdl_surface, 0, SDL_MapRGB(sdl_surface->format, 101, 192, 49));
Sprite* sprite = Sprite::CreateFromTexture(*m_gfx_manager, "splash");
sprite->Render(*m_screen, (m_screen->GetWidth() / 2) - (sprite->GetWidth() / 2), (m_screen->GetHeight() / 2) - (sprite->GetHeight() / 2));
SDL_Flip(sdl_surface);
SDL_Event event;
bool running = true;
bool exit = false;
unsigned int interval = 0;
m_timer->Reset();
while (running && interval < 3000)
{
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_QUIT:
running = false;
exit = true;
break;
case SDL_KEYDOWN:
running = false;
break;
default:
break;
}
}
m_timer->Update();
interval += m_timer->GetInterval();
}
Sprite::DestroySprite(sprite);
if (!exit)
{
m_timer->Reset();
running = true;
while (running)
{
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_QUIT:
running = false;
break;
case SDL_KEYDOWN:
// Exit game
if (event.key.keysym.sym == SDLK_ESCAPE)
{
if (m_menu)
{
running = false;
}
else
{
StartNewGame(true);
}
}
// New game
else if (event.key.keysym.sym == SDLK_F2)
{
StartNewGame(false);
}
// Pause game
else if (event.key.keysym.sym == SDLK_p)
{
if (!m_menu)
{
m_pause = !m_pause;
}
}
// Sound on/off
else if (event.key.keysym.sym == SDLK_s)
{
int volume = Mix_Volume(-1, -1);
if (volume == 0)
{
Mix_Volume(-1, MIX_MAX_VOLUME);
}
else
{
Mix_Volume(-1, 0);
}
}
// Screenshot
else if (event.key.keysym.sym == SDLK_F11)
{
m_screen->Capture();
}
break;
default:
break;
}
}
// Update
if (m_snake->IsAlive())
//.........这里部分代码省略.........
示例14: LoadResource
bool MyGame::LoadResource()
{
// Build scene graph
ContainerNode* root = new ContainerNode();
OrthographicProjectionNode* ortho = new OrthographicProjectionNode();
Texture* texTile = Texture::Get("!tile.png");
Texture* texStair = Texture::Get("!stair.png");
Font* texFont = Font::Get("!DroidSans.ttf|texture_size=256");
Cube* floor = new Cube(Vector3f(50.f, 1.f, 50.f), 50.f, "Floor");
floor->SetTexture(texTile);
root->AddChild(floor);
floor->AddToPhysic(0, Vector3f(0, -.5f, 0));
// Stair
float sw = 1.f; // stair depth
float sh = 1.0f; // stair height
for(int i = 0; i < 5; ++i)
{
Cube* stair = new Cube(Vector3f(6.f, sh, sw), 4);
stair->SetTexture(texStair);
root->AddChild(stair);
stair->AddToPhysic(0, Vector3f(0, sh / 2.f + (i * sh), 5 + (i * sw)));
}
TextNode* title = new TextNode(texFont, 12.f, "TAK game sample");
title->SetShader(Shader::Get("!nolight"));
title->SetPositionAbsolute(10, GetScene().GetParams().GetHeight() - 25, 0);
ortho->AddChild(title);
TextNode* instruction = new TextNode(texFont, 12.f, "Drag and hold left mouse button to rotate, hold right mouse button to zoom");
instruction->SetShader(Shader::Get("!nolight"));
instruction->SetPositionAbsolute(10, GetScene().GetParams().GetHeight() - 45, 0);
ortho->AddChild(instruction);
m_txtFps = new TextNode(texFont);
m_txtFps->SetShader(Shader::Get("!nolight"));
m_txtFps->SetPositionAbsolute(10, GetScene().GetParams().GetHeight() - 65, 0);
ortho->AddChild(m_txtFps);
m_txtCubeCount = new TextNode(texFont);
m_txtCubeCount->SetShader(Shader::Get("!nolight"));
m_txtCubeCount->SetPositionAbsolute(10, GetScene().GetParams().GetHeight() - 85, 0);
ortho->AddChild(m_txtCubeCount);
Cube* pc1;
// front wall
pc1 = new Cube(Vector3f(5.5f, 7.f, .5f), 10.f);
pc1->SetTexture(texTile);
root->AddChild(pc1);
pc1->AddToPhysic(0, Vector3f(0, pc1->GetSize().y / 2.f, 9.75f));
// right wall
pc1 = new Cube(Vector3f(.5f, 7.f, 10.f), 10.f);
pc1->SetTexture(texTile);
root->AddChild(pc1);
pc1->AddToPhysic(0, Vector3f(-3, pc1->GetSize().y / 2.f, 5));
// right wall
pc1 = new Cube(Vector3f(.5f, 7.f, 10.f), 10.f);
pc1->SetTexture(texTile);
root->AddChild(pc1);
pc1->AddToPhysic(0, Vector3f(3, pc1->GetSize().y / 2.f, 5));
// Flag engine logo
Sprite* flag = new Sprite(128, 128, Texture::Get("!engineflag.png"));
flag->SetShader(Shader::Get("!nolight"));
flag->SetPositionAbsolute(GetScene().GetParams().GetWidth() - flag->GetWidth() / 2.f, flag->GetHeight() / 2.f - 20.f, 0);
ortho->AddChild(flag);
root->AddChild(ortho);
GetScene().SetRoot(root);
// Setup camera:
Camera* camera = new LookAtCamera(Vector3f(0, 0, 5), 25.f);
GetScene().SetCamera(camera);
return true;
}
示例15: main
int main()
{
Window window(1200, 600, "This is window!");
Render render(window.GetWidth(), window.GetHeight());
ResourceManager* res = ResourceManager::Create();
Texture* card;
card = &res->LoadTextureFromFile("Test.png");
Texture* bg = &res->LoadTextureFromFile("Background.png");
Texture bulletTex = res->LoadTextureFromFile("Bullet.png");
Texture chipTex = res->LoadTextureFromFile("suitsChip.png");
Sprite Background, Card;
Background.SetTexture(*bg);
Background.Scale(1.5);
Background.SetPosition(-800, -600);
Card.SetTexture(*card);
Card.SetPosition(400, 300);
std::vector<Sprite> bullets, chips;
int r = 0, c = 0;
for (int i = 0; i < 12; i++)
{
r = i % 4;
c = i % 3;
Sprite temp;
temp.SetTexture(chipTex);
temp.SetPosition(r*350, c*225);
chips.push_back(temp);
}
window.SetClearColor(100, 50, 150);
float rotation = 0;
float cardSpeed = 10.0f, rotationSpeed = 2.0f, bulletSpeed = 15.0f;
float chipScale = 1.0f;
bool grow = true;
float timer = 0;
while (window.IsOpen())
{
timer++;
if (Input::Hold(Button::W))
{
Card.SetPosition(Card.GetX(), Card.GetY()-cardSpeed);
}
if (Input::Hold(Button::A))
{
Card.SetPosition(Card.GetX()-cardSpeed, Card.GetY());
}
if (Input::Hold(Button::S))
{
Card.SetPosition(Card.GetX(), Card.GetY()+cardSpeed);
}
if (Input::Hold(Button::D))
{
Card.SetPosition(Card.GetX()+cardSpeed, Card.GetY());
}
if (Input::Hold(Button::UP))
{
rotation += rotationSpeed;
}
if (Input::Hold(Button::LEFT))
{
rotation -= rotationSpeed;
}
if (Input::Hold(Button::DOWN))
{
rotation -= rotationSpeed;
}
if (Input::Hold(Button::RIGHT))
{
rotation += rotationSpeed;
}
Card.Rotate(rotation);
Background.Rotate(-rotation);
if (Input::Press(Button::SPACE))
{
Sprite temp;
temp.SetTexture(bulletTex);
temp.Rotate(rotation);
temp.SetPosition((Card.GetX()+(Card.GetWidth()*0.5 - temp.GetWidth()*0.5)), (Card.GetY()+(Card.GetHeight()*0.5 - temp.GetHeight()*0.5)));
bullets.push_back(temp);
}
if (chipScale >= 1.0251f)
grow = false;
if (chipScale <= 0.975f)
grow = true;
if (grow)
{
//.........这里部分代码省略.........