Пример #1
0
void Renderer_renderTile(TileComponent* tileComponent, Layer* layer)
{
	if (tileComponent->getTileset() != 0)
	{
		GameObject* gameObject = tileComponent->getGameObject();

		vec2 position = layer->getMap()->tileToDeviceCoordinates(gameObject->getPosition().x, gameObject->getPosition().y);
		tileComponent->getSprite()->setDepth(layer->getDepth());
		tileComponent->getSprite()->setOpacity(layer->getOpacity());
		Tileset* tileset = tileComponent->getTileset();

		Sprite::PixelClip clip = tileset->getSpriteSheet()->getClip(tileComponent->getTileId());
		Texture* tex = tileset->getSpriteSheet()->getTexture();
		tileComponent->getSprite()->setClip(float(tex->getWidth()), float(tex->getHeight()), clip);

		vec2 scale(1.0f);
		if (tileComponent->isFlippedHorizontally())
		{
			scale.x *= -1.0f;
		}

		if (tileComponent->isFlippedVertically())
		{
			scale.y *= -1.0f;
		}

		vec2 p = position;
		//p.x += clip.clipSize.x*0.5f;
		p.y += clip.clipSize.y*0.5f;
		p.x += layer->getMap()->getTileWidth();// *0.5f;
	//	p.x -= 1.5f;
		p.y -= layer->getMap()->getTileHeight();// *0.5f;
		p.x -= tileset->getTileOffsetX();
		p.y -= tileset->getTileOffsetY();

		p.y += layer->getMap()->getTileWidth() * 0.5f;
		p.x -= layer->getMap()->getTileWidth() * 1.0f;

		if (gameObject->getName() == "Ball")
		{
			int i = 0;
			i;
		}

		layer->getBatch()->addSprite(tex, tileComponent->getSprite(), p, gameObject->getRotation(), scale, vec2(0,0));
	}
}
Пример #2
0
void Tile::render(Layer* layer)
{
	if( getTileset() != 0 )
	{
		vec2 position = layer->getMap()->tileToDeviceCoordinates(getPosition().x,getPosition().y);
		m_sprite->setDepth( layer->getDepth() );
		m_sprite->setOpacity( layer->getOpacity() );
		Tileset* tileset = getTileset();

		Sprite::PixelClip clip = tileset->getSpriteSheet()->getClip(getTileId());
		Texture* tex = tileset->getSpriteSheet()->getTexture();
		m_sprite->setClip(float(tex->getWidth()), float(tex->getHeight()), clip);

		vec2 scale(1.0f);
		if( isFlippedHorizontally() )
		{
			scale.x *= -1.0f;
		}

		if( isFlippedVertically() )
		{
			scale.y *= -1.0f;
		}

		vec2 p = position;
		p.x += clip.clipSize.x*0.5f;
		p.y += clip.clipSize.y*0.5f;
		p.x -= layer->getMap()->getTileWidth()*0.5f;
		p.y -= layer->getMap()->getTileHeight()*0.5f;
		p.x -= tileset->getTileOffsetX();
		p.y -= tileset->getTileOffsetY();

		vec2 offset(0.0f);

		layer->getBatch()->addSprite( tex, m_sprite, p, 0, scale );
	}
}