Solved

Next channel available

Posted on 2004-04-23
10
184 Views
Last Modified: 2013-12-24
Hi, I would like to make a series of puppetSprites wich will appear and disappear at various rates.
Is there a way to put the puppetSprite in the next available channel?

I made a repeat this:

repeat with channel= gSProjectile to gNbChannels
    if sprite(channel).memberNum=0 then
      sprite(channel).puppet = true
    end if
end repeat

But I am not satisfied, is there a way to do this without a repeat?

Norm
0
Comment
Question by:Normand14
10 Comments
 
LVL 20

Expert Comment

by:MediaMacros
ID: 10902567
Why not use a repeat loop?  Thats what they are for.  Also, you can do this with objects.  IE you create an instance of a script object and the object puppets its own sprite channel.  No need to puppet a channel until you plan to use it.
0
 

Author Comment

by:Normand14
ID: 10902674
a repeat loop is too slow, this is for a game and every time the user shoots, the repeat is done and there are 50 puppetSprites so it makes 50 verifications at 60 fps, it slows down performance. But if there is no other way, I will stick to it
0
 
LVL 20

Expert Comment

by:MediaMacros
ID: 10902718
You do not need to repuppet them each time.  You may also want to look at sendAllSprites()  Using that command you cna broadcast a message out to all sprites and any one that has that handler will then run it. Much more efficent way to run code on multiple sprites at once.

Puppeting only needs to happen if you are populating an empty channel with a cast member and only once.  If there is a sprite in the score puppetSprite is not needed.
0
 

Author Comment

by:Normand14
ID: 10903041
Thanks, but I already know the sendAllSprites method, and I don't think it would be useful in this case, I only need to take the next empty channel to put a new bullet wich will disappear when it hit a wall or something.

I don't want to have 150 sprites wich detects collision 60 times per seconds neither do I want to give them a variable to know if they're active or not
0
 
LVL 9

Expert Comment

by:j3one
ID: 10903150
What kind of sprite is it? there may be a way to achieve this through a visual effect and you will only puppet it once. Or maybe hold... more info on the type of sprite would be good.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:Normand14
ID: 10903217
The sprite is a bullet, a grenade, or whatver, i'ts a graphic. The player shoots it, it appears, has a script attached and then dies if it hits the wall.
0
 
LVL 20

Expert Comment

by:MediaMacros
ID: 10903576
You may definately want to look at some more object oriented approaches.  Let each "bullet" contain a script that thinks for itself.  It can have its own exitFrame script that checkes its rect against other objects (walls, etc) that it can hit.  I do this a lot in games with sendALlSprite commands and its much mroe efficent than repeat loops and a lot easier to debug.
0
 

Expert Comment

by:Charles03
ID: 10914733
Thank you for your suggestion, but about giving each bullet an individual script with sendAllSprites method, I am already using it, my problem is to know where is the first empty channel. But that's okay, I will stick with the repeat method mentionned above.

Maybe what you meant was to put about 150 sprites with no script attached and no cast member and then when I activate it, I would just have to attach the script, but I doubt having a whole load of sprites, even if empty, will be faster than a repeat every time I hit the "fire" button.
0
 
LVL 20

Accepted Solution

by:
MediaMacros earned 125 total points
ID: 10917861
A repeat loop works well looking for empty sprites.  I use this method.  Note I ONLY run this when I need to create a new sprite...

on findNextEmptySprite
  repeat with x = the lastChannel down to 1
    if sprite(x).member.type = #empty then
     return x
    end if
  end repeat
  return 0
end
0
 

Author Comment

by:Normand14
ID: 10920710
alright, thanks
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Now that Expression Web 4.0 (http://www.microsoft.com/expression/products/Upgrade.aspx) is free if you buy or have the full version of Expression Web 3.0, now is the best time to  migrate from FrontPage to Expression Web (http://www.frontpage-to-exp…
When setting up new project requests for our site, one of the most powerful tools our team has available to use is Axure (http://www.axure.com/). It’s a tool for creating software and web prototypes that can function and interact as if it were the a…
The purpose of this video is to demonstrate how to automatically show related posts at the bottom of a blog post in WordPress. This will be demonstrated using a Windows 8 PC. Plugin “Yet Another Related Posts Plugin” will be used. Go to your…
The purpose of this video is to demonstrate how to integrate Mailchimp with Facebook. This will be demonstrated using a Windows 8 PC. Mailchimp and Facebook will be used. Log into your Mailchimp account. : Click on your name. Go to Account Setti…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now