News:

Function Finder  Find all the functions within source code files

Main Menu

Sprite Movement

Started by servogod85, January 06, 2006, 09:49:06 AM

Previous topic - Next topic

servogod85

I made a program that moved a sprite ( a square in this case) according to the arrowkeys. the cose looked something like like:



Load Sprite
Position Sprite in middle of screen
set frames 24

do

if upkey then MoveSpriteY -2
if downkey then MoveSpriteY +2
if leftkey then MoveSpriteX -2
if rightkey then MoveSpriteX +2

drawallsprites

sync
loop


The problem is when i press the arrowkeys and the sprite moves, the nee one get drawm and the old one remains, creaing a smudge effect after a few moments of movement. The problem is the old sprite is never deleted from the screen. I inserted a 'Cls 0' command right after the 'do' command and it worked. What i want to know is if this is the best solution, the ony one, will this method create problems on a larger scale game, on the quality of the game. Pretty much, did i make a smart move? or is there a better way to solve this?

Sal

kevin

#1
When a sprite is drawn, it's image becomes part of the picture that it was drawn onto.    So yes, if you draw a sprite, move it,  then draw it again.  It will leave a trail.    Which is true for all GFX's not just sprites.

  To rectify this and create the illusion of animation in your game, you'll need to either clear the screen at the start of drawing (like you did) or draw a backdrop to the screen each frame (like a map perhaps)..

kevin

#2
An example

PlayBASIC Code: [Select]
; make a circle image to look at
Circlec 32,32,32,1,rgb(200,100,50)
getimage 1,0,0,64,64


; Make a sprite and position it in the middle of the screen
Me=NewSprite(GetSCreenWidth()/2,GetSCreenHeight()/2,1)


Speed=3
Do
; clear the screen to black
Cls 0
Print "Move Sprite"

; move the control sprite with the arrow keys
if LeftKey() then MoveSpriteX Me,-Speed
if RightKey() then MoveSpriteX Me,Speed
if upKey() then MoveSpriteY Me,-Speed
if downKey() then MoveSpriteY Me,Speed

; draw all sprites
DrawAllSprites

Sync
loop



servogod85

yeah i thought so..well now that that is solved back to the retro compo. Ciao

Sal