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 / ( yet another ) Problem with "Play Sprite"

Author
Message
Dejunai
19
Years of Service
User Offline
Joined: 19th Jul 2005
Location: Mentally: Manhattan; Physically: LA -doh
Posted: 25th Jul 2005 10:30
I am new to DBPRo,
( as if you didn't know )

I don't seem to understand the "Play Sprite" command...

My specific situation is,
I have a large tile world generated with "paste image"
of the world I can see 1000 tiles in the game window...
after updating the window with the tiles, I lay in any
requested animated sprites on top of the tile world.
when I lay in a sprite ( there is only one at this point )
I set it to play.

and then wait for a key...

`main loop
do
`screen updates
do
sync
scan = scancode$()
if scan
if <a key I want> then do something :exit
if <a key I want> then do something :exit
if <a key I want> then do something :exit
endif
loop
loop

the animated sprite is placed and begins play in the screen updates
the sync is in the "waiting for scancode" loop, shouldn;t
the frames be playing on each sync? or do I need to call the
play sprite again? and again and again?

if I am pressing a key ( scrolling the world ) it plays just fine...
if I let up off the key, it freezes,
often distorts for one more frame, and it waits for the next key...

what am I missing...

================
-Dejunai
================
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 25th Jul 2005 16:24
The "play sprite" command must be in the do loop to animate. Everytime Darkbasic Pro see's the "play sprite" command it checks the current frame it's on and goes to the next frame.

Also it's always better to post proper code and any media that the code loads.

Dejunai
19
Years of Service
User Offline
Joined: 19th Jul 2005
Location: Mentally: Manhattan; Physically: LA -doh
Posted: 25th Jul 2005 20:30 Edited at: 25th Jul 2005 20:47
Wow, that's dumb founding...
so if I had 10 animated sprites on screen,
I would need ten calls to the play sprite command
and every loop redefine which frames to play, and then for how long,
And they would execute is series???
NOT in paralllel...
And the code is at adead stop until all sprites have played?

EDIT *** Hly $h!T I posted this post and it just showed up...
No long wait, no warning "you might be a spammer in disguse"...
Oh, happy days...

================
-Dejunai
================
Dejunai
19
Years of Service
User Offline
Joined: 19th Jul 2005
Location: Mentally: Manhattan; Physically: LA -doh
Posted: 26th Jul 2005 01:08
Ok, I have been playing around with animated sprites for
several hours... My brain is at an impasse, It wants
to think of animated sprites as animated GIFs in HTML.
You place the image, tell it run over a sequence of
frames and it just does it after being told to start...

Obviously that is not the case...
The next logical place my brain takes me is that
an animated sprite should increment on SYNC...
Once placed and told to start, it will update
on each sync, based on current frame rate and
some mathimatical formula using the delay value.

Well that's not the case either...
So with some experimentaion I now know
that you must continuosly call the "PLAY SPRITE"
function within some loop... since all the parameters
are still in the function, this means there is no
cacheing of the parameters, it also means the function
must determine which frame the sprite is on, increment
it by one and determine if it is exceeded the endframe
parameter and if so display the start frame parameter.
And only do so based on some hidden mathimatical formula,
based on framrate and the delay parameter.

Am I getting close?

So if I want to use an animated sprite in
the fashion I first described... I need to write
a function to "UpdateAllVisibleAnimatedSprites()"
and put it before my sync loop? The function would
itterate over an array with the list of loaded
sprites and playing any visible sprite in
sequence... Hopefully so fast as to not appear
as a sequence...

Am I on the right track?

================
-Dejunai
================
Dejunai
19
Years of Service
User Offline
Joined: 19th Jul 2005
Location: Mentally: Manhattan; Physically: LA -doh
Posted: 26th Jul 2005 01:34 Edited at: 26th Jul 2005 02:35
On yet another note,

it would appear that the "play sprite"
does cache the delay... using the following
snippet I would expect the animations to
change frame rates.



but once drawn, the sprite's delay is a constant...
altering it with subsequent calls, has no affect...

I suspect that is true of the startframe, and endframe...
Time to go test my suspections...


EDIT :
I haven't tested my theory completely but it is
interesting to note, the following code...



Where varF is decreasing brings a runtime error
that the "image number is illegal", so my theory is
definately wrong ( how wrong I am not sure ), changes
to the endframe DO affect the command on subsequent calls,
However please note that the error message is irrelevant
to the problem. It can only be rellevant to something
under the hood. "Play Sprite" might just be creating images
for me...

EDIT :
Ok, so to prove affecting the play sprite parameters
is not the problem directly above I did this...



Where varF is only reduced ONCE, everything on screen
appears fine... Everything runs normally, no errors...

So now lets reduce F to 2...



Now that F is reduced to 2 the animation is indeed
now only playing frame 1 and frame 2.. So my theory is shot...
Subsequent calls to "play sprite" can affect the endframe...
They cannot affect the delay, but endframe can be manipulated.

Just to be thorough tho, I'll test the startframe
parameter by increaseing it...



Completely destroying my original theory,
( which leaves me utterly perplexed why I cannot affect the delay parameter )
changes to either the startframe or the endframe
are possible. However one strange thing did happen.
If I set the max value of s to f-1 which should allow
for two frames of animation ( f-1 and then f ). The animation
ceases all together, and stays static at the original
last frame ( f )... It should display the second-to-last and the
last frames. Instead it shows the only the last frame, and
becomes static. Setting the max value of varS to f-2 has the
desired affect of f-1... The animation shows two frames,
when logically it should be showing three ( f-2, f-1, f ).

Subsequent changes and experiments with manipulation
of the startframe, appear to always loose the first frame of the
original frame list. The first frame is there as long as you make
no changes to the startframe... once you do however,
the set of frames is decreased by one loosing whatever the
new startframe SHOULD be.

I think my experimentation with play sprite is comming to
a close. I look forward to any technical help, advice, or
insights any one has that might help me better understand
play sprite.

================
-Dejunai
================
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 26th Jul 2005 05:38
Yup you got it.

Login to post a reply

Server time is: 2024-09-23 23:28:42
Your offset time is: 2024-09-23 23:28:42