{"id":2598,"date":"2013-09-25T10:54:39","date_gmt":"2013-09-25T10:54:39","guid":{"rendered":"http:\/\/www.benoitfreslon.com\/?p=2598"},"modified":"2024-11-03T15:21:59","modified_gmt":"2024-11-03T13:21:59","slug":"actionscript-move-object-with-smooth-acceleration-and-deceleration-with-inertia","status":"publish","type":"post","link":"https:\/\/benoitfreslon.com\/fr\/news\/actionscript-move-object-with-smooth-acceleration-and-deceleration-with-inertia\/","title":{"rendered":"ActionScript: Move object with smooth acceleration and deceleration with inertia"},"content":{"rendered":"<p>Aujourd&rsquo;hui voici un exemple de code pour cr\u00e9er un effet d&rsquo;acc\u00e9l\u00e9ration et d&rsquo;inertie en Flash ActionScript 3.0.<\/p>\n<p>Le personnage va commencer \u00e0 acc\u00e9l\u00e9rer si on appuie sur une fl\u00e8che. Il atteindra sa vitesse maximale puis il ralentira si on rel\u00e2che la touche.<\/p>\n<p>[swf:\/wp-content\/uploads\/2013\/09\/Flash_acceleration_benoifreslon.com_.swf 550 400]<\/p>\n<p>Vous pouvez t\u00e9l\u00e9charger le code source ici :\u00a0<a href=\"https:\/\/benoitfreslon.com\/wp-content\/uploads\/2013\/09\/Flash_acceleration_benoifreslon.com_.fla\">Flash_acceleration_benoifreslon.com<\/a><\/p>\n<pre class=\"brush:as3\">\/\/ Copyrights\r\n\/\/ Beno\u00eet Freslon\r\n\/\/ http:\/\/www.benoitfreslon.com\r\n\r\nimport flash.events.KeyboardEvent;\r\nimport flash.events.MouseEvent;\r\n\r\n\/\/ Constantes (Vous pouvez modifier ces valeurs)\r\nconst acceleration:Number = 0.1;\r\nconst decceleration:Number = 0.9;\r\nconst speedMax:Number = 5;\r\n\r\n\/\/ Variables\r\nvar speedX:Number = 0;\r\nvar speedY:Number = 0;\r\n\r\n\/\/ Etats des touches\r\nvar leftPressed:Boolean = false;\r\nvar rightPressed:Boolean = false;\r\nvar upPressed:Boolean = false;\r\nvar downPressed:Boolean = false;\r\n\r\n\/\/ Ev\u00e9nements clavier\r\nstage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown);\r\nstage.addEventListener(KeyboardEvent.KEY_UP, keyUp);\r\nfunction keyDown(e:KeyboardEvent):void {\r\n\tswitch (e.keyCode) {\r\n\t\tcase 37 :\r\n\t\t\tleftPressed = true;\r\n\t\t\tbreak;\r\n\t\tcase 38 :\r\n\t\t\tupPressed = true;\r\n\t\t\tbreak;\r\n\t\tcase 39 :\r\n\t\t\trightPressed = true;\r\n\t\t\tbreak;\r\n\t\tcase 40 :\r\n\t\t\tdownPressed = true;\r\n\t\t\tbreak;\r\n\t}\r\n}\r\nfunction keyUp(e:KeyboardEvent):void {\r\n\tswitch (e.keyCode) {\r\n\t\tcase 37 :\r\n\t\t\tleftPressed = false;\r\n\t\t\tbreak;\r\n\t\tcase 38 :\r\n\t\t\tupPressed = false;\r\n\t\t\tbreak;\r\n\t\tcase 39 :\r\n\t\t\trightPressed = false;\r\n\t\t\tbreak;\r\n\t\tcase 40 :\r\n\t\t\tdownPressed = false;\r\n\t\t\tbreak;\r\n\t}\r\n}\r\n\r\n\/\/ Ev\u00e9nement r\u00e9p\u00e9t\u00e9 toutes les images\r\npig.addEventListener(Event.ENTER_FRAME, enterFrame);\r\nfunction enterFrame(e:Event):void {\r\n\r\n\t\/\/ Si un touche est enfonc\u00e9e on augmente la valeur de la vitesse avec la valeur d'acc\u00e9l\u00e9ration\r\n\r\n\tif (upPressed) {\r\n\t\tspeedY -=  acceleration;\r\n\t} else if (downPressed) {\r\n\t\tspeedY +=  acceleration;\r\n\t} else {\r\n\t\t\/\/ Si la touche haut et bas sont rel\u00e2ch\u00e9es alors on diminue la vitesse avec la valeur de decceleration\r\n\t\tspeedY *=  decceleration;\r\n\t}\r\n\r\n\tif (leftPressed) {\r\n\t\tspeedX -=  acceleration;\r\n\t} else if (rightPressed) {\r\n\t\tspeedX +=  acceleration;\r\n\t} else {\r\n\t\tspeedX *=  decceleration;\r\n\t}\r\n\r\n\t\/\/ Ne pas oublier de limiter les vitesses\r\n\tif (speedX &gt; speedMax) {\r\n\t\tspeedX = speedMax;\r\n\t}\r\n\tif (speedX  &lt;-speedMax) { speedX = - speedMax; } if (speedY &gt; speedMax) {\r\n\t\tspeedY = speedMax;\r\n\t}\r\n\tif (speedY &lt;-speedMax) {\r\n\t\tspeedY =  -  speedMax;\r\n\t}\r\n\r\n\t\/\/ D\u00e9placer le cochon constamment\r\n\tpig.x +=  speedX;\r\n\tpig.y +=  speedY;\r\n\r\n\t\/\/ Affiche les valeurs sur l'interface\r\n\ttValues.text = \"speedX: \" + speedX + \"\\nspeedY: \" + speedY;\r\n\r\n}\r\n\r\n\/\/ RAZ du cochon\r\nstage.addEventListener(MouseEvent.CLICK , click);\r\nfunction click(e:MouseEvent):void {\r\n\tpig.x = stage.stageWidth \/ 2;\r\n\tpig.y = stage.stageHeight \/ 2;\r\n}<\/pre>\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>Aujourd&rsquo;hui voici un exemple de code pour cr\u00e9er un effet d&rsquo;acc\u00e9l\u00e9ration et d&rsquo;inertie en Flash ActionScript 3.0. Le personnage va&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1],"tags":[85,94,247,6,302,248,102,104],"class_list":["post-2598","post","type-post","status-publish","format-standard","hentry","category-news","tag-acceleration","tag-as3","tag-decceleration","tag-flash","tag-actionscript","tag-inertia","tag-move","tag-smooth","wpcat-1-id"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>ActionScript: Move object with smooth acceleration and deceleration with inertia - Beno\u00eet Freslon<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/benoitfreslon.com\/fr\/news\/actionscript-move-object-with-smooth-acceleration-and-deceleration-with-inertia\/\" \/>\n<meta name=\"twitter:label1\" content=\"\u00c9crit par\" \/>\n\t<meta name=\"twitter:data1\" content=\"Benoit Freslon\" \/>\n\t<meta name=\"twitter:label2\" content=\"Dur\u00e9e de lecture estim\u00e9e\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/benoitfreslon.com\\\/news\\\/actionscript-move-object-with-smooth-acceleration-and-deceleration-with-inertia\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/benoitfreslon.com\\\/news\\\/actionscript-move-object-with-smooth-acceleration-and-deceleration-with-inertia\\\/\"},\"author\":{\"name\":\"Benoit Freslon\",\"@id\":\"https:\\\/\\\/benoitfreslon.com\\\/#\\\/schema\\\/person\\\/fe9fe28a6b6c2b56648448b977fd6b78\"},\"headline\":\"ActionScript: Move object with smooth acceleration and deceleration with inertia\",\"datePublished\":\"2013-09-25T10:54:39+00:00\",\"dateModified\":\"2024-11-03T13:21:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/benoitfreslon.com\\\/news\\\/actionscript-move-object-with-smooth-acceleration-and-deceleration-with-inertia\\\/\"},\"wordCount\":131,\"keywords\":[\"acceleration\",\"as3\",\"decceleration\",\"flash\",\"Flash development\",\"inertia\",\"move\",\"smooth\"],\"articleSection\":[\"Actualit\u00e9s\"],\"inLanguage\":\"fr-FR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/benoitfreslon.com\\\/fr\\\/news\\\/actionscript-move-object-with-smooth-acceleration-and-deceleration-with-inertia\\\/\",\"url\":\"https:\\\/\\\/benoitfreslon.com\\\/fr\\\/news\\\/actionscript-move-object-with-smooth-acceleration-and-deceleration-with-inertia\\\/\",\"name\":\"ActionScript: Move object with smooth acceleration and deceleration with inertia - Beno\u00eet Freslon\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/benoitfreslon.com\\\/fr\\\/#website\"},\"datePublished\":\"2013-09-25T10:54:39+00:00\",\"dateModified\":\"2024-11-03T13:21:59+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/benoitfreslon.com\\\/#\\\/schema\\\/person\\\/fe9fe28a6b6c2b56648448b977fd6b78\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/benoitfreslon.com\\\/fr\\\/news\\\/actionscript-move-object-with-smooth-acceleration-and-deceleration-with-inertia\\\/#breadcrumb\"},\"inLanguage\":\"fr-FR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[[\"https:\\\/\\\/benoitfreslon.com\\\/fr\\\/news\\\/actionscript-move-object-with-smooth-acceleration-and-deceleration-with-inertia\\\/\"]]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/benoitfreslon.com\\\/fr\\\/news\\\/actionscript-move-object-with-smooth-acceleration-and-deceleration-with-inertia\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/benoitfreslon.com\\\/fr\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"ActionScript: Move object with smooth acceleration and deceleration with inertia\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/benoitfreslon.com\\\/fr\\\/#website\",\"url\":\"https:\\\/\\\/benoitfreslon.com\\\/fr\\\/\",\"name\":\"Beno\u00eet Freslon\",\"description\":\"[:en]Game designer | D\u00e9veloppeur de jeux ind\u00e9pendant | Freelance | Enseignant | Blogueur[:fr]Game designer | Independent game developer | Freelance | Teacher | Blogger[:]\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/benoitfreslon.com\\\/fr\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"fr-FR\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/benoitfreslon.com\\\/#\\\/schema\\\/person\\\/fe9fe28a6b6c2b56648448b977fd6b78\",\"name\":\"Benoit Freslon\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"fr-FR\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0b828da2527f91fb7c86dab67050492f4303279afa245d6e718ea1c6e6f00bb2?s=96&d=identicon&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0b828da2527f91fb7c86dab67050492f4303279afa245d6e718ea1c6e6f00bb2?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0b828da2527f91fb7c86dab67050492f4303279afa245d6e718ea1c6e6f00bb2?s=96&d=identicon&r=g\",\"caption\":\"Benoit Freslon\"},\"sameAs\":[\"https:\\\/\\\/benoitfreslon.com\",\"https:\\\/\\\/www.instagram.com\\\/benoitfreslon\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/benoitfreslon\",\"https:\\\/\\\/x.com\\\/BenoitFreslon\",\"https:\\\/\\\/www.youtube.com\\\/benoitfreslon\"],\"url\":\"https:\\\/\\\/benoitfreslon.com\\\/fr\\\/author\\\/admin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"ActionScript: Move object with smooth acceleration and deceleration with inertia - Beno\u00eet Freslon","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/benoitfreslon.com\/fr\/news\/actionscript-move-object-with-smooth-acceleration-and-deceleration-with-inertia\/","twitter_misc":{"\u00c9crit par":"Benoit Freslon","Dur\u00e9e de lecture estim\u00e9e":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/benoitfreslon.com\/news\/actionscript-move-object-with-smooth-acceleration-and-deceleration-with-inertia\/#article","isPartOf":{"@id":"https:\/\/benoitfreslon.com\/news\/actionscript-move-object-with-smooth-acceleration-and-deceleration-with-inertia\/"},"author":{"name":"Benoit Freslon","@id":"https:\/\/benoitfreslon.com\/#\/schema\/person\/fe9fe28a6b6c2b56648448b977fd6b78"},"headline":"ActionScript: Move object with smooth acceleration and deceleration with inertia","datePublished":"2013-09-25T10:54:39+00:00","dateModified":"2024-11-03T13:21:59+00:00","mainEntityOfPage":{"@id":"https:\/\/benoitfreslon.com\/news\/actionscript-move-object-with-smooth-acceleration-and-deceleration-with-inertia\/"},"wordCount":131,"keywords":["acceleration","as3","decceleration","flash","Flash development","inertia","move","smooth"],"articleSection":["Actualit\u00e9s"],"inLanguage":"fr-FR"},{"@type":"WebPage","@id":"https:\/\/benoitfreslon.com\/fr\/news\/actionscript-move-object-with-smooth-acceleration-and-deceleration-with-inertia\/","url":"https:\/\/benoitfreslon.com\/fr\/news\/actionscript-move-object-with-smooth-acceleration-and-deceleration-with-inertia\/","name":"ActionScript: Move object with smooth acceleration and deceleration with inertia - Beno\u00eet Freslon","isPartOf":{"@id":"https:\/\/benoitfreslon.com\/fr\/#website"},"datePublished":"2013-09-25T10:54:39+00:00","dateModified":"2024-11-03T13:21:59+00:00","author":{"@id":"https:\/\/benoitfreslon.com\/#\/schema\/person\/fe9fe28a6b6c2b56648448b977fd6b78"},"breadcrumb":{"@id":"https:\/\/benoitfreslon.com\/fr\/news\/actionscript-move-object-with-smooth-acceleration-and-deceleration-with-inertia\/#breadcrumb"},"inLanguage":"fr-FR","potentialAction":[{"@type":"ReadAction","target":[["https:\/\/benoitfreslon.com\/fr\/news\/actionscript-move-object-with-smooth-acceleration-and-deceleration-with-inertia\/"]]}]},{"@type":"BreadcrumbList","@id":"https:\/\/benoitfreslon.com\/fr\/news\/actionscript-move-object-with-smooth-acceleration-and-deceleration-with-inertia\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/benoitfreslon.com\/fr\/"},{"@type":"ListItem","position":2,"name":"ActionScript: Move object with smooth acceleration and deceleration with inertia"}]},{"@type":"WebSite","@id":"https:\/\/benoitfreslon.com\/fr\/#website","url":"https:\/\/benoitfreslon.com\/fr\/","name":"Beno\u00eet Freslon","description":"[:en]Game designer | D\u00e9veloppeur de jeux ind\u00e9pendant | Freelance | Enseignant | Blogueur[:fr]Game designer | Independent game developer | Freelance | Teacher | Blogger[:]","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/benoitfreslon.com\/fr\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"fr-FR"},{"@type":"Person","@id":"https:\/\/benoitfreslon.com\/#\/schema\/person\/fe9fe28a6b6c2b56648448b977fd6b78","name":"Benoit Freslon","image":{"@type":"ImageObject","inLanguage":"fr-FR","@id":"https:\/\/secure.gravatar.com\/avatar\/0b828da2527f91fb7c86dab67050492f4303279afa245d6e718ea1c6e6f00bb2?s=96&d=identicon&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/0b828da2527f91fb7c86dab67050492f4303279afa245d6e718ea1c6e6f00bb2?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/0b828da2527f91fb7c86dab67050492f4303279afa245d6e718ea1c6e6f00bb2?s=96&d=identicon&r=g","caption":"Benoit Freslon"},"sameAs":["https:\/\/benoitfreslon.com","https:\/\/www.instagram.com\/benoitfreslon","https:\/\/www.linkedin.com\/in\/benoitfreslon","https:\/\/x.com\/BenoitFreslon","https:\/\/www.youtube.com\/benoitfreslon"],"url":"https:\/\/benoitfreslon.com\/fr\/author\/admin\/"}]}},"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/pLAe3-FU","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/benoitfreslon.com\/fr\/wp-json\/wp\/v2\/posts\/2598","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/benoitfreslon.com\/fr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/benoitfreslon.com\/fr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/benoitfreslon.com\/fr\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/benoitfreslon.com\/fr\/wp-json\/wp\/v2\/comments?post=2598"}],"version-history":[{"count":20,"href":"https:\/\/benoitfreslon.com\/fr\/wp-json\/wp\/v2\/posts\/2598\/revisions"}],"predecessor-version":[{"id":39192,"href":"https:\/\/benoitfreslon.com\/fr\/wp-json\/wp\/v2\/posts\/2598\/revisions\/39192"}],"wp:attachment":[{"href":"https:\/\/benoitfreslon.com\/fr\/wp-json\/wp\/v2\/media?parent=2598"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/benoitfreslon.com\/fr\/wp-json\/wp\/v2\/categories?post=2598"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/benoitfreslon.com\/fr\/wp-json\/wp\/v2\/tags?post=2598"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}