My animation routine would work much better if the origin was at the bottom left of the sprite instead of the top left as it would keep the "feet" nicely lined up when different sized frames are used. Keeping every frame the same size would work, but it would also be a dreadful waste of memory and processing power as there would be huge big empty bits of blank space in the frame which the CPU would have to spend time masking out.
I've had a sniff around the internet and I couldn't find anything on the topic.
I realise that under the hood, the sprites will always be drawn from the top left, and that's fine, I'm not trying to change that - just get a new point from which to set them which will always keep the bottom of the frame the same level. I'm currently trying to write some code that will make a new reference point from which to calculate the X/Y by finding out and storing the bottom left coordinate and using that as a reference, but I'm failing rather spectacularly at it (also, no idea how this will affect up/down movement).
I think my logic is sound, because I keep looking at the code and seeing nothing wrong with it, and if that's the case it must be a placement problem within the draw routine (which is just a modified version of the "Simple sprites on the CPC" lesson).
If I've missed an easier way (or even a sneaky firmware way) to do this then then please feel free to inform me, because I'd like to post a progress video in the Show and Tell, but I'd rather get this issue sorted first.
Thanks!
Code: Select all
ORIGIN_BOTTOMLEFT:
push hl ; Preserve 'hl' as it's used elsewhere
ld hl,(PLAYER_YPOS) ; Take current Y-Position (Top left of frame)
ld bc,(SPRITE_HEIGHT) ; Take the current height of the frame
or a
sbc hl,bc ; Subtract the frame height from the Y-Position and this...
; ...will give us a coordinate at the bottom left of the frame
ld (PLAYER_YPOS_BTMLFT),hl ; Transfer the new co-ordinate value to a label-variable
ld hl,(PLAYER_YPOS_BTMLFT_PREV) ; Take PREVIOUS frames's bottom left Y-Position
ld bc,(SPRITE_HEIGHT) ; Take the height of the CURRENT frame
add hl,bc ; Add the CURRENT sprite's height to the bottom left...
; ...coordinate of the PREVIOUS frame
ld (PLAYER_YPOS),hl ; Transfer new draw coordinate to PLAYER_YPOS
ld hl,(PLAYER_YPOS_BTMLFT) ; Store the bottom left coordinate to use in next frame
ld (PLAYER_YPOS_BTMLFT_PREV),hl
pop hl
RET