{"id":181,"date":"2010-09-24T16:20:19","date_gmt":"2010-09-24T16:20:19","guid":{"rendered":"http:\/\/www.crazygaze.com\/blog\/?p=181"},"modified":"2010-09-24T16:22:34","modified_gmt":"2010-09-24T16:22:34","slug":"cutscene-using-squirrel-scripting","status":"publish","type":"post","link":"https:\/\/www.crazygaze.com\/blog\/2010\/09\/24\/cutscene-using-squirrel-scripting\/","title":{"rendered":"Cutscene using squirrel scripting"},"content":{"rendered":"<p>The last 2 weeks or so, I\u2019ve been working on an update for Weston Westie, and one of the things coming out with the update is cutscenes.     <br \/>I\u2019ve been integrating Squirrel Scripting into the engine, as I thought would make things easier if I used a scripting language.     <br \/>After the initial painful process of making it work on Samsung Wave, creating some bindings between C++ and Squirrel, things started to pick up.     <br \/>In Weston Westie, cutscenes are mostly a series of still images, playing some sounds, some fading out\/in, the occasional moving background, etc.     <br \/>Using coroutines, the cutscene scripting is done in a serial way, unaware of the game loop.     <\/p>\n<div style=\"padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px\" id=\"scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:dd24aca2-9b4b-4fb9-a7ef-b869a90fef87\" class=\"wlWriterEditableSmartContent\">\n<div><object width=\"425\" height=\"355\"><param name=\"movie\" value=\"http:\/\/www.youtube.com\/v\/zVnSWbLgtIA&amp;hl=en\"><\/param><\/object><\/div>\n<div style=\"width:425px;clear:both;font-size:.8em\">One of the simple cutscenes I\u2019ve done so far.<\/div>\n<\/div>\n<p>The scripting for this particular scene goes kind of like this (simplified version)\u2026<\/p>\n<div style=\"padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px\" id=\"scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:bf2e1757-0f6c-4107-8c69-2e46e3c7e0f6\" class=\"wlWriterEditableSmartContent\">\n<pre>\n<pre class=\"brush: cpp; pad-line-numbers: true; title: ; notranslate\" title=\"\">\nfunction SailAway()\n{\n\t\/\/ Load needed resources...\n\tlocal imgDash = resourcemanager.Get(ResourceType.IMAGE, &quot;Sequences_Debut_Dash&quot;);\n\tlocal imgWestonOnFire = resourcemanager.Get(ResourceType.IMAGE, &quot;Sequences_Debut_WestonOnFire&quot;);\n\tlocal imgEnd1Shore = resourcemanager.Get(ResourceType.IMAGE, &quot;Sequences_End1Shore&quot;);\n\tlocal sngDetermination = resourcemanager.Get(ResourceType.SOUND, &quot;Determination&quot;);\n\t\/\/ ...\n\t\n\t\/\/ Create a UI Scene to use\n\tlocal scene = CUIScene.Create();\n\tscene.Activate();\n\t\n\t\/\/ Create two widgets to display a background, and a front image\n\tlocal back = CWidget.Create(scene.GetRootWidget());\n\tlocal front = CWidget.Create(scene.GetRootWidget());\n\t\n\t\/\/ Setup the images\n\tback.SetBackgroundImage(imgWestonOnFire, CColour4.WHITE);\n\tfront.SetBackgroundImage(imgDash, CColour4.WHITE);\n\n\t\/\/ Setup background and foreground images movement using some helper classes\n\t\/\/ ...\n\n\t\/\/\n\t\/\/ First part - Weston appearing, with the &quot;fire&quot; background\n\t\/\/\n\t\n\t\/\/ play introduction song as weston appears\n\tlocal sngH = soundmanager.Play(sngDetermination, false);\n\tTickFor(2.0); \/\/ animate everything for 2 seconds\n\t\/\/ starts a fade out on the song, that takes 4 seconds\n\tsoundmanager.SetFade(sngH, 0, 4.0); \n\tTickFor(1.0); \/\/ animate for 1.0\n\n\t\/\/\n\t\/\/ Second part - weston surprised\n\t\/\/\n\t\n\t\/\/ Show weston surprised at shore\n\tfront.SetBackgroundImage(imgEnd1Shore, CColour4.WHITE);\n\t\/\/ Play &quot;surprised&quot; sound\n\tsoundmanager.Play(sndWhat, false);\n\tTickFor(1.0);\n\t\n\t\/\/ .. and the list goes on, serially showing images,\n\t\/\/ playing sounds, fading, etc\n\t\n}\n\n<\/pre>\n<\/div>\n<p>My engine doesn\u2019t have any specific support for cutscenes, or fancy editors, so each cutscene is basically handcoded.<br \/>\n  <br \/>I do have some utility code to automate a fade in\/ou, or move an image around for example. <\/p>\n<p>I use mostly C++, so I\u2019m used to strongly typed languages. Using a scripting language like squirrel is a bit painful at start, as the compiler isn\u2019t much of a help catching mistakes. On the other hand, it does force you to pay more attention on what you\u2019re doing. <\/p>\n<p>Overall, I\u2019m happy with squirrel. The library is relatively small, and with a bit of effort you can find your way around. <\/p>\n<p>In the future I\u2019ll probably try some other scripting languages, particularly Lua, since it\u2019s so widespread in the games industry, or AngelScript, which is not that widespread, but has a nice feature set and it\u2019s closer to C++. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>The last 2 weeks or so, I\u2019ve been working on an update for Weston Westie, and one of the things coming out with the update is cutscenes. I\u2019ve been integrating Squirrel Scripting into the engine, as I thought would make things easier if I used a scripting language. After the initial painful process of making [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[3],"tags":[23,22,21],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p7jpe0-2V","_links":{"self":[{"href":"https:\/\/www.crazygaze.com\/blog\/wp-json\/wp\/v2\/posts\/181"}],"collection":[{"href":"https:\/\/www.crazygaze.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.crazygaze.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.crazygaze.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.crazygaze.com\/blog\/wp-json\/wp\/v2\/comments?post=181"}],"version-history":[{"count":1,"href":"https:\/\/www.crazygaze.com\/blog\/wp-json\/wp\/v2\/posts\/181\/revisions"}],"predecessor-version":[{"id":802,"href":"https:\/\/www.crazygaze.com\/blog\/wp-json\/wp\/v2\/posts\/181\/revisions\/802"}],"wp:attachment":[{"href":"https:\/\/www.crazygaze.com\/blog\/wp-json\/wp\/v2\/media?parent=181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.crazygaze.com\/blog\/wp-json\/wp\/v2\/categories?post=181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.crazygaze.com\/blog\/wp-json\/wp\/v2\/tags?post=181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}