Haptic Feedback For Buildbox 3

Discussion in 'How Can I...?' started by itzonator, Jun 28, 2019.

?

Do you know what's Haptic Feedback?

  1. Hap, what?

    1 vote(s)
    25.0%
  2. Yes, that's related to ... Apple

    2 vote(s)
    50.0%
  3. Yes I know, but it's a secret.

    0 vote(s)
    0.0%
  4. Android has this, right?

    1 vote(s)
    25.0%
  1. itzonator

    itzonator Avid Boxer

    Joined:
    Dec 18, 2017
    Messages:
    433
    Likes Received:
    141
    Hey boxers,

    There are few folks here in the forum that managed to do this Haptic Feedback feature (phone vibrates after a trigger). I've been looking to do something like this but for Buildbox 3.

    For instance, after a point / coin collect the haptic feedback (phone vibration) to trigger. Any ideas how to do this with nodes? Or we have to use custom code for that on the already exported project for Xcode as that's native to iOS?

    https://www.appcoda.com/haptic-feedback/

    Best,
    Itzo
     
  2. itzonator

    itzonator Avid Boxer

    Joined:
    Dec 18, 2017
    Messages:
    433
    Likes Received:
    141
    @Vikas has a nice solution for Haptic Feedback, but when a button is pressed on a UI the device vibrates and this would work for BB2 as well as BB3 games. But I do not need it when a button is pressed on UI, but when:

    If Collide with Actor -> Add Point + 1
    If Collide with Actor -> Haptic Feedback (Vibrate)

    So this can be done with nodes. Partially the @Vikas solution would work, as he's using Custom Navigation button to enable/disable Haptic feedback on device - which is great because it's huge battery drainer.

    @rizwanashraf shared a code like this:

    Code:
    if ( value ) {
    system.sendHapticFeedback(2);
    }
    But how to put it all together?

    @weboha - you got this right?

    @rizwanashraf if I do this (edited the Add Point Node):
    Code:
    if(value){
            let amount = this.attribute('Amount');
            this.scene().addScorePoint( amount );
            system.sendHapticFeedback(2);
        }
    Will it work? Where 2, stands for 2nd level of intensity or something... @weboha what's your value for best results 2 or something else? I am asking because I do not have a device that can test this Haptic Feedback properly, as I am using iPhone 6+ and from a hardware point of view that's missing, yeah I know I have to upgrade :p :D

    On BB3 previewer, I get
    ReferenceError: system is not defined -> every time point is +1 (added), when I have system.sendHapticFeedback(2); on Add Point node? Is that normal since the previewer is not a device? If not, how do we define the system in sendHapticFeedback?

    On Xcode, iPhone6+ Device, I get:
    [PTPlayer] - JS Error [asset: Actor, component: Add Point, line: 12] - ReferenceError: system is not defined -> when a point is added. The point is added correctly to score, but this error is due to the Haptic Feedback system.
     

    Attached Files:

    • API.png
      API.png
      File size:
      30.4 KB
      Views:
      13
    Last edited: Jun 28, 2019
    Blacklist likes this.
  3. weboha

    weboha Avid Boxer

    Joined:
    Aug 8, 2018
    Messages:
    221
    Likes Received:
    163
    yes this code is work for haptic. I used my game. just add when you want to use.
    this code should be work:

    if(value){
    let amount = this.attribute('Amount');
    this.scene().addScorePoint( amount );
    System.sendHapticFeedback(1);
    }
     
    Blacklist and itzonator like this.
  4. itzonator

    itzonator Avid Boxer

    Joined:
    Dec 18, 2017
    Messages:
    433
    Likes Received:
    141
    Thanks man, why did you put intensity of 1, instead of 2?

    When I have this code inside the IF statement, I get this error is console each time coin/point is collected:

    ReferenceError: system is not defined

    and

    this error is Xcode: [PTPlayer] - JS Error [asset: Actor, component: Add Point, line: 12] - ReferenceError: system is not defined


     
  5. itzonator

    itzonator Avid Boxer

    Joined:
    Dec 18, 2017
    Messages:
    433
    Likes Received:
    141
    I see now the issue:

    You have:

    Code:
    System.sendHapticFeedback(1); 
    I have:

    Code:
    system.sendHapticFeedback(1);
    it should be System. instead of system. this capital letter is messing the whole thing and system is not defined if it is with small letter 's'



     
  6. weboha

    weboha Avid Boxer

    Joined:
    Aug 8, 2018
    Messages:
    221
    Likes Received:
    163
    haha yes a small step for a man a giant leap for Buildbox ;)
     
    itzonator likes this.
  7. itzonator

    itzonator Avid Boxer

    Joined:
    Dec 18, 2017
    Messages:
    433
    Likes Received:
    141
    Tell me about it, took me 4 hours to figure out. :D
     
  8. itzonator

    itzonator Avid Boxer

    Joined:
    Dec 18, 2017
    Messages:
    433
    Likes Received:
    141
    @weboha when implemented this Haptic Feedback for points, have you made any Turn oN/ Off button for Haptic Vibrations? Or there's not an option to disable Haptic Feedback on your game - in Settings maybe?
     
  9. weboha

    weboha Avid Boxer

    Joined:
    Aug 8, 2018
    Messages:
    221
    Likes Received:
    163
    there is no close button, but you can make. I added a buton to ui.
    when u click button I changed global var like Settings.haptic=1;
    u can add a if code, if (Settings.haptic==1)
     
    itzonator likes this.
  10. itzonator

    itzonator Avid Boxer

    Joined:
    Dec 18, 2017
    Messages:
    433
    Likes Received:
    141
    Interesting, can you provide all the code you did to disable haptic feedback on button press. Was it a navigation button on the UI?
     
  11. weboha

    weboha Avid Boxer

    Joined:
    Aug 8, 2018
    Messages:
    221
    Likes Received:
    163
    yes I added a buton on ui, when you click I change a global var.
     

Share This Page