0

In PL class we were asked to make a pacman clone in Gloss, nevertheless I got stuck at making the map.

My approach was taking a .png of the classical pacman first level, and paste it in the render function so I don't need to draw everything by hand.

Nevertheless by doing so, the games lags horribly, I'm assuming that it's because the game renders the map in every step.

Is there some way to just render the map as a background a single time, or avoid the huge lag? Or am I taking a bad approach and it would it be better if I draw the components by hand using the Picture module?

I append the render function just in case I'm wiring it badly:

render :: PacmanGame -> IO Picture
render game = do
  sprite <- fmap (head) (playerSprites $ player game)
  let playerOne = uncurry translate (playerPos $ player game) $ sprite
  map' <- pacmanMap 
  return $ pictures [map', playerOne]

Where pacmanMap :: IO Picture

1 Answers1

0

It looks like you’re reloading the file in every call to render. You need to run the pacmanMap :: IO Picture action once, for example at startup in main; then you can just return the resulting static Picture from your render function. For example, you might store the reference to the current background image in the PacmanGame, or pass it as an additional argument to render.

Jon Purdy
  • 53,300
  • 8
  • 96
  • 166
  • Many thanks! I binded pacmanMap to a variable in Main, then passed that as a parameter to render and the lag went away. This gives me a new perspective when working with bindings. – Daniel Andres Pinto Alvarado Oct 24 '20 at 18:50