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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:06:38+00:00 2026-05-26T21:06:38+00:00

How do I make a infinite/repeating world that handles rotation, just like in this

  • 0

How do I make a infinite/repeating world that handles rotation, just like in this game:

http://bloodfromastone.co.uk/retaliation.html

I have coded my rotating moving world by having a hierarchy like this:

Scene
  – mainLayer (CCLayer)
     – rotationLayer(CCNode)
        – positionLayer(CCNode)

The rotationLayer and positionLayer have the same size (4000×4000 px right now).

I rotate the whole world by rotating the rotationLayer, and I move the whole world by moving the positionLayer, so that the player always stays centered on the device screen and it is the world that moves and rotates.

Now I would like to make it so that if the player reaches the bounds of the world (the world is moved so that the worlds bounds gets in to contact with the device screen bounds), then the world is “wrapped” to the opposite bounds so that the world is infinite. If the world did not rotate that would be easy, but now that it does I have no idea how to do this. I am a fool at math and in thinking mathematically, so I need some help here.

Now I do not think I need any cocos2d-iphone related help here. What I need is some way to calculate if my player is outside the bounds of the world, and then some way to calculate what new position I must give the world to wrap the world.

I think I have to calculate a radius for a circle that will be my foundry inside the square world, that no matter what angle the square world is in, will ensure that the visible rectangle (the screen) will always be inside the bounds of the world square. And then I need a way to calculate if the visible rectangle bounds are outside the bounds circle, and if so I need a way to calculate the new opposite position in the bounds circle to move the world to. So to illustrate I have added 5 images.

Visible rectangle well inside bounds circle inside a rotated square world:
Visible rectangle well inside bounds circle inside a rotated square world

Top of visible rectangle hitting bounds circle inside a rotated square world:
enter image description here

Rotated square world moved to opposite vertical position so that bottom of visible rectangle now hitting bounds circle inside rotated world:
enter image description here

Another example of top of visible rectangle hitting bounds circle inside a rotated square world to illustrate a different scenario:
enter image description here

And again rotated square world moved to opposite vertical position so that bottom of visible rectangle now hitting bounds circle inside rotated world:
And again rotated square world moved to opposite vertical position so that bottom of visible rectangle now hitting bounds circle inside rotated world

Moving the positionLayer in a non-rotated situation is the math that I did figure out, as I said I can figure this one out as long as the world does not get rotate, but it does. The world/CCNode (positionLayer) that gets moved/positioned is inside a world/CCNode (rotationLayer) that gets rotated. The anchor point for the rotationLayer that rotates is on the center of screen always, but as the positionLayer that gets moved is inside the rotating rotationLayer it gets rotated around the rotationLayer’s anchor point. And then I am lost… When I e.g. move the positionLayer down enough so that its top border hits the top of the screen I need to wrap that positionLayer as JohnPS describes but not so simple, I need it to wrap in a vector based on the rotation of the rotationLayer CCNode. This I do not know how to do.

Thank you
Søren

  • 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-26T21:06:39+00:00Added an answer on May 26, 2026 at 9:06 pm

    Like John said, the easiest thing to do is to build a torus world. Imagine that your ship is a point on the surface of the donut and it can only move on the surface. Say you are located at the point where the two circles (red and purple in the picture) intersect:

    Circles on a torus.

    If you follow those circles you’ll end up where you started. Also, notice that, no matter how you move on the surface, there is no way you’re going to reach an “edge”. The surface of the torus has no such thing, which is why it’s useful to use as an infinite 2D world. The other reason it’s useful is because the equations are quite simple. You specify where on the torus you are by two angles: the angle you travel from the “origin” on the purple circle to find the red circle and the angle you travel on the red circle to find the point you are interested in. Both those angles wrap at 360 degrees. Let’s call the two angles theta and phi. They are your ship’s coordinates in the world, and what you change when you change velocities, etc. You basically use them as your x and y, except you have to make sure to always use the modulus when you change them (your world will only be 360 degrees in each direction, it will then wrap around).

    Suppose now that your ship is at coordinates (theta_ship,phi_ship) and has orientation gamma_ship. You want to draw a square window with the ship at its center and length/width equal to some percentage n of the whole world (say you only want to see a quarter of the world at a time, then you’d set n = sqrt(1/4) = 1/2 and have the length and width of the window set to n*2*pi = pi). To do this you need a function that takes a point represented in the screen coordinates (x and y) and spits out a point in the world coordinates (theta and phi). For example, if you asked it what part of the world corresponds to (0,0) it should return back the coordinates of the ship (theta_ship,phi_ship). If the orientation of the ship is zero (x and y will be aligned with theta and phi) then some coordinate (x_0,y_0) will correspond to (theta_ship+k*x_0, phi_ship+k*y_0), where k is some scaling factor related to how much of the world one can see in a screen and the boundaries on x and y. The rotation by gamma_ship introduces a little bit of trig, detailed in the function below. See the picture for exact definitions of the quantities.
    !Blue is the screen coordinate system, red is the world coordinate system and the configuration variables (the things that describe where in the world the ship is). The object
    represented in world coordinates is green.

    The coordinate transformation function might look something like this:

    # takes a screen coordinate and returns a world coordinate
    function screen2world(x,y)
        # this is the angle between the (x,y) vector and the center of the screen           
        alpha = atan2(x,y); 
        radius = sqrt(x^2 + y^2); # and the distance to the center of the screen
    
        # this takes into account the rotation of the ship with respect to the torus coords
        beta = alpha - pi/2 + gamma_ship;
    
        # find the coordinates
        theta = theta_ship + n*radius*cos(beta)/(2*pi);
        phi = phi_ship + n*radius*sin(beta)/(2*pi));
    
        # return the answer, making sure it is between 0 and 2pi
        return (theta%(2*pi),phi%(2*pi))
    

    and that’s pretty much it, I think. The math is just some relatively easy trig, you should make a little drawing to convince yourself that it’s right. Alternatively you can get the same answer in a somewhat more automated fashion by using rotations matrices and their bigger brother, rigid body transformations (the special Euclidian group SE(2)). For the latter, I suggest reading the first few chapters of Murray, Li, Sastry, which is free online.

    If you want to do the opposite (go from world coordinates to screen coordinates) you’d have to do more or less the same thing, but in reverse:

    beta = atan2(phi-phi_ship, theta-theta_ship);
    radius = 2*pi*(theta-theta_ship)/(n*cos(beta));
    alpha = beta + pi/2 - gamma_ship;
    x = radius*cos(alpha);
    y = radius*sin(alpha);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am experimenting with this: http://dev.sencha.com/deploy/ext-4.0.0/examples/grid/infinite-scroll.html I'm trying to make it possible for the
I am attempting to make an infinite world 2d game source for the class
I'm considering trying to make a game that takes place on an essentially infinite
I would like to make a horizontal listbox that could be infinite scrolling (looping
I'm trying to make a PHP script that will take a potentially infinite number
I would like to make an infinite scrolling on a UITableViewController , I'm using
This is purely a theory question, so, given an "infinite" time to make a
I'm attempting to make a class that holds a (in theory) infinite amount of
I'd like to make a delegate that invokes a specific instance method, unfortunately, it
I have 5 pictures inside an infinite scrollView. So in order to make that

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.