Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon
24. August 2016

 

Welcome back to the ongoing Defold Game Engine tutorial series looking at all aspects of game development using the Defold game engine.  In this tutorial we are going to look at the process of playing sound and music in Defold.

 

There is an HD video version of this tutorial available here.

 

Playing sound in the Defold engine is simple, which is a double edged sword.  It’s extremely easy to add and play a sound file.  On the other hand the functionality provided is also quite simple.  Many things you may want to accomplish ( callback on sound end, fast forwarding/rewinding a playing audio file, positional audio, etc. ) simply aren’t supported.

Let’s start by adding some audio files to the project.  In my case I added a folder named audio and dragged in an ogg file and a wav file from Windows Explorer to Defold.  These are the two file formats supported.  The ogg file is an Ogg Vorbis file, a compressed streamed format similar to mp3 format but not patent encumbered.  Wav files are almost entirely uncompressed but require less processing power.  In a nutshell for longer form audio files, such as music, use an ogg.  For sound effects, use wav.  The end result should look something like:

image

 

Next we go ahead and create a sound component for our game.  You could parent your sound components to whatever game object you wish.  If it makes sense to create a music player game object and attach all the sounds to it, you could.  Or if you want your game objects (for example, the player) to own their own sound components, that’s alright too.  Select whatever game object you want to add the sound to, right click and select Add Component.

image

 

Next select Sound from the component list.

image

 

Here I am creating one for the music file first:

image

 

Hit the … button beside Sound and select the ogg file you dropped in earlier.  Notice in this case I changed the Group to music.  I repeat the same process for the wav file, instead named sfx. 

 

Now playing the sound effect using code is extremely easy and once again uses messages like so:

msg.post("#music","play_sound")

 

Simply post the play_sound message to the music component of our current game object.  Playing the sound effect file is the exact same process but instead post the message to the #sfx component like so:

msg.post("#sfx","play_sound")

 

We can also control the volume of the sound component, like so:

msg.post("#music","set_gain", { gain = volume })

 

Volume is a value from 0.0 to 1.0, where 0.0 is no volume, while 1.0 represents full volume.  Remember earlier when I changed the group for our music file from “master” to “music”.   Groups enable you to control several sound effects at once, for example muting all the playing songs or sound effects.  For example, we could mute all the sounds in the group music with the following call:

sound.set_group_gain(hash("music"), 0.0)

 

Here is the full source for this example:

-- Local variable for volume. 0 is none, 1 is full
local volume = 1.0

function init(self)
  msg.post(".","acquire_input_focus")
  -- start playing the background music
  msg.post("#music","play_sound")
end

function on_input(self, action_id, action)
  if(action_id == hash("SPACE_PRESSED") and action.pressed == true) then
    -- if user hits the spacebar play the soundfx file. 
    -- multiple presses will play multiple instances.
    msg.post("#sfx","play_sound")
  elseif(action_id == hash("ESC") and action.pressed == true) then
    -- on ESC mute the entire group "music"
    sound.set_group_gain(hash("music"), 0.0)
  elseif(action_id == hash("DOWN_ARROW") and action.pressed == true) then
    if volume >= 0 then
      volume = volume - 0.1
    end
    -- lower the volume of our music
    msg.post("#music","set_gain", { gain = volume })
  elseif(action_id == hash("UP_ARROW") and action.pressed == true) then
    if volume <= 1 then
      volume = volume + 0.1
    end
    -- increase the volume of our music
    msg.post("#music","set_gain", { gain = volume })    
  end
end

 

The Video

Programming

23. August 2016

 

Put a hand up if you are sick of reading about these database hacks?  Yeah... me too.  Epic Games just announced that their forums, including the Unreal Engine forums, were the victim of a recent break in.  Thankfully it’s not a huge deal, as password information wasn’t taken.  User information however was taken and could certainly result in a rise in spam... yay.  They don’t however expect you need to change your password on their forums.  If you do however enter proper information when you sign up for forums (date of birth, name, etc.) you may want to be wary of unauthorized activity.  In addition to the Unreal Engine forums, account information for several older Epic developed game forums was also compromised and in these cased, encrypted passwords were also taken.

 

The full details:

We believe a recent Unreal Engine and Unreal Tournament forum compromise revealed email addresses and other data entered into the forums, but no passwords in any form, neither salted, hashed, nor plaintext.  While the data contained in the vBulletin account databases for these forums were leaked, the passwords for user accounts are stored elsewhere. These forums remain online and no passwords need to be reset.

Also, we believe a compromise of our legacy forums covering Infinity Blade, UDK, previous Unreal Tournament games, and archived Gears of War forums revealed email addresses, salted hashed passwords and other data entered into the forums. If you have been active on these forums since July 2015, we recommend you change your password on any site where you use the same password.

We don’t believe that other Epic related forums were affected, including Paragon, Fortnite, Shadow Complex, and SpyJinx.

We apologize for the inconvenience this causes everyone and we’ll provide updates as we learn more.

GameDev News

23. August 2016

 

Another week, another Unity patch, this one 5.3.6p3.  The release notes for this patch follow:

 

Improvements
  • DX11: Improved texture upload performance for compressed, floating point ant RGBA32 formats. (812350)
  • Networking: Ping implementation for ipv6.
  • VR: Update Oculus to version 1.7
  • VR: Update Oculus GearVR to version 1.7.1
Fixes
  • (800914, 802831) - 2D: Fixed an assert message "importer.GetNPOTScale() == TextureImporter::kNPOTKeep" showing when creating sprites in Advance mode. Creating sprites now ignores TextureImporter's non power of two settings if the texture is already a power of two.
  • (811963) - Android: Audio - Fixed glitches on GearVR when Best Latency is selected.
  • (811880) - Android: Fix for crash on returning from Handheld.PlayFullScreenMovie.
  • (769505) - Animation: Fixed an issue where having animations with a mixed number of bones in a controller, and having Write Defaults to false would throw errors.
  • (763293) - AssetBundles: Fixed AssetBundle.LoadFromFile usage with Application.streamingAssetsPath on Android.
  • (none) - Core: Added support for loading serialized files stored with 5.5.0a4.
  • (793567) - Editor: Exceptions from PostProcessBuild callbacks now introduce errors to the build.
  • (808080) - Editor: Fixed crash when trying to connect a GameObject to a prefab with no root GameObject set.
  • (793679) - Graphics: Don't re-upload textures to the graphics device when a quality change is requested and the pixel data is unavailable. This applies to textures loaded from asset bundles unloaded with AssetBundle.Unload (false).
  • (791721) - IL2CPP/Windows Store: Allow non-blocking sockets to work properly on 64-bit builds.
  • (819647) - IL2CPP: Corrected some calls to HasValue on nullable types, which could return true when the nullable does not have a value.
  • (818966) - IL2CPP: Generate proper C++ code for some cases involving array parameters passed by reference.
  • (815722) - IL2CPP: Prevent a stack overflow during code conversion which can occur for mutli-dimensional arrays with generic types.
  • (818102) - IL2CPP: Rename the types.h file to be il2cpp-string-types.h to avoid the possibility of is conflicted with a user-defined header file.
  • (369773) - iOS: Building from GUI now uses a project relative path if the location is under the project folder
  • (790724) - Kernel:Fixed rounding error so Mathf.MoveTowardsAngle always reaches target angle.
  • (735709) - Linux: Fallback to NET_WM_ICON for setting custom player icon.
  • (810289) - Networking: Fixed starting a server cashes on libwebsocket_service_fd.
  • (820523) - OS X: Fixed HTTPS support for WWW/UnityWebRequest when Mac App Store receipt validation is on.
  • (770034) - OSX: Fixed a crash when building for OSX in certain circumstances to do with paths to splash screen and icon.
  • (808187, 790220, 816014) - Prefabs: Fixed some issues and crashes related to undo-ing the creation of prefabs and prefab connections.
  • (none) - Tizen: Fixed a problem with UnityPluginLoad() not working.
  • (none) - UI: Fixed issue with OnPointerEnter event firing after touch ends.
  • (none) - VCS: Stop a C++ method being called during C# constructor and serialization (which is a scripting warning as it is unsafe to do this).
  • (806810) - VR: Fixed different particle shader transparencies between editor and build when splash screen is active.
  • (801951) - Windows Standalone: Custom image will be correctly shown in screen selector dialog when building to directory with non-english letters.
  • (803319) - Windows Standalone: Fixed a regression where "touch up" events would be lost when occurring outside window bounds.

You can download the patch here.

GameDev News

21. August 2016

 

Facebook used to be an absolute powerhouse in the game publishing space before mobile games became so dominant.  Many now gigantic companies like King got their start on Facebook as did many of the most popular mobile IP (Candy Crush, Clash of Kings, etc.)  So it should come as no surprise that Facebook is keen to become a bigger player in the gaming space.  This is doubly true considering their multi-billion dollar purchase of Oculus.  The approach they have taken is however somewhat shocking. 

 

Earlier this year Facebook launched the beta of their Facebook Arcade, a downloadable client for playing several of their most popular games.  It seems that Facebook is intending to morph this service into a more Steam like service.  One part of this strategy is a newly announced partnership with Unity that will enable Unity developers to publish directly to Facebook’s new service.  From the Unity forum:

Sign up to be a closed-alpha partner! Unity is partnering with Facebook to lower the cost and friction of bringing your games cross-platform, with the power to reach over 650 million people who are already playing Facebook-connected games every month. With over $2.5B paid out by Facebook to game developers last year alone, Facebook will be selecting developers building in Unity 5.4 to join as closed-alpha partners to test a new export functionality within the Unity editor. With this new functionality, Unity developers will be able to easily publish their games onto a brand-new Facebook PC gaming distribution platform to help drive additional growth and monetization.
Sign up here (fb.me/FBUnityAlpha) by August 31, 2016 to help us test and provide feedback on an alpha build of the new functionality we're in building into the Unity editor. Don't miss this opportunity to help shape an exciting new venture that we're investing in and reap the benefits of being an early partner*.
* Once selected, closed-alpha partners will need to agree to the the following minimum requirements:

  • Sign a non-disclosure agreement (NDA)
  • Use the alpha build and report bugs in order to help make this a better product
  • Once you've built your game for the new Facebook PC platform, submit it to Facebook for review

Please share any questions you may have in this forum thread.

 

Details of this new service are quite scarce.  Given the requirement to sign an NDA to sign up, it seems likely it will remain that way.  As loathe as I am to link to them (the TMZ of tech “journalism”), TechCrunch currently have the most details available:

Facebook was apprehensive to reveal details about the specs and plans for the PC platform, but here’s what we know from talking with Facebook and Unity:

  • It will run on different types of PCs, not just Windows like the Games Arcade test
  • The desktop platform provides a distraction-free gaming environment uncluttered by other Facebook features like the News Feed
  • It will support the traditional casual Facebook games, mobile games ported from iOS and Android, and Unity says it will likely support more “immersive” hardcore games like you typically see on Steam or consoles, as there’s no plans for a limit on genres or specs right now
  • It will offer discoverability so gamers can find titles to play
  • Facebook will provide a revenue split for game publishers, though it’s unclear if it will deviate from the industry standard 30% it’s used in the past

So basically Facebook appear to be launching their own marketplace to compete with the likes of Steam with both casual games and an eye towards more hardcore games in the future.  If you are interested in signing up you have until the end of August.

GameDev News

21. August 2016

 

LibGDX just released version 1.9.4 composed primarily of bug fixes.  LibGDX is a cross platform Java based 2D/3D game framework.  If you are interested in learning more we did a Closer Look at LibGDX review.  Additionally there is a full tutorial series available both text based and video based.

 

While not exactly a massive release, here are 1.9.4’s release notes: 

 

[1.9.4]
- Moved snapping from ProgressBar to Slider to prevent snapping when setting the value programmatically.
- Bullet: added btSoftBody#getLinkCount() and btSoftBody#getLink(int), see https://github.com/libgdx/libgdx/issues/4152
- API Change: Wrapping for scene2d's HorizontalGroup and VerticalGroup.
- Fix hiero problem with certain unicode characters. See https://github.com/libgdx/libgdx/issues/4202
- Switched to RoboVM fork 2.2.0, fixes incompatibility with Android Gradle plugin and iOS 9.3.4
 

There were several other bug fixes that can be viewed on the Github commits

 

LibGDX is available for download here.

GameDev News

Month List

Popular Comments