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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:14:53+00:00 2026-05-18T20:14:53+00:00

I have 2 pygame surfaces (technically subsurfaces) and I need to test for their

  • 0

I have 2 pygame surfaces (technically subsurfaces) and I need to test for their equality.

Here’s my code:

actor.display(mockSurface, Rect((0, 0, 640, 640)))
assert actor.image == actor.spriteSheet.subsurface(Rect((0, 30, 30, 30)))

And here’s the code behind actor.display:

def display(self, screen, camera_location):
    self.image = self.spriteSheet.subsurface(Rect((0, 30, 30, 30)))
    screen.blit(self.image, (0, 0))

Now here’s the error I get from that assertion line:

>           assert teste.image == teste.spriteSheet.subsurface(Rect((0, 30, 30, 30)))
E           assert <Surface(30x30x32 SW)> == <Surface(30x30x32 SW)>
E            +  where <Surface(30x30x32 SW)> = <actor.Actor instance at 0x2f78ef0>.image
E            +  and   <Surface(30x30x32 SW)> = <Surface(120x90x32 SW)>.subsurface(<rect(0, 30, 30, 30)>)
E            +    where <Surface(120x90x32 SW)> = <actor.Actor instance at 0x2f78ef0>.spriteSheet
E            +    and   <rect(0, 30, 30, 30)> = Rect((0, 30, 30, 30))

These should be equal (am I wrong), but by some sneaky snake trick the assertion fails.

  • 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-18T20:14:53+00:00Added an answer on May 18, 2026 at 8:14 pm

    Use Surface.get_offset() and Surface.get_parent() to determine whether both subsurfaces point to the same area of their parent surface.

    >>> parent = pygame.image.load("token1.png")
    >>> parent
    <Surface(128x128x32 SW)>
    >>> s1 = parent.subsurface(pygame.Rect(0, 0, 2, 2))
    >>> s2 = parent.subsurface(pygame.Rect(0, 0, 2, 2))
    >>> s1
    <Surface(2x2x32 SW)>
    >>> s2
    <Surface(2x2x32 SW)>
    >>> s1 == s2
    False
    >>> s1.get_parent() == s2.get_parent()
    True
    >>> s1.get_offset() == s2.get_offset()
    True
    >>> s1.get_parent() == s2.get_parent() and s1.get_offset() == s2.get_offset()
    True
    

    Both s1 and s2 refer to different objects thus are not equal.

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

Sidebar

Related Questions

I have 2 pygame surfaces (technically subsurfaces) and I need to test for their
I have installed python 2.6.6 and pygame 2.6 from here: http://pygame.org/ftp/pygame-1.9.1.win32-py2.6.msi However, when I
I have the following Python (3.2) code: from pygame import * class Application: def
I posted this on the pygame mailing list but maybe someone here will have
I have to know what key is pressed, but not need the code of
I have used PyGame for a while now, and quite enjoyed doing so, but
So with pygame you have a while loop that loops continuously, then your event
I have a customized version of SDL 1.2 and pygame 1.9.1 that implement SDL2's
I'm working on a pygame project and have the main engine layed out. The
I'm trying to learn pygame, And I found the best way to have the

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.