News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_Kitsune Mifune

Best way to clean up sprite trails

Started by Kitsune Mifune, 10:37, 28 November 20

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Kitsune Mifune

Hi all!


I'm trying to dip my toe back into Z80 assembly again and I'm doing a very simple one screen platform game just to get the hang of core techniques. My player sprite works fine, but as it's the only thing on the screen atm and is just writing directly to the screen memory at &C000, it's leaving behind the previous draws/frames on the screen, and I was wondering what would be the best way to solve this?

I thought about storing the sprite's previous position and then just erasing that part of the screen within the draw routine (it's just a 16x16 sprite) but I'd rather get some directions from experts before wandering down a rabbit hole that might not be the best way.

I'll likely be adding backgrounds later so perhaps it would be a case of just using them to "clean up" the screen? If so, would it be wiser to construct the background once using a tilemap then store a copy of that whole constructed screen somewhere to draw instead of repeating the entire tile fetch/draw routine for every frame (I can see this slowing things down)?

I know this is really two questions, but they are linked. I tried searching for something on this topic but I couldn't find much, although I may have been using wrong terminology, so apologies if this has already been answered.

Thank you.
Unlocking the dark arts of assembly!

reidrac

It depends on the project and your engine.

In case it helps, this is what I usually do:

I store a description of the screen, which is usually a matrix of width x height in tile indexes, and a tile is a block of i x j (say 8x8). That information is used for two things: collision detection (e.g. if tile index is > K, then is a solid tile), and drawing the screen (get tile index, go to the tile data and draw that tile).

Then you have a draw screen function that draws the complete screen and an erase sprite function that given an x, y position and knowing the dimensions of the sprite, can calculate what tiles need to be drawn again on the screen, erasing the sprite.

So your game loop can be something like this:

draw map
game loop:
  draw entities
  update entities (will update position)
  erase entities old position


So if your sprite is 8x16 (common in mode 0), you will erase 2 tiles if the sprite was tile aligned, or 6 tiles in worst case (both x and y unaligned).

You need to do this fast enough so you don't have flickering, or have some sort of back buffer strategy.

Again, it depends on the project. This is a sprite/tile engine. If your background is not tile based, you could also grab the background before drawing the sprite, so you can erase it later.
Released The Return of Traxtor, Golden Tail, Magica, The Dawn of Kernel, Kitsune`s Curse, Brick Rick and Hyperdrive for the CPC.

If you like my games and want to show some appreciation, you can always buy me a coffee.

Kitsune Mifune

Thank you, that's good info to chew on.

So you are just constructing the screen pre-loop, and only updating what tiles need to be redrawn as and when is needed? I can see how that would be very efficient.

I have a background tile paster, although it's a little crude it does work, so I could probably adapt that.

Thanks again.
Unlocking the dark arts of assembly!

reidrac

Quote from: Kitsune Mifune on 12:28, 28 November 20
So you are just constructing the screen pre-loop, and only updating what tiles need to be redrawn as and when is needed? I can see how that would be very efficient.

Exactly. It all can be simplified as: go as fast as you can.

How? Both using tricks to do what you need to do but faster and by doing less things.
Released The Return of Traxtor, Golden Tail, Magica, The Dawn of Kernel, Kitsune`s Curse, Brick Rick and Hyperdrive for the CPC.

If you like my games and want to show some appreciation, you can always buy me a coffee.

reidrac

This is an old video when I was debugging a tile/sprite engine.

It shows the "erases" in red, it may be useful!

https://twitter.com/reidrac/status/952689606255939584
Released The Return of Traxtor, Golden Tail, Magica, The Dawn of Kernel, Kitsune`s Curse, Brick Rick and Hyperdrive for the CPC.

If you like my games and want to show some appreciation, you can always buy me a coffee.

Kitsune Mifune

Quote from: reidrac on 13:50, 28 November 20How? Both using tricks to do what you need to do but faster and by doing less things.

Sage advice, thank you!

That video is really good for seeing a visual representation of what's happening which is great. It's good to know what path to set down now as I wasn't sure before, but your advice has been incredibly helpful.
Unlocking the dark arts of assembly!

Powered by SMFPacks Menu Editor Mod