Save
Saving
  • T
    tienery

    Thank you for your response. I will convert my audio files to wave files instead and see what happens.

    I suppose using Assets.loadSound would be more appropriate.

    posted in Kode read more
  • T
    tienery

    Hello everyone.

    I am attempting to play sound from a kha.Blob using the kha.audio2.SoundChannel class but I keep getting errors when trying to load it.

    I have a simple AudioPlayer class in my code to handle separate channels such as music, sound effects and voice overs, but I am having trouble loading the assets.

    I have just over 2000 assets being exported via HTML5 and debugging on Linux (elementary OS, based on Ubuntu 18.04) and using the latest version of Kode Studio for the platform. This works fine, but the code itself does not seem to operate.

    I have the following code:

    audioPlayer = new AudioPlayer();
    audioPlayer.playMusic(Assets.blobs._53223_ogg);
    

    The AudioPlayer class is as follows:

    package;
    
    import kha.Blob;
    import kha.audio2.StreamChannel;
    
    class AudioPlayer
    {
    
    	private var _musicChannel:StreamChannel;
    
    	private var _playingMusic:Int;
    	private var _loop:Bool;
    
    	public function new()
    	{
    
    	}
    
    	public function playMusic(id:Blob)
    	{
    		_musicChannel = new StreamChannel(id.toBytes(), true);
    		_musicChannel.volume = 0.5;
    		_musicChannel.play();
    	}
    
    }
    

    When running this code, I get the following error:

    TypeError: Cannot read property 'toBytes' of null
    SystemImpl.hx:55
        at AudioPlayer.playMusic (/media/luke/Data/Projects/Haxe/Games/Open WoW/Source/AudioPlayer.hx:24:37)
        at Function.Game.init (/media/luke/Data/Projects/Haxe/Games/Open WoW/Source/Game.hx:33:3)
        at /media/luke/Data/Projects/Haxe/Games/Open WoW/Source/Main.hx:18:13
        at /home/luke/Documents/GitHub/Core/twinspire/Application.hx:127:5
        at Function.kha_SystemImpl.initSecondStep (/home/luke/Documents/Kode Studio/resources/app/kodeExtensions/kha/Kha/Backends/HTML5/kha/SystemImpl.hx:88:3)
        at /home/luke/Documents/Kode Studio/resources/app/kodeExtensions/kha/Kha/Backends/HTML5/kha/SystemImpl.hx:74:4
    

    This, to me, means that the resource can't be read despite Kha being able to pick up the asset at compile time (it shows up in auto-completion), so I am utterly confused why this isn't working.

    I've tried multiple different methods, such as Assets.loadBlob and Assets.loadBlobFromPath and none appear to work.

    The Assets.loadBlob doesn't produce a console error but doesn't play the ogg file:

    Assets.loadBlob("_" + id + "_ogg", function(data:Blob)
    		{
    			_musicChannel = new StreamChannel(data.toBytes(), true);
    			_musicChannel.volume = 0.5;
    			_musicChannel.play();
    		});
    

    Using Assets.loadEverything is just far too slow to use launch and test the application with the number of assets that exist.

    Is there something I'm doing wrong?

    posted in Kode read more
  • T
    tienery

    I've recently created a 2D game engine based on Kha, which is here:

    https://github.com/twinspire/Twinspire

    posted in Kode read more