|
Post by Noble on Mar 2, 2023 14:37:19 GMT -5
So what is the proper way to achieve smooth sprite movement? To be more specific, using the left/right arrow keys to move a sprite smoothly at set speeds.
Thanks in advance.
|
|
|
Post by tsh73 on Mar 2, 2023 15:48:09 GMT -5
>>using the left/right arrow keys GetAsyncKeyState Search on forum
|
|
|
Post by Noble on Mar 2, 2023 16:30:55 GMT -5
Hey... thanks for your answer. While I understand and use that, this is the issue I have.. Perhaps my question should have been worded differently.. lol
Let's say a user has a block on the screen. He wants to move the block from point a to point b. Let's say to the right at the speed of 20 pixel's. You can see the jerky animation as the block jumps 20px a time to the destination. My question, how to smooth that out and keep the speed? There are methods such as vector and delta time, etc. I never see those mentioned in an LB program. Just wandering how people do it in LB to make it smoother. Make sense? lol
|
|
|
Post by atomose on Mar 3, 2023 3:06:58 GMT -5
hi, you can check this game its normaly very smooth and you have the keyboard function if you want a better moove than 20px by 20px you just have to moove it 1px by 1 and speed up the loop GAME JUST HERE
|
|
|
Post by Rod on Mar 3, 2023 3:14:59 GMT -5
I often set the sprite in motion from a single key press. This is as opposed to jerky keypress following. If I am moving to a specific location I calculate delta values and apply those in cycle steps. You can make it fast or slow by increasing or decreasing both delta. However 20 pixel jumps are twenty pixel jumps. To smooth it we need 20, 1 pixel jumps, twenty times slower movement. Not sure how you get over that compromise.
The trick would be to cycle twenty times faster than needed and move the block every twenty cycles and the sprite every cycle. Probably difficult to manage and the block may look jerky. So you would mitigate that by doubling its timing and halving its delta.
Which gets you right down to fastest cycle possible with minimum movement and speed dictated by delta. Bear in mind that the screen updates every 17ms and you are at your stonewall.
Welcome back by the way. You have been gone a long time!
|
|
|
Post by honkytonk on Mar 3, 2023 3:27:28 GMT -5
Maked with cat foot
NOMAINWIN mapw=500: maph= 400 WindowWidth=mapw+15: WindowHeight=maph+40 UpperLeftX = 10: UpperLeftY = 20 GRAPHICBOX #w.g, 5, 5, mapw, maph OPEN "Help" FOR window_nf AS #w #w, "TRAPCLOSE [closeHelp]" ' #w.m, "when leftButtonDown [scanne]" #w.g, "down;fill darkpink;color white;backcolor white" ax=30: ay=100: bx=100: by=100: temp=50: dx=1 #w.g, "place ";ax;" ";ay: #w.g, "boxfilled 50 150" #w.g, "getbmp bmp 30 100 20 50" #w.g, "getbmp backgr ";"5";" ";"5";" ";mapw;" ";maph #w.g, "background backgr" #w.g, "addsprite sprit bmp" ' #w.g, "fill darkpink" #w.g, "spritexy sprit ";" ";ax+50;" ";ay #w.g, "background backgr" #w.g, "drawsprites" while p=0 scan if ax=bx then ax=30: temp=temp-10 #w.g, "spritexy sprit ";" ";ax;" ";ay gosub [pause] ax=ax+dx #w.g, "drawsprites" wend #w.g, "flush" wait [go] wait [pause] timer temp, [temps] wait [temps] timer 0 return [closeHelp] CLOSE #w END
|
|
|
Post by Rod on Mar 3, 2023 4:49:08 GMT -5
|
|
|
Post by Noble on Mar 3, 2023 7:42:44 GMT -5
Thanks for the great answers. This will get me started. Rod - It's good to be back around. Life has been busy and has not afforded me much leisure time lately.
|
|