Note that there are some explanatory texts on larger screens.

plurals
  1. POError with NPC random movement
    primarykey
    data
    text
    <p>I made part of a game. In the game there is a player and enemies. I decided to add NPC characters to the game which move randomly. The problem is that they do not draw as expected. </p> <p>NPCs do not run as smoothly as the rest of the code. When an NPC moves around it leaves big patches of white where it has been. I think it's the speed of the update but I'm not quite sure. The framerate is roughly 40 fps. I have tried to find a problem in the update function of NPCs but it looks perfectly fine. However, NPCs only stop creating the weird white patches when I exclude the <code>def update(self)</code>. I'm running Window Vista, Python 2.6 and Pygame. Any help is appreciated.</p> <pre><code>class NPC(pygame.sprite.Sprite): change_x = 0 def __init__(self, color, width, height): pygame.sprite.Sprite.__init__(self) self.image = pygame.Surface([width, height]) self.image.fill(white) self.rect = self.image.get_rect() def update(self): self.rect.x += self.change_x speed = 2 Movementlist = ['moveRight', 'moveLeft'] randomMove = random.choice(Movementlist) if randomMove == 'moveRight': self.change_x = -6 * speed elif randomMove == 'moveLeft': self.change_x = 6 * speed </code></pre> <p>Here is the where an NPC is created:</p> <pre><code>if level == 1: npc = NPC(white, 20, 15) npc.rect.x = 400 npc.rect.y = 485 NPC_list.add(npc) all_sprites_list.add(npc) </code></pre> <p>And here's the update: </p> <pre><code>NPC_list.update() </code></pre> <p>The draw commands are here:</p> <pre><code># --- Draw Frame # Set the screen background if level &lt; 5 or level == 5: screen.fill(black) if level == 10: screen.fill(silver) all_sprites_list.draw(screen) # Go ahead and update the screen with what we've drawn. pygame.display.update() # Limit to 40 frames per second clock.tick(40) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload