Solved

Next channel available

Posted on 2004-04-23
10
190 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
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 

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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Turn A Profile Picture Into A Cartoon Using Photoshop And Illustrator This tutorial will teach you how to make a cartoon style image out of a regular picture. I have tried to keep the tutorial as simple as possible. I used Adobe CS4 for this tuto…
Objective of This Article In 1990’s, when I was a budding software professional, I had a lot of confusion about which stream or technology, I had to choose to build my career. In those days, I had lot of confusion like whether to choose System so…
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…

729 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