Jump to content
• What is your GameDev Story?

• Advertisement

Public Group

moving 2D image.....

This topic is 3956 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi friends, I have stuck for this problem for 2 whole day, decided to find it on Google, then found this community here. Let's say, I create a 2D polygon image, and I want to move it around in my windows screen. Yes, I have successfully make it move by using its vector, but what I want is, the 2D image will go to other direction after its reach the edge of the screen, and move on, and after its reach at another edge, it will change it direction again and again, so its appear move around on the windows only. May I have some basic Idea on how to do this. Only the basic idea or suggestion on how to do this. Thanks.

Share this post

Share on other sites
Advertisement
Well use a Ai idea this is hypothetical and places an idea of logic
For you to work with.

First example
Action 1
Action-patrol
Action on activation go to action
action 2
Action 2
Action-move to target
Action-attack
Action - if targets lost go to action
Action-action 1
So in logic you know the directive and also the sub directive if
Directive fails
Put it to your work
Action1
Action -move curser up
Action-if contact boundary 1 go to action
Action-action 2
Action 2
Action-move curser down
Action-if contact boundary 2 go to action
Action-action 1
So by stipulating a bounding box as a hole or in 4 segments you are able to control direction threw action
He he I hope that was an exciting way to make some thing simple sound complex

Share this post

Share on other sites
Thanks, and hey!...you are successfully make it complicated..:D, let me digest it first while waiting for the next solution....:D

Share this post

Share on other sites
Do you want your 2D object to rotate? If so, that would be a little more complicated.

If you don't want it to rotate, check your leftmost point against the left of the screen ( probably 0 ) If your left most point is off the screen, then move your object back to the right by this much, and negate (0-x) the X component of your movement vector.

Do this for all the other sides.

Share this post

Share on other sites
You could inverse the velocity vector. VelVec.x *= -1; VelVec.y *= -1;
if you mean that it should warp around the screen, you just have to change its position vector.

if(PosVec.x > SCREEN_WIDTH)
PosVec.x = 0;

Share this post

Share on other sites

• Advertisement
• Advertisement
• What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• Popular Now

• 10
• 15
• 14
• 46
• 22
• Advertisement
• Forum Statistics

• Total Topics
634054
• Total Posts
3015269
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!