├── haptic ├── register_types.h ├── config.py ├── SCsub ├── register_types.cpp └── ios │ └── src │ ├── haptic.h │ └── haptic.mm ├── Example.png ├── .gitignore └── README.md /haptic/register_types.h: -------------------------------------------------------------------------------- 1 | void register_haptic_types(); 2 | void unregister_haptic_types(); -------------------------------------------------------------------------------- /Example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GhostWalker562/Godot-Haptic-Feedback-Module-IOS/HEAD/Example.png -------------------------------------------------------------------------------- /haptic/config.py: -------------------------------------------------------------------------------- 1 | def can_build(platform): 2 | return platform == "iphone" 3 | 4 | def configure(env): 5 | pass 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Godot-specific ignores 3 | .import/ 4 | export.cfg 5 | export_presets.cfg 6 | 7 | # Mono-specific ignores 8 | .mono/ 9 | data_*/ 10 | -------------------------------------------------------------------------------- /haptic/SCsub: -------------------------------------------------------------------------------- 1 | Import('env') 2 | 3 | sources = [ 4 | 'register_types.cpp', 5 | 'ios/src/haptic.mm' 6 | ] 7 | 8 | if (env["platform"] == "iphone"): 9 | env.add_source_files(env.modules_sources, sources) -------------------------------------------------------------------------------- /haptic/register_types.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "register_types.h" 4 | #include "ios/src/haptic.h" 5 | 6 | void register_haptic_types() { 7 | Engine::get_singleton()->add_singleton(Engine::Singleton("Haptic"), memnew("Haptic"))); 8 | } 9 | 10 | void unregister_haptic_types() { 11 | } 12 | -------------------------------------------------------------------------------- /haptic/ios/src/haptic.h: -------------------------------------------------------------------------------- 1 | #ifndef HAPTIC_H 2 | #define HAPTIC_H 3 | 4 | #include "reference.h" 5 | 6 | class Haptic : public Reference { 7 | GDCLASS(Haptic, Reference); 8 | 9 | protected: 10 | static void _bind_methods(); 11 | 12 | Haptic* instance; 13 | 14 | public: 15 | void selection(); 16 | void impact(int feedback_style); 17 | 18 | Haptic(); 19 | ~Haptic(); 20 | }; 21 | 22 | #endif -------------------------------------------------------------------------------- /haptic/ios/src/haptic.mm: -------------------------------------------------------------------------------- 1 | #include "haptic.h" 2 | 3 | #import "app_delegate.h" 4 | #import 5 | 6 | UISelectionFeedbackGenerator* selectionGenerator = NULL; 7 | NSArray* impactGenerator = NULL; 8 | 9 | Haptic::Haptic() { 10 | ERR_FAIL_COND(instance != NULL); 11 | instance = this; 12 | selectionGenerator = [UISelectionFeedbackGenerator new]; 13 | impactGenerator = 14 | @[ 15 | [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleLight], 16 | [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleMedium], 17 | [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleHeavy] 18 | ]; 19 | } 20 | 21 | Haptic::~Haptic() { 22 | instance = NULL; 23 | selectionGenerator = NULL; 24 | impactGenerator = NULL; 25 | } 26 | 27 | void Haptic::selection() { 28 | [selectionGenerator selectionChanged]; 29 | } 30 | 31 | void Haptic::impact(int feedback_style) { 32 | UIImpactFeedbackGenerator *hap = [[UIImpactFeedbackGenerator alloc] init]; 33 | 34 | [hap prepare]; 35 | 36 | if(feedback_style == 0) [hap initWithStyle:UIImpactFeedbackStyleLight]; 37 | 38 | else if(feedback_style == 1) [hap initWithStyle:UIImpactFeedbackStyleMedium]; 39 | 40 | else if(feedback_style == 2) [hap initWithStyle:UIImpactFeedbackStyleHeavy]; 41 | 42 | else [hap initWithStyle:UIImpactFeedbackStyleLight]; 43 | 44 | [hap impactOccurred]; 45 | } 46 | 47 | void Haptic::_bind_methods() { 48 | ClassDB::bind_method(D_METHOD("impact"), &Haptic::impact); 49 | ClassDB::bind_method(D_METHOD("selection"), &Haptic::selection); 50 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Godot Haptic Feedback module - iOS 2 | ========== 3 | 4 | Today, many apps are following a haptic feedback craze, so why not get your hands on the ability to do so? I'm providing a haptic feedback module for Godot, only for iOS. 5 | 6 | For more information of feedback, https://developer.apple.com/documentation/uikit/uifeedbackgenerator 7 | 8 | - [Godot Game Engine](https://godotengine.org/) 9 | 10 | Hello! Thanks for checking out this module, I spent quite a time learning how to make the module so if you would like to lend a few bucks to a young programmer, I'd greatly appreciate it :D 11 | 12 | [Click me to Donate!](https://www.paypal.me/Moonsdontburn) 13 | 14 | How to use 15 | ---------- 16 | 17 | - Download the zip file 18 | - Place the "haptic" directory into your "module" directory in the Godot engine. 19 | - [Export](https://docs.godotengine.org/en/3.1/getting_started/workflow/export/exporting_projects.html) your iOS project normally by using the template provided by Godot themselves. 20 | - Put the template provided into the iOS export and rename it to replace the previous .a file. 21 | ![Export Screenshot](/Example.png "Example Screenshot") 22 | - haptic haptic haptic! 23 | 24 | API Refrence (iOS) 25 | ---------- 26 | The following methods are available: 27 | ``` 28 | # Makes the device trigger a selection feedback 29 | selection() 30 | 31 | # Makes the device trigger a impact feedback 32 | # @param int feedback_style declares the style of feedback, 0 - light, 1 - medium, 2 - heavy 33 | impact(feedback_style) 34 | ``` 35 | Example in GD: 36 | ``` 37 | # Creates an instance of Haptic 38 | var hap 39 | if Engine.has_singleton("Haptic"): 40 | hap = Engine.get_singleton("Haptic") 41 | hap.selection() 42 | ``` 43 | Why not Android? 44 | ----------- 45 | 46 | I currently do not know how to code for Android devices. 47 | 48 | Donate - Thank you! 49 | ----------- 50 | [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.me/Moonsdontburn) 51 | 52 | --------------------------------------------------------------------------------