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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:57:52+00:00 2026-05-22T18:57:52+00:00

Am writing a game using cocos 2d which involves lot of Float type properties

  • 0

Am writing a game using cocos 2d which involves lot of Float type properties to determine the vertices(x,y) of my shapes (Square , Triangle). I have a Shape class which simply holds the total number of vertices(int) and the vertices (CGFloat*). I have one more class called ShapeHolder which defines the values for different types of shapes , it has the properties called Shape square; and Shape Triangle. In the ShapeHolder init am storing(hard coding) the vertices information(x,y) as follows , am also printing the values immediately after the definition which works perfectly

          CGPoint _square[] = {
        CGPointMake(100.0f, 100.0f) , 
        CGPointMake(200.0f, 100.0f) , 
        CGPointMake(200.0f, 200.0f) , 
        CGPointMake(100.0f, 200.0f)
    };. 
            square = [[[Shape alloc] initWithVerticesLength: 4] retain];
        square.vertices = _square;
        for (int i = 0; i< square.count; i++) {
            NSLog(@"Init Square Vertices X Y = %f , %f" , square.vertices[i].x ,square.vertices[i].y );
        }
        triangle = [[[Shape alloc] initWithVerticesLength: 3] retain];
        triangle.vertices = _triangle;

The problem am having is on while retrieving the same values in my OpenGL drawing class to render different shapes , here is the code

        allShapes = [[ShapeHolder alloc] init];
        for (int i = 0; i< allShapes.square.count; i++) {
            NSLog(@"Main Square Vertices X Y = %f , %f" , [[allShapes square]vertices][i].x ,[[allShapes square] vertices][i].y );

        }

The value is converted somehow , no idea why please clarify. Am not getting any runtime errors or compile time error which is really bothering my knowledge

Init Square Vertices X Y = 100.000000 , 100.000000 
Init Square Vertices X Y = 200.000000 , 100.000000 
Init Square Vertices X Y = 200.000000 , 200.000000 
Init Square Vertices X Y = 100.000000 , 200.000000 

Main Square Vertices X Y = 100.000000 , 100.000000 
Main Square Vertices X Y = -1.998910 , 0.000000 
Main Square Vertices X Y = 0.000000 , 0.000000 
Main Square Vertices X Y = -1.998912 , 0.000000
  • 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-22T18:57:53+00:00Added an answer on May 22, 2026 at 6:57 pm

    Looks like you are doing a shallow copy of the array pointer for _square. You need to be doing a deep copy of the vertices into a member array in your object.

    The reason your first vertex isn’t being changed is that your class is keeping the pointer to the first point in the array. Subsequent vertices in the array are being reclaimed by the memory manager and reused. Possibly luck too.

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

Sidebar

Related Questions

I'm writing a game which uses a border layout with a JPanel using BorderLayout.CENTER.
I'm writing an iOS game (Using UIView), which has a randomly generated 2D city.
I'm writing a game in C using the Gtk libraries, in which the player
in my spare time I'm engaged with writing a little game using Microsofts XNA
I am writing a small game by using cocos2d. It is a shooting game.
I'm writing an XNA game in C# using the XNA port of Box2d -
I'm writing a game for iPhone, and I want an online leaderboard using mySQL,
I'm writing an iPhone game in objective-C using XCode. I'd like to profile the
I'm writing myself a little game in JavaScript, using jQuery. The game has a
I'm in the process of writing a Java 2D game. I'm using the built-in

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.