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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:44:37+00:00 2026-06-13T15:44:37+00:00

I am developing a game that uses the gyroscope to keep enemies in relatively

  • 0

I am developing a game that uses the gyroscope to keep enemies in relatively the same place, with the following code:

if([motionManager isGyroAvailable])
{
    [motionManager setGyroUpdateInterval:0.05];

    [motionManager startGyroUpdatesToQueue:[NSOperationQueue mainQueue]
                               withHandler:^(CMGyroData *gyroData, NSError *error)
     {
         valueX3 = gyroData.rotationRate.y* 50;
         valueY3 = gyroData.rotationRate.x* 50;

         int newX3 = (int)(enemyufoG.center.x +valueY3);
         int newY3 = (int)(enemyufoG.center.y -valueX3);

         CGPoint newCenter2 = CGPointMake(newX3, newY3);

         enemyufoG.center = newCenter2;

         valueX2 = gyroData.rotationRate.y* 50;
         valueY2 = gyroData.rotationRate.x* 50;

         int newX2 = (int)(enemyufoR.center.x +valueY2);
         int newY2 = (int)(enemyufoR.center.y -valueX2);

         CGPoint newCenter = CGPointMake(newX2, newY2);

         enemyufoR.center = newCenter;

         valueX = gyroData.rotationRate.y* 50;
         valueY = gyroData.rotationRate.x* 50;

         int newX = (int)(enemyAlien.center.x +valueY);
         int newY = (int)(enemyAlien.center.y -valueX);

         CGPoint newCenter3 = CGPointMake(newX, newY);

         enemyAlien.center = newCenter3;
     }];
}

Once you shoot an enemy that is in the crosshairs of the gun, it hides the UIImageView, then uses NSTimer to call a different method that shows it again. I would like to have the enemies reappear in random positions on the screen.

CGPoint pos = enemyAlien.center;

if ((pos.x > 254) && (pos.x < 304) && (pos.y > 140) && (pos.y < 160 && _ammoCount != 0))
{
    enemyAlien.hidden = YES;
    [dangerBar setProgress:dangerBar.progress-0.10];
    _killCount = _killCount+3;
    [killCountField setText: [NSString stringWithFormat:@"%d", _killCount]];

    timer = [NSTimer scheduledTimerWithTimeInterval: 4.0
                                             target: self
                                           selector: @selector(showAlien)
                                           userInfo: nil
                                            repeats: NO];
}

- (void) showAlien {

enemyAlien.hidden = NO;

}

When I try and use enemyAlien.center = enemyAlien.center + arc4random()%100; above enemyAlien.hidden = NO, I get the following error:

'Invalid operands to binary expression ('CGPoint (aka 'struct CGPoint') and 'unsigned int').

  • 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-13T15:44:38+00:00Added an answer on June 13, 2026 at 3:44 pm

    You’re trying to add an integer to a cgpoint.
    try this.

    enemyAlien.center = CGPointMake(enemyAlien.center.x + (arc4random()%100),enemyAlien.center.y + (arc4random()%100));
    

    although this will only move the alien in a diagonal direction. You should probably change it to the following for a better experience.

    enemyAlien.center = CGPointMake((arc4random()%SCREEN_WIDTH),(arc4random()%SCREEN_HEIGHT));
    

    where SCREEN_WIDTH and SCREEN_HEIGHT are the dimensions of your playing field.

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

Sidebar

Related Questions

I have a C# game program that i'm developing. it uses sound samples and
I am developing an iPad game that uses cocos2d and requires a virtual joystick.
I'm developing a card game that uses rummy-style sets of three cards. From a
I am developing game editor in C# that uses c++ lib files. I want
I am developing a game that uses a different controller for each level. It
I am developing a live-action tag game (called DeTag) that uses a web interface
I'm developing an Android game that uses the orientation sensor to get the rotation
I am developing a pyramid game that uses a Minimax tree that searches for
I'm developing an android game that uses a surface view for representing the ui
I am developing a project that uses mp3 and .lrc file for my game

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.