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.

DarkBASIC Discussion / need help with sprite

Author
Message
z3r0mind
19
Years of Service
User Offline
Joined: 11th Aug 2006
Location: Behind you...
Posted: 11th Aug 2006 21:15
Hey guys I\'m new at this and I was playing around with sprites. I\'m trying to make it so when I press the left or right arrow the sprite will go in that direction but when I run the program the sprite just disappears when I press an arrow. But if I put a print command in each of the while statements it works. Can someone tell me whats wrong so I dont have to put in those prints or maybe show me a better way of doing this. I know this is problably a newb way of doing this so dont go to hard on me.
Thanks

Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 12th Aug 2006 10:34 Edited at: 12th Aug 2006 10:36
Hi z,

First off, you don't really need all those while endwhiles... unless you planned on nesting other code.

Instead of editing your code, I whipped up a simple "move sprite around screen" example. I think the key element you were missing was turning SYNC ON at the beginning of your program and then using the SYNC command at the end of your loop. SYNC allows you to control the refresh of your screen.

Take a look at this sample code. I contain all the movement in one loop (with sync just before the LOOP command):



Enjoy your day.
z3r0mind
19
Years of Service
User Offline
Joined: 11th Aug 2006
Location: Behind you...
Posted: 12th Aug 2006 18:49
Nice thanks alot man.
Sonic 91 Software
21
Years of Service
User Offline
Joined: 19th Mar 2005
Location: In a Cryptic Crossworld!
Posted: 10th Oct 2006 09:47
Nice work, Latch. Quick question, however. How can I maintain this smooth movement of a sprite and have animation as well. I know how to do animation with sprites, it's just when I tried to do it, it was very jerky when moving, and if I pressed the right key, for instance, it only stopped moving once it had gone through all the frames of animation.

"Fight the good fight of faith,
Lay hold on eternal life"
-1 Timothy 6:12
Bluestar4
20
Years of Service
User Offline
Joined: 19th Dec 2005
Location: USA
Posted: 12th Oct 2006 10:16
I believe if you look at the code closely , you will find at the begining of the code a command called "sync on" and near the end of the do-loop one called "sync". You can also obtain additional control by using the sync rate command.
Using these commands in conjunction with each other will allow your program to perform better as the p.c. doesn't have to worry about refreshing the screen as much which in turn allows it to process things faster.

Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 12th Oct 2006 12:32 Edited at: 12th Oct 2006 12:33
@Sonic

Like Bluestar4 said, a lot of the processing can be controlled with the raster refresh (SYNC). In the days of old, one looked for ways of sticking assembly code in between the raster redraws. You would send an interupt request to the processor and point to the memory where your inserted code was stored - I wonder if that's what the BACK BUFFER commands are for...but I digress... sorry

What your symptom sounds more like is a loop inside of a loop. From what you said I'm gussing you have a loop that cycles through all of the images that represent the animation of the sprite, and this all happens inside the movement control loop. In this scenario, if you had 1000 cells of animation, you'd have to wait for them all to finish before the next position of the sprite was updated.

If this is the problem, you'll have to find a way to switch the images in the sprite within the main loop without having a subloop that has to finish before the main loop can take one step. That would mean switching an image at the same time you press a movement key. For example, if you have a series of images that would be a sprite climbing:



If you absolutely have to have a subloop within the main loop that cycles through all of the animation frames of the sprite, try putting a sync at the end of that loop as well. It might eliminate any flicker, but you would still have to wait for that loop to finish before it takes another step in the main loop. You can use sync multiple times within the program. Remeber, it's a way for you to control the refresh of the screen.

Enjoy your day.
Bluestar4
20
Years of Service
User Offline
Joined: 19th Dec 2005
Location: USA
Posted: 12th Oct 2006 16:06 Edited at: 12th Oct 2006 16:10
@latch
if degress further back , you might recall that some the early games were actually done using all ascii in plain console mode with and were made using compilers with extreme limitations -> less than 64kb of memory was available , 2-16 colors , source code file size and final exe size were also limited
@z3r0mind
be careful when using while-endwhile loops. if you make a mistake in coding and it crashes it will crash really hard. take a look at the sample code below it might help you in the future with your coding.



Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 12th Oct 2006 17:05 Edited at: 12th Oct 2006 17:15
@Bluestar4

TI-99 (but that's a personal computer that I don't think ran with a compiler, just a built in basic interpreter rom)

@Sonic
Bluestar4's code applies to your question as well. From what I gleaned from your question:

If there are a different series of images for each direction the sprite moves, for each direction there should be a conditional (IF THEN) associated with it so that the proper series of sprite images can be cycled through. Maybe images 4 through 12 are a climb cycle. Maybe images 1 to 3 are an idle cycle. Maybe images 13 through 20 are a walk cycle, etc. Whatever the direction associated with a specific animation, you would have to include instruction to reference that:



The whole point of all of this goes back to trying to avoid a series of subloops within your main loop that have to finish before the main loop completes one iteration.

Enjoy your day.
Sonic 91 Software
21
Years of Service
User Offline
Joined: 19th Mar 2005
Location: In a Cryptic Crossworld!
Posted: 12th Oct 2006 22:13
good advice, all. thanks for helping. i'll get back to you soon.

"Fight the good fight of faith,
Lay hold on eternal life"
-1 Timothy 6:12

Login to post a reply

Server time is: 2026-07-06 20:16:22
Your offset time is: 2026-07-06 20:16:22