Exemplo n.º 1
0
 void SpriteFont::draw(SpriteBatch& batch, const char* s, glm::vec2 position, glm::vec2 scaling, 
                       float depth, ColorRGBA8 tint, Justification just /* = Justification::LEFT */) {
     glm::vec2 tp = position;
     // Apply justification
     if (just == Justification::MIDDLE) {
         tp.x -= measure(s).x * scaling.x / 2;
     } else if (just == Justification::RIGHT) {
         tp.x -= measure(s).x * scaling.x;
     }
     for (int si = 0; s[si] != 0; si++) {
         char c = s[si];
         if (s[si] == '\n') {
             tp.y += _fontHeight * scaling.y;
             tp.x = position.x;
         } else {
             // Check for correct glyph
             int gi = c - _regStart;
             if (gi < 0 || gi >= _regLength)
                 gi = _regLength;
             glm::vec4 destRect(tp, _glyphs[gi].size * scaling);
             batch.Draw(destRect, _glyphs[gi].uvRect, _texID, depth, tint);
             tp.x += _glyphs[gi].size.x * scaling.x;
         }
     }
 }
void RagdollCharacter::Draw(SpriteBatch& _spriteBatch) {
	// Loop through and draw the bodies
	for (int i = 0; i < bodies.size(); i++) {
		b2Vec2 positionMetres = GetBody(i)->GetPosition();
		float widthMetres = 0.5F, heightMetres = 0.5F;
		// Scale it to 100 pixels per metre
		if (GetBody(i)->GetFixtureList()->GetShape()->GetType() == b2Shape::e_circle)
		{
			widthMetres = GetBody(i)->GetFixtureList()->GetShape()->m_radius * 2;
			heightMetres = GetBody(i)->GetFixtureList()->GetShape()->m_radius * 2;

			glm::vec4 destRect(positionMetres.x * 100, positionMetres.y * 100, widthMetres * 100, heightMetres * 100);
			glm::vec4 uv(0.0F, 0.0F, 1.0F, 1.0F);
			Color color;

			_spriteBatch.Draw(destRect, uv, headTexture.id, 0.0F, GetBody(i)->GetAngle(), color);
			_spriteBatch.Draw(destRect, uv, headHappyTexture.id, 0.0F, GetBody(i)->GetAngle(), color);
		}

		else if(GetBody(i)-> GetFixtureList()->GetShape()->GetType() == b2Shape::e_polygon)
		{
			b2PolygonShape* shape = (b2PolygonShape*)GetBody(i)->GetFixtureList()->GetShape();

			widthMetres = shape->GetVertex(0).x * 2;
			heightMetres = shape->GetVertex(0).y * 2;

			glm::vec4 destRect(positionMetres.x * 100, positionMetres.y * 100, widthMetres * 100, heightMetres * 100);
			glm::vec4 uv(0.0F, 0.0F, 1.0F, 1.0F);
			Color color;

			_spriteBatch.Draw(destRect, uv, boxTexture.id, 0.0F, GetBody(i)->GetAngle(), color);
		}


	}
}
Exemplo n.º 3
0
	virtual void Draw() override
	{
		GetGraphicsDevice().Clear(Color4::White);
		spriteBatch.Begin(BlendState::AlphaBlend);

		for (int i = 0; i < blipCount; i++)
		{
			spriteBatch.Draw(ball, blips[i], scale, origin);
		}

		theta += 0.01f;

		Game::Draw();
		spriteBatch.End();
	}
Exemplo n.º 4
0
void ListBox::Draw( SpriteBatch& spriteBatch, SpriteBatch& spriteBatchFont )
{
	if (!mVisible)
		return;

	int2 screenPos = GetScreenPosition();

	float zOrder = GetDepthLayer();

	// Draw background first
	Rectanglef backRC((float)screenPos.X(), (float)screenPos.Y(), (float)mSize.X(), (float)mSize.Y());
	mLisBoxStyle->DrawNinePatch(spriteBatch, UI_State_Normal, backRC, zOrder);

	if (mItems.size())
	{
		int mimItem, maxItem;
		mVertScrollBar->GetScrollRange(&mimItem, &maxItem);

		Rectanglef rc((float)mTextRegion.X, (float)mTextRegion.Y, (float)mTextRegion.Width, (float)mTextRegion.Height);
		rc.SetBottom( rc.Y + mTextRowHeight);

		for (int i = mVertScrollBar->GetScrollValue(); i < maxItem + mNumVisibleItems; ++i)
		{		
			if (rc.Bottom() > (float)mTextRegion.Bottom())
				break;

			if( i == mSelectedIndex )
			{
				// Draw selected highlight
				Rectanglef rcSel;

				rcSel.SetLeft(mSelectionRegion.Left()+1);
				rcSel.SetRight(mSelectionRegion.Right());
				rcSel.SetTop((float)rc.Top());
				rcSel.SetBottom((float)rc.Bottom());
				
				spriteBatch.Draw(mLisBoxStyle->StyleTex, rcSel, &mLisBoxStyle->StyleStates[UI_State_Hover].TexRegion,
					mLisBoxStyle->StyleStates[UI_State_Hover].TexColor, zOrder);
			}

			// draw text
			//Rectanglef region((float)rc.X, (float)rc.Y, (float)rc.Width, (float)rc.Height);
			mLisBoxStyle->Font->DrawString(spriteBatchFont, mItems[i], mLisBoxStyle->FontSize, AlignVCenter, rc, mLisBoxStyle->ForeColor, zOrder);

			rc.Offset(0, mTextRowHeight);
		}
	}
}
Exemplo n.º 5
0
void TopLayer::Draw(const GameTime& gameTime, SpriteBatch& spriteBatch) {
	
	Point cameraPt = Camera2D::getCell();
	
	Point viewPt = Point::toCell((Vector2) {
		Camera2D::getPosition().x + Camera2D::getViewPort().width,
		Camera2D::getPosition().y + Camera2D::getViewPort().height
	});
	
	Point min = (Point) {
		std::max((ChunkLength - 1) * _cellPosition.x, cameraPt.x - 1),
		std::max((ChunkLength - 1) * _cellPosition.y , cameraPt.y - 1)
	};
	Point max = (Point) {
		std::min(viewPt.x + 1, (ChunkLength - 1) * (_cellPosition.x + 1)),
		std::min(viewPt.y + 1, (ChunkLength - 1) * (_cellPosition.y + 1))
	};

	// if(max.x <= 0 || max.y <= 0 || min.x >= ChunkLength || min.y >= ChunkLength)
	// return;
	
	Tile tile;
	Rectangle destination = (Rectangle) {0, 0, TileLength, TileLength};
	
	for(register int y = min.y; y < max.y; y++) {
		
		for(register int x = min.x; x < max.x; x++) {
			
			tile = getTile(x - (ChunkLength - 1) * _cellPosition.x, y - (ChunkLength - 1) * _cellPosition.y);
			
			
			
			if(tile.getTileSet() == -1 || tile.getIndex() == -1)
				continue;
			
			destination.x = x * TileLength;
			destination.y = y * TileLength;
			
			spriteBatch.Draw(
				*((_tileSets.get() + tile.getTileSet())->getTexture()),
				(_tileSets.get() + tile.getTileSet())->getSourceRec(tile.getIndex()),
				destination, (Vector2){0.0f, 0.0f}, 0.0f, WHITE);
		}
		
	}
	
}
Exemplo n.º 6
0
void Sprite::Draw(SpriteBatch& batch)
{
	batch.Draw(*this);
}