Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8015177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:10:41+00:00 2026-06-04T20:10:41+00:00

I’m trying to implement ‘lever’ into my android game, here’s image showing what do

  • 0

I’m trying to implement ‘lever’ into my android game, here’s image showing what do I want, showing how does it work:

1)

enter image description here

2)

enter image description here

I managed to do basic of it by using joint:

final RevoluteJointDef revoluteJointDef = new RevoluteJointDef();
revoluteJointDef.initialize(anchorBody, movingBody, anchorBody.getWorldCenter());
revoluteJointDef.enableLimit = true;
revoluteJointDef.upperAngle = MathUtils.degToRad(40);
revoluteJointDef.lowerAngle = MathUtils.degToRad(-40);
physicsWorld.createJoint(revoluteJointDef);   

And it works, I can move lever stick in left/right direction, and as it should you can not exceed proper angle, so this part is done. But now I’m looking for a way, when execute actions after moving this lever (for example open some doors/gate)

Here’s my basic idea, how to check which part of the stick has been touched by player (left or right) by creating stick’s body with this way:

enter image description here

So explaining, by adding 2 sensors, one on left side and one on right side, so in contact listener I would check which side has been touched.

But still I have no idea how to check if action should be performed, I know I could check on every update if stick angle is 40 or -40, but is it effective way? Or maybe there is better? I will be greatly thankful for any tips! Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T20:10:43+00:00Added an answer on June 4, 2026 at 8:10 pm

    You don’t need to worry about efficiency here, the performance penalty for checking the angle is absolutely negligible. I measured the times needed to get the angle of a Sprite and a Body using the following code snippet:

    double testEnd;
    double testStart;
    testStart = System.nanoTime();
    for (int i = 0; i<1000000; i++) {doStuff()}
    testEnd = System.nanoTime();
    Log.v("speed test", "it takes "+ (testEnd - testStart)/1000000 + " nanoseconds");
    

    So, on Desire Z it takes only 157 ns to find the angle of a Sprite and 393 ns to do the same with Body. It is also much simpler than using contact listeners. Just a side note, the angles of Sprites can be outside of (-360, +360) degrees if you rotate the Sprite.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.