gameEngine/gameEngine/Sprite.cpp
//called every cycle as long sprite is active, sets position and center based on dx and dy. Check bounds
called every cycle as long sprite is active, sets position and center based on dx and dy. Check bounds
called every cycle as long sprite is active sets position and center based on dx and dy . Check bounds
void Sprite::Update()
{
	this->Position.x += this->Velocity.x;
	this->Position.y -= this->Velocity.y;
	this->Center.x += this->Velocity.x;
	this->Center.y -= this->Velocity.y;
	glm::vec2 diffPos = glm::vec2(0);
	glm::vec2 diffSize = glm::vec2(0);
	bool change = false;
	if (Position != lastPosition)
	{
		diffPos = Position - lastPosition;
		change = true;
	}
	if (Size != lastSize)
	{
		diffSize = Size - lastSize;
		this->Position.x = this->Center.x - this->Size.x / 2;
		this->Position.y = this->Center.y - this->Size.y / 2;
		change = true;
	}
	if (change)
	{
		for (int i = 0; i < colliders_.size(); i++)
		{
			colliders_[i]->changePositionBy(diffPos);
			colliders_[i]->setSize(colliders_.at(i)->getSize() + diffSize);
		}
		for (int i = 0; i < children.size(); i++)
		{
			children[i]->changePositionBy(diffPos);
			children[i]->setSize(children.at(i)->getSize() + diffSize);
		}
	}
	lastPosition = Position;
}
void Sprite :: Update ( ) { this -> Position . x += this -> Velocity . x ; this -> Position . y -= this -> Velocity . y ; this -> Center . x += this -> Velocity . x ; this -> Center . y -= this -> Velocity . y ; glm :: vec2 diffPos = glm :: vec2 ( 0 ) ; glm :: vec2 diffSize = glm :: vec2 ( 0 ) ; bool change = false ; if ( Position != lastPosition ) { diffPos = Position - lastPosition ; change = true ; } if ( Size != lastSize ) { diffSize = Size - lastSize ; this -> Position . x = this -> Center . x - this -> Size . x / 2 ; this -> Position . y = this -> Center . y - this -> Size . y / 2 ; change = true ; } if ( change ) { for ( int i = 0 ; i < colliders_ . size ( ) ; i ++ ) { colliders_ [ i ] -> changePositionBy ( diffPos ) ; colliders_ [ i ] -> setSize ( colliders_ . at ( i ) -> getSize ( ) + diffSize ) ; } for ( int i = 0 ; i < children . size ( ) ; i ++ ) { children [ i ] -> changePositionBy ( diffPos ) ; children [ i ] -> setSize ( children . at ( i ) -> getSize ( ) + diffSize ) ; } } lastPosition = Position ; }
called every cycle as long sprite is active, sets position and center based on dx and dy.
called every cycle as long sprite is active sets position and center based on dx and dy .
//update Center //we need to recalc center