Why using clearRect , previous image isn't getting completely cleared? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Why using clearRect , previous image isn't getting completely cleared?

So when bird Hits rectangle ,from Bird class fall_down function is called which in turn calls render function where all the clearing and rotating is happening https://code.sololearn.com/WcBQHr95syMW/?ref=app

9th Aug 2020, 11:52 AM
Abhay
Abhay - avatar
2 Answers
+ 1
I hope you don't mind me suggesting improvements. It's probably a case where you update the position of the bird before clearing but it's hard to tell. You should only have one function that deals with all the drawing, and which clears the whole screen once too. Also only one render function per object, so the pull_down function I would try to remove. If we are smart about how we calculate positions we can clean up most of your positioning logic, so let me teach you about euler integration :) https://code.sololearn.com/WWvM5cJ2Xkes/?ref=app Basically every object stores a position, and a velocity, and acceleration. And you update it on every time step. This way you don't need a pull_down function, gravity just takes care of it. Your rectangle class could use the same code but it probably shouldn't respond to gravity.
9th Aug 2020, 1:06 PM
Schindlabua
Schindlabua - avatar
+ 1
Schindlabua I am up for any suggestion or improvements ,thank you very much:-) ,tho I don't really like physics ,I will take into account the following method and try to apply it in near feature .Also pull down function is just increasing position by 1 ,and I don't really get why should i include velocity and acceleration for such a basic thing ,it might be useful in like making collision look real and all other bouncy things but I am not at that level for sure , And fall down function can be replaced easily by render which is rotating the object leaving only one ,pull down .
9th Aug 2020, 7:26 PM
Abhay
Abhay - avatar