Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / moving animated sprites help

Author
Message
oneiro naut
16
Years of Service
User Offline
Joined: 19th Aug 2008
Location:
Posted: 20th Aug 2008 20:32
i just started using DBpro yesterday, but i caught on pretty fast to the basic 2D commands. in the same day, i managed to make a simple MS paint clone (just color swatches and a single 'brush'), and a 1P pong clone with a score system, multipliers and whatnot. all by myself, btw. :}

now i tried using some commands that require imported graphics today, and I'm seeing that my previous craftiness might not work so well with the more advanced commands. i can draw a sprite on screen, and move it with input just fine, but when i try to animate it... well, i get problems. it seems simply re-drawing everything on the screen every single frame manually isn't a very efficient way to move an animated sprite around.. go figure.

could someone point me to a code/tutorial that just demonstrates how to move a 2-frame sprite on screen with player input, while smoothly cycling between frames? (nothing fancy, this is literally ALL i need!)
i tried figuring out ways to do this by myself, but it just didn't happen. :\

thanks. :}
BlobVanDam
16
Years of Service
User Offline
Joined: 26th Jul 2008
Location: one of Cybertrons moons
Posted: 21st Aug 2008 20:36 Edited at: 21st Aug 2008 20:36
I know when I first started using DarkBASIC, I noticed my code wasn't running very nicely either. In my particular case it was because I hadn't used the "sync on" command, which means you tell the program when to refresh the picture, which you would do at the end of your main loop, using the command "sync". Without code though, I'm just speculating based on my own experience.
oneiro naut
16
Years of Service
User Offline
Joined: 19th Aug 2008
Location:
Posted: 21st Aug 2008 21:50
oh my lord, i actually DID forget to 'sync on'. how silly.

thanks for that. :0

i got it working, but I might as well ask if the way i achieved this is efficient?
also oooone more thing, i have it so the sprite moves with the arrow keys, but i couldn't figure out the commands to move it with the a/s/d/w keys.. :\
how would i do this?



btw thanks for replying. =D
Terrorist Zero
18
Years of Service
User Offline
Joined: 29th Aug 2006
Location: Teh YouKai
Posted: 22nd Aug 2008 01:25 Edited at: 22nd Aug 2008 01:25
Your best bet is to use the Scancode() and Keystate() functions which will return the current key pressed and test to see if a particular key is being pressed respectively.

For example:
Pressing the "w" key whilst scancode() is called would return "17".
Pressing the "w" key whilst keystate(17) is called would return "1".

In this manner we can check to see when our chosen keys are being pressed. Here's a modified version of your own code that's had the default up/down/left/right keys replaced with W/A/S/D:



Just play around with the commands to get the hang of it (not that it's that hard hehe)

Towards the bottom of TGC newsletter 57 is an article you may want to read up on, since it goes over this topic and has a handy scancode map. Here's a link: http://www.thegamecreators.com/data/newsletter/newsletter_issue_57.html

Hope it helps!!!

Ed222
17
Years of Service
User Offline
Joined: 3rd Nov 2007
Location: Calgary
Posted: 22nd Aug 2008 02:17 Edited at: 22nd Aug 2008 02:18
or you can use inkey$() but it'll only accept one input at a time. e.g. you can't press w&d as the same time to diagonally down.

oneiro naut
16
Years of Service
User Offline
Joined: 19th Aug 2008
Location:
Posted: 22nd Aug 2008 05:04
thanks a bunch, man. i wasn't sure what keystate was for, but now i get it. i'll have to take a read through the custom key article, seems like something worth learning. at the very least, the scancode map is already a big help.


yar.. i'm not a big fan of the inkey$() because it seems to work in its own little universe, instead of flowing with everything else. @_@

thanks guys. (:
BlobVanDam
16
Years of Service
User Offline
Joined: 26th Jul 2008
Location: one of Cybertrons moons
Posted: 22nd Aug 2008 08:29
Also, shouldn't the "sprite 10,vSpriteX,vSpriteY,5" line be after the input code? I'd put it at the end of the loop after the input commands, otherwise the sprite would be a frame behind.

Login to post a reply

Server time is: 2024-11-25 18:46:53
Your offset time is: 2024-11-25 18:46:53