Solved

Next channel available

Posted on 2004-04-23
10
191 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

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
 

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When deciding to adopt any help desk solutions many factors should be explored before taking decisions. This will change from business to another but in general there are some kind of rule of thumb. Here are some quick tips: Do we need only ticket…
This article provides a case study on how our local youth baseball league deployed a new website, including the platform selection, implementation and benefits to the league.
The purpose of this video is to demonstrate how to create a Printer Friendly PDF on a WordPress Page. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome Screenshot” Google Chrome Extension, and SmallPDF.com Log…
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…

628 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