Skip to main content
gamedev.net
🔒 Locked

SDL/CPP Basic Move Towards Point Help?

Started by kc_0045 0 replies 800+ views
Original Post
kc_0045
kc_0045
So yeah, this should be simple but idk it just isnt working, im stumped. Trying to get LastDrawnx and LastDrawny to smoothly follow Mousex,Mousey so when ondraw is called it draws it smoothly. (for drawing a line) The code below would be in a while loop with something like while(dis>1) so it loops till it gets close(incase of fast mouse movement causing effects to look weird.) mOffsetx=Mousex-LastDrawnx; mOffsety=Mousey-LastDrawny; float fx=(float)mOffsetx; float fy=(float)mOffsety; float legth =sqrt( (fx*fx) + (fy*fx) ); if(((int)legth)!=0) { mOffsetx/=(int)legth; mOffsety/=(int)legth; } LastDrawnx+=mOffsetx; LastDrawny+=mOffsety; CSurface::OnDraw(Surf_Display, Surf_Brush, LastDrawnx,LastDrawny); it sorta gets to the mouse....but it acts all random and doesnt follow a pattern to my mouse.
gzboli
gzboli
You have a typo where an 'x' should be a 'y'.

Also, to have this line animate you will need to draw each iteration over multiple frames... Unless OnDraw is doing something magical I don't know about.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.