{"id":1361,"date":"2011-02-01T11:29:30","date_gmt":"2011-02-01T11:29:30","guid":{"rendered":"http:\/\/www.benoitfreslon.com\/?p=1361"},"modified":"2024-07-19T09:34:08","modified_gmt":"2024-07-19T07:34:08","slug":"actionscript-move-an-object-with-keyboard-with-absolute-controls","status":"publish","type":"post","link":"https:\/\/benoitfreslon.com\/fr\/news\/actionscript-move-an-object-with-keyboard-with-absolute-controls\/","title":{"rendered":"ActionScript: Move an object with keyboard with absolute controls"},"content":{"rendered":"<p>Dans ce tutoriel je vais vous montrer comment d\u00e9placer un objet avec le clavier en\u00a0contr\u00f4le\u00a0absolu\u00a0en Flash.<\/p>\n<p><a href=\"https:\/\/benoitfreslon.com\/actionscript-move-an-object-with-keyboard-with-absolute-controls\">Voir \u00e9galement comment d\u00e9placer un objet avec le clavier avec des contr\u00f4les relatifs \u00e0 la cam\u00e9ra.<\/a><\/p>\n<p><strong>Contr\u00f4le absolu ? K\u00e9zako ?<\/strong><\/p>\n<p>La direction de votre objet va \u00eatre calcul\u00e9e en fonction de l&rsquo;orientation de votre objet. (Resident Evil, Micro Machines, Gears of War, etc.). Ce script est tr\u00e8s utile pour les jeux de voitures.<\/p>\n<p><strong>Comment faire un contr\u00f4le\u00a0absolu en Flash?<\/strong><\/p>\n<ul>\n<li>R\u00e9cup\u00e9rer les informations des touches du clavier (touche enfonc\u00e9e, touche rel\u00e2ch\u00e9e)<\/li>\n<li>D\u00e9placer ou tourner l&rsquo;objet entre chaque frame avec la nouvelle vitesse (Touche gauche et droite : tourner l&rsquo;objet, Haut : faire avancer l&rsquo;objet, Bas ; faire reculer l&rsquo;objet)<\/li>\n<\/ul>\n<pre class=\"brush:as3\">\/\/ Assigner 4 bool\u00e9ens pour chaque touche\r\nvar keyUp = false;\r\nvar keyDown = false;\r\nvar keyLeft = false;\r\nvar keyRight = false;\r\n\/\/ Ajouter une \u00e9couteur d'\u00e9v\u00e9nement clavier pour une touche press\u00e9e sur la sc\u00e8ne\r\nstage.addEventListener(KeyboardEvent.KEY_DOWN, pressKey);\r\n\r\nfunction pressKey(pEvent) {\r\n\t\/\/ Si une touche est enfonc\u00e9e, changer la valeur du boolean (true) assign\u00e9e pour la touche correspondante\r\n\tif (pEvent.keyCode == 38) {\r\n\t\tkeyUp = true;\r\n\t} else if (pEvent.keyCode == 40) {\r\n\t\tkeyDown = true;\r\n\t} else if (pEvent.keyCode == 37) {\r\n\t\tkeyLeft = true;\r\n\t} else if (pEvent.keyCode == 39) {\r\n\t\tkeyRight = true;\r\n\t}\r\n}\r\n\/\/ Ajouter un \u00e9couteur d'\u00e9v\u00e9nement clavier pour une touche rel\u00e2ch\u00e9e sur la sc\u00e8ne\r\nstage.addEventListener(KeyboardEvent.KEY_UP, releaseKey);\r\nfunction releaseKey(pEvent) {\r\n\t\/\/ Si une touche est rel\u00e2ch\u00e9e, changer la valeur du boolean (false) assign\u00e9e pour la touche correspondante\r\n\tif (pEvent.keyCode == 38) {\r\n\t\tkeyUp = false;\r\n\t} else if (pEvent.keyCode == 40) {\r\n\t\tkeyDown = false;\r\n\t} else if (pEvent.keyCode == 37) {\r\n\t\tkeyLeft = false;\r\n\t} else if (pEvent.keyCode == 39) {\r\n\t\tkeyRight = false;\r\n\t}\r\n}\r\n\r\n\/\/ Assigner la vitesse de l'objet \u00e0 6px\/frame\r\nvar speed = 6;\r\n\r\n\/\/ Et la vitesse de rotation en \u00b0\r\nvar rotationSpeed = 5;\r\n\r\n\/\/ Ajouter un \u00e9couteur d'\u00e9v\u00e9nement entre chaque frame sur l'objet en mouvement\r\nmyCircle.addEventListener(Event.ENTER_FRAME, circleEnterFrame);\r\n\r\nfunction circleEnterFrame(pEvent) {\r\n\t\/\/ Assigner la v\u00e9locit\u00e9 initiale de l'objet \u00e0 0\r\n\tvar velocity = 0;\r\n\tif (keyUp) {\r\n\t\t\/\/ Si la touche Haut est enfonc\u00e9e on assigne la vitesse de l'objet \u00e0 la v\u00e9locit\u00e9 courante\r\n\t\tvelocity = speed;\r\n\t}\r\n\tif (keyDown) {\r\n\t\t\/\/ Si la touche Haut est enfonc\u00e9e on assigne la vitesse de l'objet \u00e0 la v\u00e9locit\u00e9 courante divis\u00e9e par 2\r\n\t\tvelocity =  -  speed \/ 2;\r\n\t}\r\n\tif (keyLeft) {\r\n\t\t\/\/ Faire tourner l'objet sur lui m\u00eame\r\n\t\tpEvent.currentTarget.rotation -=  rotationSpeed;\r\n\t}\r\n\tif (keyRight) {\r\n\t\t\/\/Faire tourner l'objet sur lui m\u00eame\r\n\t\tpEvent.currentTarget.rotation +=  rotationSpeed;\r\n\t}\r\n\r\n\t\/\/ On convertie l'angle form\u00e9 par l'objet en radian\r\n\tvar angleRadian = pEvent.currentTarget.rotation \/ 180 * Math.PI;\r\n\r\n\t\/\/ On d\u00e9place l'objet avec l'angle, soit son orientation et sa vitesse courante donc sa v\u00e9locit\u00e9\r\n\tpEvent.currentTarget.x +=  Math.cos(angleRadian) * velocity;\r\n\tpEvent.currentTarget.y +=  Math.sin(angleRadian) * velocity;\r\n}<\/pre>\n<p>[swf:\/wp-content\/uploads\/2011\/02\/www.benoitfreslon.com_Move_an_object_with_keyboard_with_absolute_controls.swf 550 400]<\/p>\n<p>T\u00e9l\u00e9charger la source : <a href=\"https:\/\/benoitfreslon.com\/wp-content\/uploads\/2011\/02\/www.benoitfreslon.com_Move_an_object_with_keyboard_with_absolute_controls1.zip\">www.benoitfreslon.com_Move_an_object_with_keyboard_with_absolute_controls<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>Dans ce tutoriel je vais vous montrer comment d\u00e9placer un objet avec le clavier en\u00a0contr\u00f4le\u00a0absolu\u00a0en Flash. Voir \u00e9galement comment d\u00e9placer&#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":[406,408,6,48,402,407],"class_list":["post-1361","post","type-post","status-publish","format-standard","hentry","category-news","tag-absolue","tag-controles","tag-flash","tag-jeu","tag-tutoriels-flash","tag-voiture","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 an object with keyboard with absolute controls - 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-an-object-with-keyboard-with-absolute-controls\/\" \/>\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-an-object-with-keyboard-with-absolute-controls\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/benoitfreslon.com\\\/news\\\/actionscript-move-an-object-with-keyboard-with-absolute-controls\\\/\"},\"author\":{\"name\":\"Benoit Freslon\",\"@id\":\"https:\\\/\\\/benoitfreslon.com\\\/#\\\/schema\\\/person\\\/fe9fe28a6b6c2b56648448b977fd6b78\"},\"headline\":\"ActionScript: Move an object with keyboard with absolute controls\",\"datePublished\":\"2011-02-01T11:29:30+00:00\",\"dateModified\":\"2024-07-19T07:34:08+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/benoitfreslon.com\\\/news\\\/actionscript-move-an-object-with-keyboard-with-absolute-controls\\\/\"},\"wordCount\":308,\"keywords\":[\"absolue\",\"controles\",\"flash\",\"jeu\",\"Tutoriels Flash\",\"voiture\"],\"articleSection\":[\"Actualit\u00e9s\"],\"inLanguage\":\"fr-FR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/benoitfreslon.com\\\/fr\\\/news\\\/actionscript-move-an-object-with-keyboard-with-absolute-controls\\\/\",\"url\":\"https:\\\/\\\/benoitfreslon.com\\\/fr\\\/news\\\/actionscript-move-an-object-with-keyboard-with-absolute-controls\\\/\",\"name\":\"ActionScript: Move an object with keyboard with absolute controls - Beno\u00eet Freslon\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/benoitfreslon.com\\\/fr\\\/#website\"},\"datePublished\":\"2011-02-01T11:29:30+00:00\",\"dateModified\":\"2024-07-19T07:34:08+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/benoitfreslon.com\\\/#\\\/schema\\\/person\\\/fe9fe28a6b6c2b56648448b977fd6b78\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/benoitfreslon.com\\\/fr\\\/news\\\/actionscript-move-an-object-with-keyboard-with-absolute-controls\\\/#breadcrumb\"},\"inLanguage\":\"fr-FR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[[\"https:\\\/\\\/benoitfreslon.com\\\/fr\\\/news\\\/actionscript-move-an-object-with-keyboard-with-absolute-controls\\\/\"]]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/benoitfreslon.com\\\/fr\\\/news\\\/actionscript-move-an-object-with-keyboard-with-absolute-controls\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/benoitfreslon.com\\\/fr\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"ActionScript: Move an object with keyboard with absolute controls\"}]},{\"@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 an object with keyboard with absolute controls - 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-an-object-with-keyboard-with-absolute-controls\/","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-an-object-with-keyboard-with-absolute-controls\/#article","isPartOf":{"@id":"https:\/\/benoitfreslon.com\/news\/actionscript-move-an-object-with-keyboard-with-absolute-controls\/"},"author":{"name":"Benoit Freslon","@id":"https:\/\/benoitfreslon.com\/#\/schema\/person\/fe9fe28a6b6c2b56648448b977fd6b78"},"headline":"ActionScript: Move an object with keyboard with absolute controls","datePublished":"2011-02-01T11:29:30+00:00","dateModified":"2024-07-19T07:34:08+00:00","mainEntityOfPage":{"@id":"https:\/\/benoitfreslon.com\/news\/actionscript-move-an-object-with-keyboard-with-absolute-controls\/"},"wordCount":308,"keywords":["absolue","controles","flash","jeu","Tutoriels Flash","voiture"],"articleSection":["Actualit\u00e9s"],"inLanguage":"fr-FR"},{"@type":"WebPage","@id":"https:\/\/benoitfreslon.com\/fr\/news\/actionscript-move-an-object-with-keyboard-with-absolute-controls\/","url":"https:\/\/benoitfreslon.com\/fr\/news\/actionscript-move-an-object-with-keyboard-with-absolute-controls\/","name":"ActionScript: Move an object with keyboard with absolute controls - Beno\u00eet Freslon","isPartOf":{"@id":"https:\/\/benoitfreslon.com\/fr\/#website"},"datePublished":"2011-02-01T11:29:30+00:00","dateModified":"2024-07-19T07:34:08+00:00","author":{"@id":"https:\/\/benoitfreslon.com\/#\/schema\/person\/fe9fe28a6b6c2b56648448b977fd6b78"},"breadcrumb":{"@id":"https:\/\/benoitfreslon.com\/fr\/news\/actionscript-move-an-object-with-keyboard-with-absolute-controls\/#breadcrumb"},"inLanguage":"fr-FR","potentialAction":[{"@type":"ReadAction","target":[["https:\/\/benoitfreslon.com\/fr\/news\/actionscript-move-an-object-with-keyboard-with-absolute-controls\/"]]}]},{"@type":"BreadcrumbList","@id":"https:\/\/benoitfreslon.com\/fr\/news\/actionscript-move-an-object-with-keyboard-with-absolute-controls\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/benoitfreslon.com\/fr\/"},{"@type":"ListItem","position":2,"name":"ActionScript: Move an object with keyboard with absolute controls"}]},{"@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-lX","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/benoitfreslon.com\/fr\/wp-json\/wp\/v2\/posts\/1361","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=1361"}],"version-history":[{"count":38,"href":"https:\/\/benoitfreslon.com\/fr\/wp-json\/wp\/v2\/posts\/1361\/revisions"}],"predecessor-version":[{"id":39125,"href":"https:\/\/benoitfreslon.com\/fr\/wp-json\/wp\/v2\/posts\/1361\/revisions\/39125"}],"wp:attachment":[{"href":"https:\/\/benoitfreslon.com\/fr\/wp-json\/wp\/v2\/media?parent=1361"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/benoitfreslon.com\/fr\/wp-json\/wp\/v2\/categories?post=1361"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/benoitfreslon.com\/fr\/wp-json\/wp\/v2\/tags?post=1361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}