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

  • Home
  • SEARCH
  • 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 8446151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:51:10+00:00 2026-06-10T09:51:10+00:00

public void onControlChange(final BaseOnScreenControl pBaseOnScreenControl, final float pValueX, final float pValueY) { final Body

  • 0
public void onControlChange(final BaseOnScreenControl pBaseOnScreenControl, final float pValueX, final float pValueY) {
            final Body carBody = CityRacerActivity.this.mCarBody;

            final Vector2 velocity = Vector2Pool.obtain(pValueX * 5, pValueY * 5);
            carBody.setLinearVelocity(velocity);
            Vector2Pool.recycle(velocity);

            final float rotationInRad = (float)Math.atan2(-pValueX, pValueY);
            carBody.setTransform(carBody.getWorldCenter(), rotationInRad);

            CityRacerActivity.this.mCar.setRotation(MathUtils.radToDeg(rotationInRad));
        }

So this works partially.

OnControlChange moves the sprite in the correct direction but when I let go to the controls it seems to move the vehicle facing upwards everytime.

I’m on android using andengine.

My code is based off of the racergameactivity example but this error seems to already exist withen the example itself.

  • 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-10T09:51:12+00:00Added an answer on June 10, 2026 at 9:51 am
            public void onControlChange(final BaseOnScreenControl pBaseOnScreenControl, final float pValueX, final float pValueY) {
                final Body carBody = CityRacerActivity.this.mCarBody;
    
                final float rotationInRad = (float)Math.atan2(-pValueX, pValueY);
    
                if ((pValueX == 0) && (pValueY == 0))
                {
                        //Don't turn the body/sprite of the car
    
    
                }else
                {
                        carBody.setTransform(carBody.getWorldCenter(), rotationInRad);
                        //turn the car body in the direction of movement
                        CityRacerActivity.this.mCar.setRotation(MathUtils.radToDeg(rotationInRad));
                }
    
                //set the velocity
                final Vector2 velocity = Vector2Pool.obtain(pValueX * 5, pValueY * 5);
                carBody.setLinearVelocity(velocity);
                Vector2Pool.recycle(velocity);
            }
    

    This works like I wanted but I’m not sure if this is the way I should handle it.

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

Sidebar

Related Questions

public void createpass() { //set up dialog final Dialog dialog = new Dialog(App.this); dialog.setContentView(R.layout.createpass);
public void openOptions() { Intent intent=new Intent(this,Game.class); //intent.putExtra(razmer, level); startActivity(intent); // Intent intent=new Intent(this,Options.class);
public void onClick(View v) { switch(v.getId()){ case R.id.save2: s = text.getText().toString(); number = Float.parseFloat(num.getText().toString());
public void onClick(View v) { switch(v.getId()){ case R.id.save2: s = text.getText().toString(); number = Float.parseFloat(num.getText().toString());
public void consumeResponse(OmwListResponse<T> response) { synchronized (response.getResultList()) { // XXX this isn't synchronized safely
public void button2_Click(object sender, System.EventArgs e) { string text = textBox1.Text; Mainform = this;
public void responsePost(Editable editable) { TableLayout chatbox = (TableLayout)findViewById(R.id.chatbox); TableRow tr1 = new TableRow(this);
public void ReplyMessage(string subject, string body, string to) { EmailMessage message = new EmailMessage(service);
public void onBackPressed() { Intent setIntent = new Intent(this,xxxxx.class); startActivity(setIntent); return; } I call
public void onCreate(Bundle savedInstanceState) { teachersData=new TeachersData(this); super.onCreate(savedInstanceState); setContentView(R.layout.main); ArrayList<Data> classid=teachersData.listClass(); ArrayAdapter<Data> adapter =

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.