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 / Keeping track of multiple animated sprites

Author
Message
roswell1329
13
Years of Service
User Offline
Joined: 12th Apr 2010
Location:
Posted: 14th Sep 2014 21:11
I'm trying to keep track of multiple independently playing sprites, but I'm not sure if I fully understand how the play sprite or create animated sprite commands work. Either that, or I'm missing something else entirely.

The goal of this code is to simply start an explosion sprite where I click the mouse, and have it complete all the frames of the sprite. But if I click somewhere else before the first one finishes, I'd like a new sprite to start there. To do this, I'm using a short function to find an available sprite number to create a new animated sprite.

I'm wondering if I cannot use create animated sprite this way and need to use something like clone sprite?

roswell1329
13
Years of Service
User Offline
Joined: 12th Apr 2010
Location:
Posted: 15th Sep 2014 00:08 Edited at: 15th Sep 2014 00:09
Okay, I'm a little closer now. I guess I don't have to worry about handling each frame with sync when using animated sprites and the play sprite command. This code will put a sprite where I click, but none of them appear to be going through all the frames, and sometimes, I'm getting the whole image back. Any ideas?

roswell1329
13
Years of Service
User Offline
Joined: 12th Apr 2010
Location:
Posted: 15th Sep 2014 00:15
Curiouser and curiouser...I'm very close now, and yet still utterly baffled. I don't understand the relationship between sync and play sprite.

This code will put one of my animated explosion sprites on the screen, but only a frame of it. If I hold the mouse button down, it'll play through all the frames continuously. In fact, it looks like it repeats each frame 2 or 3 times. I can also click elsewhere and a new sprite will be pasted there, but only up to about 3 sprites can be on the screen at a time. Any idea what's going on here?

chafari
Valued Member
17
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 15th Sep 2014 03:28 Edited at: 15th Sep 2014 03:41
Try this:



Attached example

I'm not a grumpy grandpa

Attachments

Login to view attachments
roswell1329
13
Years of Service
User Offline
Joined: 12th Apr 2010
Location:
Posted: 15th Sep 2014 18:31
Ah! I see now. It took me a while to figure out what your "ss" variable was doing. If I removed that part of the code, and just made it so a new sprite was created for every mouseclick, what actually happened was a new sprite was created every cycle the mousebutton was held for. Hold the button too long, and I quickly hit the sprite limit. It looks like the "ss" variable only kicks off one and only one sprite creation per mouse click, correct?

I'm just not sure when the "else ss=0" is ever evaluated, because I saw the as long as the mouse button is held, ss keeps incrementing. But as soon as the mouse button is let go, it would never get into the "if mouseclick()=1" condition statement. Can you explain this code a little more?

The code I created with my sprite graphic is attached.

Attachments

Login to view attachments
chafari
Valued Member
17
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 15th Sep 2014 19:58
Quote: "I'm just not sure when the "else ss=0" is ever evaluated, because I saw the as long as the mouse button is held, ss keeps incrementing. But as soon as the mouse button is let go, it would never get into the "if mouseclick()=1" condition statement. Can you explain this code a little more?"


" ss " is the name of the variable . It is like a counter that start when we mouseclick, and it reset when we release the mouse, to be ready to start again....remember that one more sprite will be create only if ss=2 ...not if ss is bigger , and the counter is always running while we press right-mouse.


This code is better.



Cheers.

I'm not a grumpy grandpa
roswell1329
13
Years of Service
User Offline
Joined: 12th Apr 2010
Location:
Posted: 15th Sep 2014 20:07 Edited at: 15th Sep 2014 20:08
I was able to understand most of your original code, and I'm not sure I understand anymore with this code.

I understand that the "counter" starts as soon as the mouse button is clicked, and when that counter hits 2, the sprite is created and drawn. But the "else counter=0" seems to me like the counter would always be resetting and never getting to 2.

On the initial pass:
1. counter=counter+1 (since counter was never initialized, counter is now equal to 1)
2. counter is NOT equal to 2, so the code in the IF statement is ignored
3. Since the IF wasn't satisfied, then counter should now be equal to 0 because of the ELSE, right?

But in my code, the counter just happily continues to increase. As soon as I let go of the mouse it resets to 0, but I don't understand why because when you let go of the mouse button, the IF/ELSE should no longer be evaluated at all.

Sorry if I seem exceptionally dense on this one. I just don't follow it.
chafari
Valued Member
17
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 15th Sep 2014 20:19
1 --We click mouse
2 --counter=counter +1
3 --if counter=2 then the sprite will be created
4 --the couter is increasing...we have to release the right-mouse
5 --we release the right-mouse
6 --right-mouse is released SO the statement says "ELSE" ...
that means in case contrary , then reset counter
7 --else counter=0
8 --Now if we press againg right-mouse....
1 --we click mouse
2 --counter=counter +1

That simmple !!

I'm not a grumpy grandpa
roswell1329
13
Years of Service
User Offline
Joined: 12th Apr 2010
Location:
Posted: 15th Sep 2014 20:29
Oh my goodness. I thought the ELSE was part of the nested IF.

I was reading it like:



I didn't understand that the ELSE is included inside the IF-ENDIF block. Many many thanks for helping me sort this out! You've been very helpful!
chafari
Valued Member
17
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 15th Sep 2014 20:43
Quote: "Oh my goodness. I thought the ELSE was part of the nested IF. "



Don't worry ! Sometimes I'm a bit grumpy with my own family . Enjoy the code .

I'm not a grumpy grandpa

Login to post a reply

Server time is: 2024-03-29 13:39:50
Your offset time is: 2024-03-29 13:39:50