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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:05:36+00:00 2026-05-30T17:05:36+00:00

I’m taking waaaayyy more classes than I normally do this semester and just haven’t

  • 0

I’m taking waaaayyy more classes than I normally do this semester and just haven’t had the time to play with objective c and make it my own, this all still feels very foreign to me and I’m having a lot of trouble doing something that I know should be fairly simple.

But basically what i have is a 6 piece mosaic puzzle that the pieces go back to the same place when the puzzle is restarted. I’m trying to swap the origin of each piece with that of another piece in a random way every time the puzzle is restarted. So I’m trying to randomize the CGRect values assigned to NSValue objects in an array, declared as such:

@synthesize topLeft;
@synthesize topMiddle;
@synthesize topRight;
@synthesize bottomLeft;
@synthesize bottomMiddle;
@synthesize bottomRight;
@synthesize scoreLabel;

topLeftRectOrigin=[NSValue valueWithCGRect: topLeft.frame];
topMiddleRectOrigin=[NSValue valueWithCGRect: topMiddle.frame];
topRightRectOrigin=[NSValue valueWithCGRect: topRight.frame];
bottomLeftRectOrigin=[NSValue valueWithCGRect: bottomLeft.frame];
bottomMiddleRectOrigin=[NSValue valueWithCGRect: bottomMiddle.frame];
bottomRightRectOrigin=[NSValue valueWithCGRect: bottomRight.frame];

puzzlePieces=[[NSMutableArray alloc]initWithObjects:topLeft, topMiddle, topRight, bottomLeft, bottomMiddle, bottomRight, nil];
puzzleOrigins=[[NSMutableArray alloc]initWithObjects:topLeftRectOrigin, topMiddleRectOrigin, topRightRectOrigin, bottomLeftRectOrigin, bottomMiddleRectOrigin, bottomRightRectOrigin, nil];

topLeftRectGrid=CGRectMake(145, 95, 30, 30);
topMiddleRectGrid=CGRectMake(235, 95, 30, 30);
topRightRectGrid=CGRectMake(325, 95, 30, 30);
bottomLeftRectGrid=CGRectMake(145, 185, 30, 30);
bottomMiddleRectGrid=CGRectMake(235, 185, 30, 30);
bottomRightRectGrid=CGRectMake(325, 185, 30, 30);

I’m really having trouble getting my brain around this, can you guys recommend how I should go about doing this? Much thanks for the help.

  • 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-05-30T17:05:37+00:00Added an answer on May 30, 2026 at 5:05 pm

    Update: You might wanna reformulate your question. I understood it as you wanting to change the origin of two objects inside your array without changing their positions in the array, ElJay gave a great solution in case you want to swap the array positions. Clarification might help just so we know what to help with! 😀

    I encountered a similar situation in a recent project of mine.

    You have an NSMutableArray with 6 elements in it, now obviously you don’t want to change the order of the items but instead their origin. Here’s a solution I think will help you for your case:

    1. Generate two random numbers from 0-5 (your array indexes) to represent 2 different items (pieces) of your array.
    2. Via a switch statement, acquire the origin each piece corresponding to the randomly generated indexes.
    3. Once again via a switch statement, set the new origins you acquired for the pieces corresponding to the randomly generated indexes.

    This is what I did, I basically had to animate swapping the position of a few images randomly. I just acquired 2 different numbers randomly, retrieved the center corresponding to each of these items and then inverted the centers on each.

    I got a smooth animation and it’s all randomly generated at runtime 🙂

    Hope this helps, feel free to ask more questions or comments (:

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.