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 7716885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:44:40+00:00 2026-06-01T02:44:40+00:00

In my app, I’m the game is set for landscape mode allowing the user

  • 0

In my app, I’m the game is set for landscape mode allowing the user to be able to flip the device with the game auto-rotating to match the angle. When the user tilts the device to its right, the hero will travel to the right, and when tilted to the left, the hero goes left.

I have that part figured out, but the problem comes in when the user flips the iDevice over (because of the headphone jack or placement of the speaker), the app is auto-rotated, but the rollingY is setting the hero’s position.x to be inverted. Tilting left makes hero go right, and tilting right makes hero go left. After looking at the NSLogs of the accelY value when flipping around the iDevice, it doesn’t seem possible to be able to reverse the position.x when rotated?

I guess this is more of a math question.

Here is my code:

-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{
#define kFilteringFactor 0.75
    static UIAccelerationValue rollingX = 0, rollingY = 0, rollingZ = 0;

    rollingX = (acceleration.x * kFilteringFactor) + (rollingX * (1.0 - kFilteringFactor));
    rollingY = (acceleration.y * kFilteringFactor) + (rollingY * (1.0 - kFilteringFactor));
    rollingZ = (acceleration.z * kFilteringFactor) + (rollingZ * (1.0 - kFilteringFactor));

    float accelX = rollingX;
    float accelY = rollingY;
    float accelZ = rollingZ;

    NSLog(@"accelX: %f, accelY: %f, accelZ: %f", accelX, accelY, accelZ);

    CGSize winSize = [CCDirector sharedDirector].winSize;
#define kRestAccelX 0.6
#define kShipxMaxPointsPerSec (winSize.height * 1.0)
#define kMaxDiffX 0.2

#define kRestAccelY 0.0
#define kShipyMaxPointsPerSec (winSize.width * 0.5)
#define kMaxDiffY 0.2

    float accelDiffX = kRestAccelX - ABS(accelX);
    float accelFractionX = accelDiffX / kMaxDiffX;
    float pointsPerSecX = kShipxMaxPointsPerSec * accelFractionX;

    float accelDiffY = -accelY;
    float accelFractionY = accelDiffY / kMaxDiffY;
    float pointsPerSecY = kShipyMaxPointsPerSec * accelFractionY;

    _shipPointsPerSecX = pointsPerSecY;
    _shipPointsPerSecY = pointsPerSecX;

    CCLOG(@"accelX: %f, pointsPerSecX: %f", accelX, pointsPerSecX);
    CCLOG(@"accelY: %f, pointsPerSecY: %f", accelY, pointsPerSecY);
}

-(void)updateShipPos:(ccTime)dt
{
    CGSize winSize = [CCDirector sharedDirector].winSize;

    float maxX = winSize.width - _ship.contentSize.width;
    float minX = _ship.contentSize.width / 2;

    float maxY = winSize.height - _ship.contentSize.height / 2;
    float minY = _ship.contentSize.height / 2;

    float newX = _ship.position.x + (_shipPointsPerSecX * dt);
    float newY = _ship.position.y + (_shipPointsPerSecY * dt);

    newX = MIN(MAX(newX, minX), maxX);
    newY = MIN(MAX(newY, minY), maxY);

    _ship.position = ccp(newX, newY);
}

The idea is, I’m trying to make it so that pointsPerSecY is positive when tilting to the right and negative when tilted to the left. The problem is when the user flips the device, they are inverted since the device is flipped. Is there a way to make it so that it will stay positive when tilted to the right and negative to the left, no matter the orientation, when flipped while being in landscape?

  • 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-01T02:44:41+00:00Added an answer on June 1, 2026 at 2:44 am

    How about to do something like this?

    if ([[UIApplication sharedApplication] statusBarOrientaion]==UIInterfaceOrientationLandscapeLeft) {
        pointsPerSecY *= -1;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My app is fixed to landscape mode, yet during viewDidLoad() and even viewWillAppear(), the
My app is set to run on minSdk = 5, but the vast majority
app.get('/',function(req,res){ res.render('home'); // I want the template to be able to access the flash
My app crashes when I do [self.navigationController popViewControllerAnimated:YES]. It crashes more on Device than
The app I'm developing needs to be able to pull from several different data
App having screen1, screen2, screen3 , screen4 user can go to screen3 from remaining
App Crashes throwing exception while launching: java.lang.UnsupportedOperationException: Device does not have package com.google.android.gsf What
My app only allows access if the current user is a specific type, this
App Engine provides a way to set the current namespace . Is this a
My app needs to be able to disconnect from a server and connect to

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.