建立在非活动类的振动? [英] Creating a vibration in a non-activity class?

查看:134
本文介绍了建立在非活动类的振动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建我的游戏(Android版)的振动,基本上我想,当碰撞发生时,开始振动,而是因为在我的水平运行类不是一个类的活动我无法创建它,我不知道豪着手,我应该怎么办?谢谢你。

I am trying create a vibration for my game(Android), basically I want a vibration to start when a collision happens, but I can't create it because the class in which my level is running is not an activity class and I don't know ho to proceed, what should I do ? Thanks.

推荐答案

但你的类要创建它应该从右活动被称为?再有就是没有问题的继续像活动课做了震动:

But your class that wants to create it should be called from an activity right? Then there is no problem to proceed like a vibration done in Activity Class:

public function vibrate(Context context){
    // Get instance of Vibrator from current Context
    Vibrator v = (Vibrator) getSystemService(context);

    // Vibrate for 300 milliseconds
    v.vibrate(300);
}

这篇关于建立在非活动类的振动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆