Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Iloveolaf

Pages: [1]
1
Graphics / Re: How to move a sprite in a fixed range?
« on: January 06, 2020, 01:30:07 am »
Thanks I'll try!

2
Graphics / How to move a sprite in a fixed range?
« on: January 05, 2020, 05:39:43 am »
I'm not a native English speaker, so sorry for my poor English in advance. :'(

I want to move a sprite, where it's y-coordinate will go from 0 to 352 and from 352 to 0 repeatedly.

But I don't know how to write it.

This is my code now. And it'll like from 0 to 352 go back to 0 and from 0 to 352.

Code: [Select]
int main(){

while (window.isOpen()) {

                sprite.move(0.f, 0.0001f * elapsed.asMicroseconds());
                clock.restart();
                if (sprite.getPosition().y >= 352) {
                     do {
                          sprite.move(0.f, -0.0001f * elapsed.asMicroseconds());
                          clock.restart();
                     } while (sprite.getPosition().y >= 0);
                }
window.draw(sprite);
window.display();
}
}

Can anyone give me some tips how to write it? Thanks!

Pages: [1]
anything