{"id":5491,"date":"2024-12-31T16:40:13","date_gmt":"2024-12-31T16:40:13","guid":{"rendered":"https:\/\/obsidiansofteducation.com\/?page_id=5491"},"modified":"2026-01-18T17:21:04","modified_gmt":"2026-01-18T17:21:04","slug":"basketball-game-in-mit-app-inventor","status":"publish","type":"page","link":"https:\/\/obsidiansofteducation.com\/index.php\/basketball-game-in-mit-app-inventor\/","title":{"rendered":"Basketball game in MIT App Inventor"},"content":{"rendered":"\n<p class=\"has-medium-font-size wp-block-paragraph\">Hello friends,<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Welcome to Obsidian Soft.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">I will teach you how to make a cool but easy basketball game in MIT app Inventor in this tutorial.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/snake20game2023.png\" alt=\"\"\/><\/figure>\n<\/div>\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Open up MIT App Inventor, start a new project, and name it BasketBall.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">For screen 1 make align horizontal and align vertical both centre. Upload a basket court image with baskets in vertical form.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\"><a href=\"https:\/\/vectorportal.com\/download-vector\/basketball-court\/22916\" target=\"_blank\" rel=\"noopener\">https:\/\/vectorportal.com\/download-vector\/basketball-court\/22916<\/a><\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">I will give the link in the video description.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Drag and drop a canvas from Drawing and Animation. Make height and width 95 percent. Choose the court image as the background. Make the paint color white as we will write the score on our canvas too.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Drag and drop two ball sprites from Drawing and Animation onto the canvas. Rename one to ball and the other one to basket. Make the ball\u2019s radius 13 and the interval after it moves 50. This is in milliseconds. Make the ball color dark orange like a real basketball.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">For the basket, make the radius a bit smaller at 10. Give it a color similar to the background and make it almost transparent by going to custom and increasing transparency. We will give both sprites their positions on Canvas programmatically in the blocks section.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Also, add a clock sensor from Sensors.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">And make timer interval 200. The timer should be enabled and the timer should always fire.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Our screen design is done so go to the blocks section.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Get ball\u2019s getFlung event.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Set ball speed to speed x7 and set heading to heading. And remember that we have already set the interval to 50 ms in designer\u2019s view in the ball\u2019s properties.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/zZ7SbHUHKMNtqURWPDtYUhpA38WYC29TTmybY5AMO9g1H2YQUC1D14xach5F8ptieWWiN2o8cX7L4WEpSxLHj0R88GwReJQX6aBV07skRaZZ0YUcMiQHY1HfOt7zG4gQZxCKmGOIVIvjt7tROE3i2mcw640-h174.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">When the clock timer fires, we will set our basket position to be on top of the actual basket in our canvas background image. You must be wondering why we aren\u2019t doing it in the screen initialize event and why in a clock timer event. I have noticed that in iPhone, any initialization using screen properties such as screen height or width doesn\u2019t work properly in the screen initialize event so it is better to do such kind of work with a tiny delay so our clock runs after 200 ms and when the timer goes off, we set our basket position.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/fOHe6JtHk4wG7CrGzHrngeOfiZxGhP7EGgPJOo5xMoT7Ip1DIi9_ZlD1zOdHGMp49xUnBAgxl1N4t43yr9KC5uPP6yCoZjQW10AAbFyLBHONWMN7mghnifKBBLzVZK7hHekMg8WiTC6mlDIQWccLi_kw640-h126.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">We will also disable the timer so that the timer doesn\u2019t keep on firing.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Next, what happens when something collides with our almost invisible basket, it is obviously the ball as that is the only thing that can move on our canvas. So, we should increase our score but also reset our ball to its original position. Let\u2019s first make a procedure for resetting the ball to go to a starting position.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/Xj9YxASfEsgZzMIKN3AuuTK3lzDgNSWQ8q5v0Zm8hMd6HlQCP878QkiyAjM44BT_Htv495sPkh5gqzNJza5MjJpVIoex_zaWfyvQGGZdTgjuhKD9D2cSnnQxvsCTuymd2hPBYzRq7ELzPk0FtDotMWUw640-h144.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Also, make a global variable score.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/yccTd3tHdVwhOi5uhTjDw8aC_bCAgvNCtWjbd4l8LbKxdEuiSvpfLDjkHfbFqhfA-HMPmotrztCT19dzjkRpTlf-j7vaQEvym2bgISVZ-Rrlf90vRencpLAgQUD1dcnM5759ehr7DVEAoDlTS29dXbUw574-h67.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Next, get the collided event for the basket. If the basket is colliding with the ball, then call procedure resetBall, clear the canvas so the previously written score is removed, set the new score, and draw it as text on canvas.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/FsqZQ1NhYalNI6v0FgMqhhROGEYyPyMX6YVfsJ_Y4oyVyxnicUVA5IddEZp1gKZrZOx8agL3ab3ywEUCANw5IRvbTHSMR0X97hwlOoGpRhvmzx8Bdyxjs4CkHGVclcj9qdKzY7g_MiVysS-joZE2Vk0w640-h421.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">We should also reset the ball in two other events.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">When the screen is initialized:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/6LcRYK4xRS0Sv8Rwx7VbGBBkBcroRCsQzS1bYh9N4W_2tsGMOSgN0Aosu4wpRsqNZZmlFTJsrBBK1ok4w1rM0uQgXzgZezrGArLY9S-7Qko9aPGOOClChX7nb5vZrEuYW9hI2pofd-M-djGopcXnAzw.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">When the ball hits the top and bottom edge. So, get the ball edge reached event.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/QRIZi05Faf0OK5aqkb7VdEaBzIyQBICG6uTzN0L1oNGu8_BVVSQf2J6IxtJOn2VVUSjH9Wz-cvOHc8KCDmxdaSvhFNTyyu5LddU9bEz_e_IDUhstkXB0v2BHsmk-GI7Ng-8nbZa0__S-QAh_S4I4P-Yw640-h217.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">For other edges i.e. left and right just let the ball bounce.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">This is done. I hope you have fun making this simple but cool basketball game in MIT App Inventor.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Thank you for reading this tutorial. <\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">If you like my tutorials, consider supporting me:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter is-resized\"><a href=\"https:\/\/obsidiansoft.gumroad.com\/l\/cxdft\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"372\" height=\"196\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/donate-button-1.png\" alt=\"\" class=\"wp-image-5381\" style=\"width:227px;height:auto\" srcset=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/donate-button-1.png 372w, https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/donate-button-1-300x158.png 300w\" sizes=\"auto, (max-width: 372px) 100vw, 372px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">You can download aia file for this project:<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\"><a href=\"https:\/\/drive.google.com\/file\/d\/1lfryhy9Sy4z0s9IQ4tPlny6wvjPAeKxB\/view?usp=sharing\" target=\"_blank\" rel=\"noopener\">Basketball game aia file<\/a><\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">You can have a look at the video tutorial for the Basketball game app here:<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<p class=\"responsive-video-wrap clr\"><iframe loading=\"lazy\" title=\"Basketball Game in MIT App Inventor | App Inventor Basketball Game | #appinventor #mitappinventor\" width=\"1200\" height=\"675\" src=\"https:\/\/www.youtube.com\/embed\/VBrZXKKb2AM?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<\/div><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Please like my videos and share them with your friends and family. Also, subscribe to my channel and press the bell icon so you don\u2019t miss any of the great projects I have planned for you.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\"><a href=\"https:\/\/www.youtube.com\/c\/obsidiansofteducation\" target=\"_blank\" rel=\"noopener\">https:\/\/www.youtube.com\/c\/obsidiansofteducation<\/a><\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Please like my Facebook page and Instagram page for more educational resources and tips.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Facebook:<a href=\"https:\/\/www.blogger.com\/blog\/page\/edit\/4947000819484484884\/7140650632339107612#\" target=\"_blank\" rel=\"noopener\">&nbsp;https:\/\/www.facebook.com\/ObsidianSoft\/<\/a><\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Instagram:<a href=\"https:\/\/www.blogger.com\/blog\/page\/edit\/4947000819484484884\/7140650632339107612#\" target=\"_blank\" rel=\"noopener\">&nbsp;https:\/\/www.instagram.com\/obsidiansoftapps\/<\/a><\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Pinterest:<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\"><a href=\"https:\/\/www.pinterest.co.uk\/obsidiansoft\/_created\" target=\"_blank\" rel=\"noopener\">https:\/\/www.pinterest.co.uk\/obsidiansoft\/_created<\/a><\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">For links to free educational apps, have a look at the&nbsp;<a href=\"https:\/\/obsidiansofteducation.com\/index.php\/mobile-apps\/\">educational apps page<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello friends, Welcome to Obsidian Soft. I will teach you how to make a cool but easy basketball game in MIT app Inventor in this tutorial. Open up MIT App Inventor, start a new project, and name it BasketBall. For screen 1 make align horizontal and align vertical both centre. Upload a basket court image [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-5491","page","type-page","status-publish","hentry","entry"],"_links":{"self":[{"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/pages\/5491","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/comments?post=5491"}],"version-history":[{"count":2,"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/pages\/5491\/revisions"}],"predecessor-version":[{"id":6866,"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/pages\/5491\/revisions\/6866"}],"wp:attachment":[{"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/media?parent=5491"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}