Exemple #1
0
// Constructor
ParallaxLayer::ParallaxLayer(const sf::Image &img, float factor_x, bool repeat_x, float offset_x, float factor_y, bool repeat_y, float offset_y){
	SetImage(img);
	
	// calculamos el ancho y alto de la imagen, esto
	// nos va a servir para evitar desbordes en el desplazamiento
	ancho_img=img.GetWidth();
	alto_img=img.GetHeight();
	
	// inicializamos las variables internas
	despl_x=despl_y=0;
	this->factor_x=factor_x;
	this->factor_y=factor_y;
	this->repeat_x=repeat_x;
	this->repeat_y=repeat_y;
	this->offset_x=offset_x;
	this->offset_y=offset_y;

	// seleccionamos la textura y habilitamos la repeticion
	// segun corresponda
	img.Bind();
	if(repeat_x)
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	if(repeat_y)
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	
	// ajustamos la posicion de la capa
	Sprite::SetPosition(offset_x, offset_y);
	SetScale(0.5,0.5);
}