Log In  

Is there any way of editing the spritesheet at runtime so that I can use the spritesheet as the save location for a game?

The game consists of a 32x32 grid but each grid can have many states so figured I could store that as binary, but that doesn't really work well with the cart data limitations. So I figured if I can store the information to the spritesheet, I'm just utilising the memory available there but I cant seem to find much documentation on the matter. I know there is sget/sset but when I used that the screen had alternating colour lines appear... (I think I was putting it on the lower half of the spritesheet if that might be part of the issue?)

Maybe a text file would be better?

P#91835 2021-05-12 10:23

are you using the map to display your game?
how much information per cell do you need to store?
32x32 ‘something’ is going to be large quite fast.

to save the cart, look at cstore() in manual

P#91836 2021-05-12 11:32

well I can probably condense the information per cell to less than 16 bits (so 16 colours), so a grid of 32x32 pixels would be plenty, I can always double up and have a second 32x32 grid if I did need extra bits.

ah so I would use sset to set the pixels, then cstore to 'apply that change' to the actual memory so it will be available when the game is next loaded?

P#91838 2021-05-12 11:41

This is what I get when I use this code (the square at the bottom left is drawn programatically while the rest is drawn using map() ):

function save_game()
 for x=0,mapw do
  for y=0,mapw do
   if checkhoed(x,y) then sset(96+x,32+y,2) end
   --other colours for other states
  end
 end
 cstore()
end

my only guess really is that I am possibly trying to edit the shared space in the spritesheet? Clearly I'm misunderstanding how something works here but I'm not entirely sure where

P#91844 2021-05-12 15:49 ( Edited 2021-05-12 15:53)

how are you displaying the map?
are you sure sprites at 96/32 are safe, eg not used by the in-game map?

P#91846 2021-05-12 15:58

The map is populated using mset(), my goal is to save the game using a grid of pixels and then load the game by reading the grid and using mset() and then map() to draw it.

I was previously trying to use MAP(0, 0, 0, 0, 128,64) because the grid was gonna be bigger so Im not sure if it still is trying to share the lower half of the sprite sheet with the map? if so how would I undo that?

EDIT:
I did see that now that Im using cstore() that there is a load of things being drawn to the lower half of the map for some reason. sset() does only affect the sprite sheet right?... maybe I got the coordinates wrong for the map... I may have embarrassed myself :P Ill check!

P#91849 2021-05-12 16:11 ( Edited 2021-05-12 16:16)

The lower half of the map and the lower half of the sprite sheet share the same memory.

P#91856 2021-05-12 18:48

[Please log in to post a comment]