Keyboard control and sprites

BlitzPlus Forums/BlitzPlus Beginners Area/Keyboard control and sprites

I want to make a sample game, overhead view (as in old SNES RPGs) where you control a character who can walk in 8 directions, with sprites for left, right, up and down both walking and standing. I can either make the sprites or use a sheet from RPG Maker, that's the easy part. But I basically want to know how to make him move and change the sprites. Do I make sense at all?

Use the command LoadAnimImage to load the sprite sheet.
It needs the width and height of a single frame and the number of frames that the sheet contains.
Then, use the 4th parameter of DrawImage to select which frame to draw.
Sort of like this:
graphics 800, 600, 0, 2
setbuffer backbuffer()

;sprites are 64x64 and sheet contains 16 sprites
sprites = loadanimimage("spritesheet.bmp", 64, 64, 0, 16)

repeat

cls

;draw current frame (frame+frameoffset)
DrawImage sprites, x, y, frame + frameoffset

;on keyhit (first keydown), select frameoffset
if keyhit(203) then frameoffset = 0: frame = 0
if keyhit(205) then frameoffset = 4: frame = 0

;on keydown, move 'x' coordinate and loop the current frame between 0 and 3 (with 'mod 4')
if keydown(203) then frame = (frame + 1) mod 4: x = x - 1
if keydown(205) then frame = (frame + 1) mod 4: x = x + 1

flip

forever


Thanks!

D2, a good book to read that would help you is Game Programming For Teens.

I've got that book, just I lost it until recently...and I didn't know how useful it would be nowadays. I'll look at it right away.

I think Learn 2D Game Programming with BlitzBasic will help even with B+. It won't cover the GUI stuff but is superb for explaining how most things are done.