Add leenkx/Sources/leenkx/logicnode/SetPositionSpeakerNode.hx
This commit is contained in:
		
							
								
								
									
										39
									
								
								leenkx/Sources/leenkx/logicnode/SetPositionSpeakerNode.hx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								leenkx/Sources/leenkx/logicnode/SetPositionSpeakerNode.hx
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,39 @@ | ||||
| package leenkx.logicnode; | ||||
|  | ||||
| #if lnx_audio | ||||
| import iron.object.SpeakerObject; | ||||
| import kha.audio1.AudioChannel; | ||||
| import iron.system.Audio; | ||||
| #end | ||||
|  | ||||
| class SetPositionSpeakerNode extends LogicNode { | ||||
|  | ||||
| 	public function new(tree: LogicTree) { | ||||
| 		super(tree); | ||||
| 	} | ||||
|  | ||||
| 	override function run(from: Int) { | ||||
| 		#if lnx_audio | ||||
| 		var object: SpeakerObject = cast(inputs[1].get(), SpeakerObject); | ||||
| 		if (object == null || object.sound == null) return; | ||||
| 		 | ||||
| 		var positionInSeconds:Float = inputs[2].get(); | ||||
| 		if (positionInSeconds < 0) positionInSeconds = 0;  | ||||
|  | ||||
| 		var volume = object.data.volume; | ||||
| 		var loop = object.data.loop; | ||||
| 		var stream = object.data.stream; | ||||
| 		 | ||||
| 		object.stop(); | ||||
|  | ||||
| 		var channel = Audio.play(object.sound, loop, stream); | ||||
| 		if (channel != null) { | ||||
| 			object.channels.push(channel); | ||||
| 			channel.volume = volume; | ||||
| 			@:privateAccess channel.set_position(positionInSeconds); | ||||
| 		} | ||||
| 		 | ||||
| 		#end | ||||
| 		runOutput(0); | ||||
| 	} | ||||
| } | ||||
		Reference in New Issue
	
	Block a user