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

  • Home
  • SEARCH
  • 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 8878341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:41:21+00:00 2026-06-14T19:41:21+00:00

This was my old algorithm def spawn(self): self.position_move() #to adjust when the player is

  • 0

This was my old algorithm

def spawn(self):
    self.position_move() #to adjust when the player is spawned
def position_move(self):
    #gets called everytime the player moves
    camera.x = -object.x+Window.size[0]/2.0
    camera.y = -object.y+Window.size[1]/2.0

It worked well though when I approached a corner, I could see the ‘outside’ of the room.
enter image description here

The whole purpose of my updated algorithm is to prevent seeing the ‘outside’ of the room:

    def spawn(self): #when the player is first spawned
        self.position_move() #to adjust when the player is spawned

    def position_move(self):
            #camera.x = -(top left x corner of camera coordinate)
            #camera.y = -(top left y corner of camera coordinate)
             #room_size= total room (or world) size

        diff=(object.x-Window.size[0]/2)
        if diff<0:
            camera.x = object.x+diff
        else:
            diff=(object.x+Window.size[0]/2)-room_size[0]
            if diff<0:
                camera.x = -object.x+Window.size[0]/2.0
        diff=(object.y-Window.size[1]/2)

        if diff<0:
            camera.y = diff+Window.size[1]/2
        else:
            diff=room_size[1]-(object.y+Window.size[1]/2)

            if diff>0:
                camera.y = -object.y+Window.size[1]/2.0

My idea for the updated algorithm was to translate the camera back into the room by how much it is outside the room. Though my updated algorithm for some reason goes wonky sometimes (flies away, or doesn’t even follow the player).

So yeah, it is a little complicated for what I thought was a simple task. Does anyone know the error is in my algorithm?

(The framework I am using has a coordinate system like this)
enter image description here

  • 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-14T19:41:23+00:00Added an answer on June 14, 2026 at 7:41 pm

    Not sure what the error in your code is (I haven’t really looked), but here’s a straightforward way of bounding the camera to the world:

    # This assumes coordinates refer to the top-left of the desired viewport
    
    # Since this is not the case, first invert the object's y to make it so:
    object_y = room_size[1] - object.y
    
    camera.x = max(0, object.x - window.size[0] / 2)
    camera.y = max(0, object_y - window.size[1] / 2)
    
    if camera.x + window.size[0] > room_size[0]:
        camera.x = room_size[0]  - window.size[0]
    if camera.y + window.size[1] > room_size[1]:
        camera.y = room_size[1]  - window.size[1]
    
    # Again, since you're using bottom-left coordinate system, invert the y:
    camera.y = room_size[1] - camera.y
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using some old C# code (specifically this Fortune's Voronoi graph algorithm ) in
I'm reviewing my old algorithms notes and have come across this proof. It was
I have this old question but no answer works for me from online, the
I have this old Access database (2000 format) which i want to convert to
We have some code kicking around that uses this old internal Sun package for
I need to get the current context given an entity I found this old
Is this faster: $(document.links).filter('a.someClass') than just plain old this: $('a.someClass') ? I don't see
This may be old news but back in March 2009, this article, Model-View-ViewModel In
NOTE: This is an old question and the answers here no longer works (since
I know this is an old question, but I have spend any hours on

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.