{"id":4765,"date":"2020-01-11T07:43:38","date_gmt":"2020-01-11T06:43:38","guid":{"rendered":"https:\/\/pythonprogramming.altervista.org\/?p=4765"},"modified":"2021-12-07T06:13:59","modified_gmt":"2021-12-07T05:13:59","slug":"pygame-sprite-animation-update","status":"publish","type":"post","link":"https:\/\/pythonprogramming.altervista.org\/pygame-sprite-animation-update\/","title":{"rendered":"Pygame Sprite Animation update"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">With this code you can animate this png files (<a href=\"https:\/\/www.gameart2d.com\/uploads\/3\/0\/9\/1\/30917885\/flatboy.zip\">go here to download them<\/a>).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">How to <strong>animate<\/strong> in different actions a sprite in <strong>pygame<\/strong>. It could seem a little tricky, but with the help of a class and the superclass <strong>Sprite<\/strong> and the <strong>Group<\/strong> class, we can manage the animation quite nicely with <strong>Python<\/strong> and <strong>Pygame<\/strong>, in this episode of the serie for the making of a platform game in Python&#8230;<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2020\/01\/Run-10.png\"><img loading=\"lazy\" decoding=\"async\" width=\"614\" height=\"564\" src=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2020\/01\/Run-10.png\" alt=\"\" class=\"wp-image-4776\" srcset=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2020\/01\/Run-10.png 614w, https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2020\/01\/Run-10-320x294.png 320w\" sizes=\"auto, (max-width: 614px) 100vw, 614px\" \/><\/a><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2020\/01\/Run-11.png\"><img loading=\"lazy\" decoding=\"async\" width=\"614\" height=\"564\" src=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2020\/01\/Run-11.png\" alt=\"\" class=\"wp-image-4777\" srcset=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2020\/01\/Run-11.png 614w, https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2020\/01\/Run-11-320x294.png 320w\" sizes=\"auto, (max-width: 614px) 100vw, 614px\" \/><\/a><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2020\/01\/Run-12.png\"><img loading=\"lazy\" decoding=\"async\" width=\"614\" height=\"564\" src=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2020\/01\/Run-12.png\" alt=\"\" class=\"wp-image-4778\" srcset=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2020\/01\/Run-12.png 614w, https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2020\/01\/Run-12-320x294.png 320w\" sizes=\"auto, (max-width: 614px) 100vw, 614px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Put the extracted <strong>images<\/strong> in a folder called &#8220;<strong>png&#8221;<\/strong> in the folder where this code is.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"right-order-of-the-images\">Right order of the images<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">As the images that ends with 10, 11, 12 ecc. would be positioned after image 1 and before image 2, I used this &#8216;trick&#8217; to load the images from 1 to 9 first, then images 10 to&#8230; in a second list, so that they were displayed in the right sequence, with this code:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">        im = glob.glob(f\"png\\\\{action}*.png\")\n        lenim = len(im[0])\n        self.images = [pygame.image.load(img) for img in glob.glob(f\"png\\\\{action}*.png\") if len(img) == lenim]\n        self.images2 = [pygame.image.load(img) for img in glob.glob(f\"png\\\\{action}*.png\") if len(img) &gt; lenim]\n        self.images.extend(self.images2)<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">As you can see, I get the lenght of the first image (the one with the number 1) that is shorter than the ones with 10, 11&#8230; in the name. So I load these first and then the ones with the longer names. At the end I join them in one list of images with <strong>extend<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"the-whole-code\">The whole code<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">import pygame\nimport glob\n \nSIZE = WIDTH, HEIGHT = 600, 600 #the width and height of our screen\nFPS = 20 #Frames per second\n \nclass MySprite(pygame.sprite.Sprite):\n    def __init__(self, action):\n        super(MySprite, self).__init__()\n        im = glob.glob(f\"png\\\\{action}*.png\")\n        lenim = len(im[0])\n        self.images = [pygame.image.load(img) for img in glob.glob(f\"png\\\\{action}*.png\") if len(img) == lenim]\n        self.images2 = [pygame.image.load(img) for img in glob.glob(f\"png\\\\{action}*.png\") if len(img) &gt; lenim]\n        self.images.extend(self.images2)\n        self.index = 0\n        self.rect = pygame.Rect(5, 5, 150, 198)\n\n    def update(self):\n        if self.index &gt;= len(self.images):\n            self.index = 0\n        self.image = self.images[self.index]\n        self.index += 1\n\ndef action(action):\n    my_sprite = MySprite(action)\n    my_group = pygame.sprite.Group(my_sprite)\n    return my_group\n\ndef main():\n    pygame.init()\n    screen = pygame.display.set_mode(SIZE)\n    pygame.display.set_caption(\"Press i w r j d or arrows and space\")\n    my_sprite = MySprite(\"idle\")\n    my_group = pygame.sprite.Group(my_sprite)\n    clock = pygame.time.Clock()\n    loop = 1\n    while loop:\n        for event in pygame.event.get():\n            if event.type == pygame.QUIT:\n                loop = 0\n            if event.type == pygame.KEYDOWN:\n                if event.key == pygame.K_w or event.key == pygame.K_LEFT:\n                    my_group = action(\"walk\")\n                if event.key == pygame.K_d:\n                    my_group = action(\"dead\")                \n                if event.key == pygame.K_j or event.key == pygame.K_UP:\n                    my_group = action(\"jump\")\n                if event.key == pygame.K_i or event.key == pygame.K_SPACE:\n                    my_group = action(\"idle\")\n                if event.key == pygame.K_r or event.key == pygame.K_RIGHT:\n                    my_group = action(\"run\")\n                if event.key == pygame.K_d or event.key == pygame.K_DOWN:\n                    my_group = action(\"dead\")\n\n \n        my_group.update()\n        screen.fill((0,0,0))\n        my_group.draw(screen)\n        pygame.display.update()\n        clock.tick(FPS)\n    pygame.quit()\n \nif __name__ == '__main__':\n    main()<\/pre>\n\n\n<div style=\"width: 600px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-4765-1\" width=\"600\" height=\"600\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2020\/01\/animation_2.mp4?_=1\" \/><a href=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2020\/01\/animation_2.mp4\">https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2020\/01\/animation_2.mp4<\/a><\/video><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"live-coding-video-about-sprite-animation-in-pygame\">Live coding video about sprite animation in Pygame<\/h2>\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<iframe loading=\"lazy\" title=\"Pygame Sprite Animation (for platform game)\" width=\"747\" height=\"420\" src=\"https:\/\/www.youtube.com\/embed\/dpzCe8NZLTY?feature=oembed&amp;enablejsapi=1\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n\n<\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"a-more-efficient-code-use-this-one\">A more efficient code&#8230; Use this one&#8230;<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If you want to use the code to animate a sprite in a real game, you better use the following code:<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-python-programming wp-block-embed-python-programming\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"aZvYHF2tWA\"><a href=\"https:\/\/pythonprogramming.altervista.org\/pygame-sprite-animation-v-2-better-coding-test-it-checking-fps-on-the-screen\/\">Pygame Sprite Animation v.2 &#8211; Better coding? Test it checking FPS on the screen<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;Pygame Sprite Animation v.2 &#8211; Better coding? Test it checking FPS on the screen&#8221; &#8212; python programming\" src=\"https:\/\/pythonprogramming.altervista.org\/pygame-sprite-animation-v-2-better-coding-test-it-checking-fps-on-the-screen\/embed\/#?secret=z62U0LxT39#?secret=aZvYHF2tWA\" data-secret=\"aZvYHF2tWA\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">This is the code<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import pygame\nimport glob\n \nSIZE = WIDTH, HEIGHT = 600, 600 #the width and height of our screen\nFPS = 60 #Frames per second\n \ndef fps():\n    fr = \"V. 2 Fps: \" + str(int(clock.get_fps()))\n    frt = font.render(fr, 1, pygame.Color(\"coral\"))\n    return frt\n\nclass MySprite(pygame.sprite.Sprite):\n    def __init__(self, action):\n        super(MySprite, self).__init__()\n        im = glob.glob(f\"png\\\\{action}*.png\")\n        lenim = len(im[0])\n        self.images = [pygame.image.load(img) for img in glob.glob(f\"png\\\\{action}*.png\") if len(img) == lenim]\n        self.images2 = [pygame.image.load(img) for img in glob.glob(f\"png\\\\{action}*.png\") if len(img) &gt; lenim]\n        self.images.extend(self.images2)\n        self.index = 0\n        self.rect = pygame.Rect(5, 5, 150, 198)\n\n    def update(self):\n        if self.index &gt;= len(self.images):\n            self.index = 0\n        self.image = self.images[self.index]\n        self.index += 1\n\ndef create_sprites():\n    idle = pygame.sprite.Group(MySprite(\"idle\"))\n    walk = pygame.sprite.Group(MySprite(\"walk\"))\n    run = pygame.sprite.Group(MySprite(\"run\"))\n    jump = pygame.sprite.Group(MySprite(\"jump\"))\n    dead = pygame.sprite.Group(MySprite(\"dead\"))\n    return idle, walk, run, jump, dead\n\ndef main():\n    global clock\n    global font\n\n    pygame.init()\n    font = pygame.font.SysFont(\"Arial\", 60)\n    screen = pygame.display.set_mode(SIZE)\n    pygame.display.set_caption(\"Game v.2\")\n    idle, walk, run, jump, dead = create_sprites()\n    my_group = idle\n    clock = pygame.time.Clock()\n    loop = 1\n    while loop:\n\n        for event in pygame.event.get():\n            if event.type == pygame.QUIT:\n                loop = 0\n            if event.type == pygame.KEYDOWN:\n                if event.key == pygame.K_LEFT: my_group = walk\n                if event.key == pygame.K_d: my_group = dead                \n                if event.key == pygame.K_UP: my_group = jump\n                if event.key == pygame.K_SPACE: my_group = idle\n                if event.key == pygame.K_RIGHT: my_group = run\n                if event.key == pygame.K_DOWN: my_group = dead\n\n \n        my_group.update()\n        screen.fill((0,0,0))\n        my_group.draw(screen)\n        screen.blit(fps(), (10, 0))\n        pygame.display.update()\n        clock.tick(FPS)\n    pygame.quit()\n \nif __name__ == '__main__':\n    main()<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"the-video-that-shows-wich-code-is-better-for-animation-fps\">The video that shows wich code is better for animation (fps)<\/h2>\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<iframe loading=\"lazy\" title=\"Pygame: FPS to see which code is better for gaming\" width=\"747\" height=\"420\" src=\"https:\/\/www.youtube.com\/embed\/gc-TnkZ6p1k?feature=oembed&amp;enablejsapi=1\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n\n<\/div><\/figure>\n\n\n<h3>Pygame's Platform Game<\/h3>\r\n\r\n<a href=\"https:\/\/pythonprogramming.altervista.org\/pygame-platform-game-5-sounds-and-mixer\/\"><img decoding=\"async\" src=\"https:\/\/i1.wp.com\/pythonprogramming.altervista.org\/wp-content\/uploads\/2020\/01\/climbercover.png?w=557&ssl=1\"\/ width=\"50%\"><\/a>\r\n<script>\r\nvar title = \"Platform Pygame\";\r\n\t\tvar links = [\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-animation-of-a-sprite-v-1-3\/\",\"Animation 1.3\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-sprite-animation-v-2-better-coding-test-it-checking-fps-on-the-screen\/\",\"Animation 1.2\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-how-to-display-the-frame-rate-fps-on-the-screen\/\",\"Display Frame rate\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-sprite-animation-update\/\",\"Animation 1.1\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-platformer-1\/\",\"Pygame Platform Game 1\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/python-platform-game-2\/\",\"Pygame Platform 2\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-platform-game-3-recap-cheatsheet\/\",\"Pygame PLatform 3 - recap and some Cheat Sheet\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-platform-game-4-background-and-stuffs\/\",\"Pygame Platform 4 - Background & organizing code\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-platform-game-5-sounds-and-mixer\/\",\"Pygame Platform 5 - Sounds\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/platform-game-in-detail-part-1\/\",\"Game in detail part 1\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/map-maker-1-2\/\", \"Map maker 1.2\"]\r\n\t\t];\r\n\t\t<\/script>\r\n<script>\r\n\t\r\nif (typeof next2 != \"undefined\"){let next2 = 0;}\r\n\t\r\nnext2 = 0;\r\n\thtml = \"\";\/\/<b style='color:coral;font-size:1.2em'>Other posts about \" + title + \"<\/b><br>\";\r\nfor (address of links) \r\n{\r\n\r\n\tif (next2 == 1){\r\n\t\thtml += \"<div style='background:coral'>\";\r\n\t\thtml += \"Next link => <a href='\" + address[0] + \"'>\" + address[1] + \"<\/a>\";\r\n\t\thtml += \"<\/div><br>\";\r\n\t\tnext2 = 0;\r\n\t}\r\n\tif (address[0] == document.URL) {\r\n\t\tnext2 = 1;\r\n\t}\r\n}\r\n\r\nif (typeof next != \"undefined\") {let next = 0;}\r\nif (typeof addressStart != \"undefined\") {let addressStart = \"\";}\r\nnext = 0;\r\naddressStart = \"<a href='\";\r\nfor (address of links) {\r\n\tif (next == 1){\r\n\t\thtml += \">>>\" + addressStart + address[0] + \"'>\" + address[1] + \"<\/a><br>\";\r\n\t\tnext = 0;\r\n\t}\r\n\telse if (addressStart + address[0] != document.URL)\r\n\t{\r\n\t\thtml += addressStart + address[0] + \"'>\" + address[1] + \"<\/a><br>\";\r\n\t}\r\n\telse\r\n\t{\r\n\t\tnext = 1;\r\n\t\tnext_address = address[0]\r\n\t\tnext_title = address[1]\r\n\t\thtml += \"<span style='color:gray'>\" + address[1] + \"<\/span><br>\";\r\n\t}\r\n\r\n}\r\n\r\n\thtml += `<span style=\"font-size:8px\">Powered by <a href=\"https:\/\/pythonprogramming.altervista.org\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2673\" src=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2019\/06\/altervista2.png\" alt=\"\" width=\"70\" height=\"25\" srcset=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2019\/06\/altervista2.png 156w, https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2019\/06\/altervista2-150x56.png 150w\" sizes=\"auto, (max-width: 70px) 100vw, 70px\" \/>pythonprogramming.altervista.org<\/a><\/span>`\r\n\thtml = \"<div style='background:yellow'>\" + html + \"<\/div>\";\r\n\tdocument.write(html)\r\n<\/script>\r\n\r\n<h3>Other Pygame's posts<\/h3>\r\n\r\n<script>\r\nvar title = \"Pygame's Posts\"\r\nvar links = [\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-platformer-1\/\",\"Platform game 1\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/make-a-platform-game-with-pygame-dafluffypotato\/\",\"DaFluffyPotato Platform Tutorials\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/python-and-classic-arcade-games-pong\/\",\"Pong Game Full\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/python-draws-in-colors-app-to-draw-with-pygame\/\",\"PyGameGIF 2\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-draw-app-with-animation\/\",\"PyGameGIF 1\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pydraw-2-0-app-to-draw-gif\/\",\"PyDraw 2.0\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-drawing-2\/\",\"Draw with Pygame\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/animation-with-pygame\",\"Sprite animation 1\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/animation-on-pygame-2-free-characters-and-more-actions\/\",\"Sprite animation 2\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/starting-with-pygame\/\",\"Starting movements with Pygame\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-3-move-sprite\/\", \"Move a Sprite\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-4-fonts\/\",\"Text and Fonts\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-animate-a-sprite\/\", \"Animate a sprite\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-and-mouse-events\/\",\"Mouse events\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pgp-aka-pygamepresentation-project\/\",\"Pygame presentation\"],\r\n\t[\"https:\/\/pythonprogramming.altervista.org\/moving-the-player-in-pygame-with-key-get_pressed\/\",\"How to use key.get_pressed()\"]\r\n]\r\n<\/script>\r\n\r\n\r\n<script>\r\n\t\r\nif (typeof next2 != \"undefined\"){let next2 = 0;}\r\n\t\r\nnext2 = 0;\r\n\thtml = \"\";\/\/<b style='color:coral;font-size:1.2em'>Other posts about \" + title + \"<\/b><br>\";\r\nfor (address of links) \r\n{\r\n\r\n\tif (next2 == 1){\r\n\t\thtml += \"<div style='background:coral'>\";\r\n\t\thtml += \"Next link => <a href='\" + address[0] + \"'>\" + address[1] + \"<\/a>\";\r\n\t\thtml += \"<\/div><br>\";\r\n\t\tnext2 = 0;\r\n\t}\r\n\tif (address[0] == document.URL) {\r\n\t\tnext2 = 1;\r\n\t}\r\n}\r\n\r\nif (typeof next != \"undefined\") {let next = 0;}\r\nif (typeof addressStart != \"undefined\") {let addressStart = \"\";}\r\nnext = 0;\r\naddressStart = \"<a href='\";\r\nfor (address of links) {\r\n\tif (next == 1){\r\n\t\thtml += \">>>\" + addressStart + address[0] + \"'>\" + address[1] + \"<\/a><br>\";\r\n\t\tnext = 0;\r\n\t}\r\n\telse if (addressStart + address[0] != document.URL)\r\n\t{\r\n\t\thtml += addressStart + address[0] + \"'>\" + address[1] + \"<\/a><br>\";\r\n\t}\r\n\telse\r\n\t{\r\n\t\tnext = 1;\r\n\t\tnext_address = address[0]\r\n\t\tnext_title = address[1]\r\n\t\thtml += \"<span style='color:gray'>\" + address[1] + \"<\/span><br>\";\r\n\t}\r\n\r\n}\r\n\r\n\thtml += `<span style=\"font-size:8px\">Powered by <a href=\"https:\/\/pythonprogramming.altervista.org\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2673\" src=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2019\/06\/altervista2.png\" alt=\"\" width=\"70\" height=\"25\" srcset=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2019\/06\/altervista2.png 156w, https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2019\/06\/altervista2-150x56.png 150w\" sizes=\"auto, (max-width: 70px) 100vw, 70px\" \/>pythonprogramming.altervista.org<\/a><\/span>`\r\n\thtml = \"<div style='background:yellow'>\" + html + \"<\/div>\";\r\n\tdocument.write(html)\r\n<\/script>\n","protected":false},"excerpt":{"rendered":"Animate a sprite with Pygame\n<a class=\"moretag\" href=\"https:\/\/pythonprogramming.altervista.org\/pygame-sprite-animation-update\/\"> [...]<\/a>","protected":false},"author":1,"featured_media":4780,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[1,191],"tags":[686,194],"class_list":["post-4765","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-examples","category-pygame","tag-animate","tag-pygame"],"avopt_banners_inside_post":true,"avopt_banners_on_page":true,"av_copy_from":"","av_sharing_message":"","av_sharing_allowed":true,"av_sharing_on":{"fb":[],"tw":[]},"av_allow_affiliate_banner":false,"av_allow_affiliate_multi_banner":false,"av_show_affiliation_buy_button":false,"av_post_rating":true,"av_have_post_rating_value":false,"av_is_artificial_intelligence_content":false,"_links":{"self":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/4765","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/comments?post=4765"}],"version-history":[{"count":5,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/4765\/revisions"}],"predecessor-version":[{"id":10985,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/4765\/revisions\/10985"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/media\/4780"}],"wp:attachment":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/media?parent=4765"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/categories?post=4765"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/tags?post=4765"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}