Log In  

I'm modifying a 3D raytracing demo to make an engine, and I was doing pretty well until i came to the realisation: I had a limited amount of tiles. Basically, in the way that the original programmer, @Hiinds , designed it, only the top half of only the first page of the spritesheet is available for use. So, basically, what I was thinking is I could use the rest of the spritesheet, and when I no longer needed a certain texture but did need another, I could copy one of the textures into one of the usable slots. What I need is a method to copy a certain part of the spritesheet onto another. How do I do this (if possible)?

P#85115 2020-12-07 15:10

good idea indeed - look at memcpy&poke variants in the manual.

P#85144 2020-12-08 06:56

Before the main cls() in your _draw function, you can use
memcpy(0x6000,0,0x1fff)

To copy the entire sprite sheet to the screen, do whatever you want to it there such as say, draw a sprite on screen with spr() to copy a tile there, or whatever else you want to do, and then, when you're done
memcpy(0,0x6000,0x1fff)

To copy it all back. There's some caveats of course, you can only run it before the rest of your drawing code so no switching things up mid-frame. It also still writes directly to the shared ram for the second half, so if you need the map data that's there you'll need to copy it to a table beforehand. From there you can either adapt your code to use the table, or copy that table back to ram every frame and then copy the sprite again every frame. Those approaches each have their own problems, though.

Credit to @sol for teaching me this, it's a neat trick. It's good for animating map tiles and such too.

P#85164 2020-12-08 20:13

@Spaz48 Thanks! The map thing shouldn't be a problem because the map I made is actually quite small, so this should actually be a very good solution!

Cheers.

P#85201 2020-12-09 18:17

So, it doesn't appear to work after all. Maybe it is because for both copying on and back to the sprite sheet uses the same memcpy code thing? I'm not entirely familiar with using that API call, but I think I may be right.

P#85204 2020-12-09 18:54

@wallgraffiti Here's a simple little example cart that should hopefully make things a little more clear.

Cart #gasomisiki-0 | 2020-12-09 | Code ▽ | Embed ▽ | No License

Note that the first one is "0x6000,0" and the second one is "0,0x6000", they're different. It'd be more clear to write "0x6000,0x0000" and "0x0000,0x6000" and those work too, but it's more text for the same thing, really.

P#85213 2020-12-09 22:28 ( Edited 2020-12-09 22:28)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-29 05:23:01 | 0.048s | Q:22