Python Forum
[PyGame] PLEASE HELP! TypeError: unsupported operand type(s) for +: 'pygame.Surface' and 'int'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] PLEASE HELP! TypeError: unsupported operand type(s) for +: 'pygame.Surface' and 'int'
#1
Very new coder here. Line 32 says player = pygame.draw.rect(gDisplay, red, ((gDisplay + playerStartingx),(gDisplay + playerStartingy), 60, 60), 0)
TypeError: unsupported operand type(s) for +: 'pygame.Surface' and 'int'

import pygame
import time
import random
import sys

pygame.init()

#screen variables
sWidth = 1280
sHeight = 720

#colours
red = (255,0,0)
black = (0,0,0)
white = (255,255,255)

#Main mechanics
gDisplay = pygame.display.set_mode((sWidth,sHeight))
clock = pygame.time.Clock()
pygame.display.set_caption('Zube')

def gameStart():

    #Mechanics
    gDisplay.fill(white)
    pygame.display.update()
    clock.tick(60)

    #Shapes and stuff
    playerStartingx = 64
    playerStartingy = 36
    player = pygame.draw.rect(gDisplay, red, ((gDisplay - playerStartingx),(gDisplay - playerStartingy), 60, 60), 0)
    pygame.display.update()

    #Game Loop Variable
    playing = True

    while playing:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()





gameStart()
Reply
#2
gDisplay is an object of type pygame.Surface, you probably meant its width and height
(gDisplay.get_width() - playerStartingx),(gDisplay.get_height() - playerStartingy)
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] Surface and rectangle in pygame Fabrizio_fg 6 2,206 May-27-2023, 09:15 AM
Last Post: Fabrizio_fg
  [PyGame] Pygame is treating blob_group as a surface, when I need it to treat it as a Sprite. Swagford 1 1,277 Jan-24-2023, 09:58 PM
Last Post: metulburr
  Coloring a surface with transparency Sandor 4 2,269 Jan-02-2022, 08:11 AM
Last Post: Sandor
  Drawn line shift when that surface is copied to another in pygame Leo_Red 4 3,293 Feb-11-2021, 06:33 AM
Last Post: Leo_Red
  [PyGame] pygame.Surface.fill help Shemira 3 6,134 Nov-29-2019, 12:01 AM
Last Post: Shemira
  pygame.surface Graham 10 8,341 Nov-29-2018, 04:45 PM
Last Post: nilamo
  [PyGame] TypeError: unsupported operand type(s) for -: 'int' and 'instancemethod' SnekLover123 5 13,164 Oct-05-2017, 07:39 PM
Last Post: SnekLover123
  downloading pygame wheel or MSI type DAS 3 5,977 Jun-09-2017, 02:27 PM
Last Post: DAS

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020