Skip to main content
Hid the last set of backtics
Source Link
Vaillancourt
  • 16.4k
  • 17
  • 56
  • 61

So, II found out the problem The:

The functions in python return NoneNone by default So, so when the while loop turned falseFalse it returned NoneNone thus throwing an error.

import pygame
import json
pygame.init()

c=0
def lcAnim(sfile):
    global c
    with open(sfile) as f:
        data=json.load(f)

    width=data['textureAtlas']['regionWidth']
    height = data['textureAtlas']['regionHeight']
 
    img=pygame.image.load(data['textureAtlas']['texture'])
    if c>=len(data['cycles']['animation0']['frames']):
        c=0
    if c<len(data['cycles']['animation0']['frames']):
        img.set_clip(pygame.Rect(data['cycles']['animation0']['frames'][c-1]*width,animpos*height,width,height))  # Locate the sprite you want
        draw_me = img.subsurface(img.get_clip())  # Extract the sprite you want
        c+=1
        return draw_me
 
```

So, I found out the problem The functions in python return None by default So when the while loop turned false it returned None thus throwing an error

import pygame
import json
pygame.init()

c=0
def lcAnim(sfile):
    global c
    with open(sfile) as f:
        data=json.load(f)

    width=data['textureAtlas']['regionWidth']
    height = data['textureAtlas']['regionHeight']
 
    img=pygame.image.load(data['textureAtlas']['texture'])
    if c>=len(data['cycles']['animation0']['frames']):
        c=0
    if c<len(data['cycles']['animation0']['frames']):
        img.set_clip(pygame.Rect(data['cycles']['animation0']['frames'][c-1]*width,animpos*height,width,height))  # Locate the sprite you want
        draw_me = img.subsurface(img.get_clip())  # Extract the sprite you want
        c+=1
        return draw_me
 
```

I found out the problem:

The functions in python return None by default, so when the while loop turned False it returned None thus throwing an error.

import pygame
import json
pygame.init()

c=0
def lcAnim(sfile):
    global c
    with open(sfile) as f:
        data=json.load(f)

    width=data['textureAtlas']['regionWidth']
    height = data['textureAtlas']['regionHeight']
 
    img=pygame.image.load(data['textureAtlas']['texture'])
    if c>=len(data['cycles']['animation0']['frames']):
        c=0
    if c<len(data['cycles']['animation0']['frames']):
        img.set_clip(pygame.Rect(data['cycles']['animation0']['frames'][c-1]*width,animpos*height,width,height))  # Locate the sprite you want
        draw_me = img.subsurface(img.get_clip())  # Extract the sprite you want
        c+=1
        return draw_me

Source Link

So, I found out the problem The functions in python return None by default So when the while loop turned false it returned None thus throwing an error

import pygame
import json
pygame.init()

c=0
def lcAnim(sfile):
    global c
    with open(sfile) as f:
        data=json.load(f)

    width=data['textureAtlas']['regionWidth']
    height = data['textureAtlas']['regionHeight']
 
    img=pygame.image.load(data['textureAtlas']['texture'])
    if c>=len(data['cycles']['animation0']['frames']):
        c=0
    if c<len(data['cycles']['animation0']['frames']):
        img.set_clip(pygame.Rect(data['cycles']['animation0']['frames'][c-1]*width,animpos*height,width,height))  # Locate the sprite you want
        draw_me = img.subsurface(img.get_clip())  # Extract the sprite you want
        c+=1
        return draw_me

```