Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / Sprite Reverse Direction at Edge of Screen

Author
Message
VOLTaire
11
Years of Service
User Offline
Joined: 7th Nov 2011
Location:
Posted: 7th Nov 2011 23:42 Edited at: 8th Nov 2011 16:59
My instructor wants us to make two sprites bounce around the screen. They need to reverse directions when they reach the edge of the screen, and reset to a random position if they hit eachother.

I've gotten it to work, but if I change the Xvel or Yvel to anything else the ships will unpredictably fly off the screen after a bounce or two. It's weird. My ships have to move really slow because of this limitation. Any help is appreciated. Thx.


afaik
12
Years of Service
User Offline
Joined: 12th Jun 2010
Location: NYC
Posted: 11th Nov 2011 06:19


I bumped up the speeds up to 10 and -10 since it sometimes takes a while for a collision to take place and it looks like it works fine. I'm assuming that if you stick with ==, you'll miss the true values of the transformers if they are moving more than one pixel at a time. By using <= and >=, you'll catch your image if it jumps over the boundaries and set it to move in the right direction.

Login to post a reply

Server time is: 2022-12-05 05:24:19
Your offset time is: 2022-12-05 05:24:19