[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 194
  • Last Modified:

Next channel available

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
Normand14
Asked:
Normand14
1 Solution
 
MediaMacrosCommented:
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
 
Normand14Author Commented:
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
 
MediaMacrosCommented:
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
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
Normand14Author Commented:
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
 
j3oneCommented:
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
 
Normand14Author Commented:
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
 
MediaMacrosCommented:
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
 
Charles03Commented:
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
 
MediaMacrosCommented:
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
 
Normand14Author Commented:
alright, thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now