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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:39:33+00:00 2026-05-30T22:39:33+00:00

well I have created a game with UIKit and I have somme performance problems

  • 0

well I have created a game with UIKit and I have somme performance problems so I decided to use Cocos2D.I would like to use this code one cocos2D but I can’t manage to do it :

- (CGPoint)randomPointSquare {
CGRect frame = [[self view] frame];

//CGFloat rand_x = ((float)arc4random() / (float)UINT_MAX) * (float)_window.frame.size.width;

NSInteger side = arc4random() / (UINT_MAX/4);
CGFloat offset = 0;

switch(side) {
    case 0: /* top */
        offset = ((float)arc4random() / (float)UINT_MAX) * (float)frame.size.width;
        return CGPointMake(offset, -10);

    case 1: /* bottom */
        offset = ((float)arc4random() / (float)UINT_MAX) * (float)frame.size.width;
        return CGPointMake(offset, frame.size.height-150);

    case 2: /* left */
        offset = ((float)arc4random() / (float)UINT_MAX) * (float)frame.size.height;
        return CGPointMake(-10, offset);

    default:
    case 3: /* right */
        offset = ((float)arc4random() / (float)UINT_MAX) * (float)frame.size.height;
        return CGPointMake(frame.size.width+200, offset);
}
}
-(void) createNewImage {

UIImage * image = [UIImage imageNamed:@"abouffer_03.png"];
imageView = [[UIImageView alloc] initWithImage:image];
[imageView setCenter:[self randomPointSquare]];
}

Can someone try to translate this code to use it in cocos2D.Thank you .Sorry for my english I’m french :/

  • 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-30T22:39:34+00:00Added an answer on May 30, 2026 at 10:39 pm

    You will probably be best off creating a new cocos2d project from the template and then inserting your game logic into the code as needed while translating the view components as needed.

    For example, your UIImage would instead be a CCSprite.

    But you might be better to encapsulate your movement code inside an object that contains a CCSprite so you can then just reuse that object.

    I’d start by creating a new cocos2d project from the template and looking at the hello world example. Then start by adding a CCSprite to that and make it move around a bit. There’s lots of tutorials out there – This for example

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

Sidebar

Related Questions

well i have this messages table with sample values like these: msg_id recipient_id read
Dear all, this is going to be tough: I have created a game object
I'm facing a weird problem in cocos2d for my iPhone game. I have created
Well as I have posted earlier too...I have created a site in two languages.One
i have created an IE band object (toolbar) that is working well. however, when
I have created a QDialog based app using Qt Creator and all is well
Well I have this MySQL stored procedure that I wrote and if I run
I've got a peer to peer iPhone game working pretty well. I've created a
I have used cocos2d c++ to create a small game on my Windows machine.
I have created the game in unity3d IOS. GUI buttons are changed their position

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.