say I have a screen (0,0,100,100)
I have sprite at point (50, 50)
How can I move the sprite to position (75, 25) over time.
So what I came up with was this:
[source c++]/*Square is a structure that holds information about a specific area of pixels.The variables used:Square* oldSquare; t= top l= left (x,y)Square* atSquare;Square* newSquare;bool isMoving;*/// Creates the function to move the game object.void GameObject::move(float ElapsedTime){ //sets the last position to the current position. this->oldSquare = this->atSquare; if(this->isMoving = true) { if(this->atSquare->t != this->newSquare->t) { if(this->atSquare->t > this->newSquare->t) { std::cout << "Move by " << ((this->atSquare->t - this->newSquare->t)/2) * ElapsedTime << std::endl; Sprite.Move(((this->atSquare->t - this->newSquare->t)/2) * ElapsedTime, 0); } if(this->atSquare->t < this->newSquare->t) { std::cout << "Move by " << ((this->atSquare->t - this->newSquare->t)/2) * ElapsedTime << std::endl; Sprite.Move(0, ((this->atSquare->t - (this->atSquare->t - this->newSquare->t))/2) * ElapsedTime); } } else{this->isMoving = false;} if(this->atSquare->l != this->newSquare->l) { if(this->atSquare->l > this->newSquare->l) { std::cout << "Move by " << ((this->atSquare->l - this->newSquare->l)/2) * ElapsedTime << std::endl; Sprite.Move(((this->atSquare->l - this->newSquare->l)/2) * ElapsedTime, 0); } if(this->atSquare->l < this->newSquare->l) { std::cout << "Move by " << ((this->atSquare->l - this->newSquare->l)/2) * ElapsedTime << std::endl; Sprite.Move(0,((this->atSquare->l - (this->atSquare->l - this->newSquare->l))/2) * ElapsedTime); } } else { this->isMoving = false; } }}
The problem is that this doesn't work. It only makes the square go in one direction; in this case, straight down.