|
-
Game Master
Multiple Elements assigned to one Variable?
My computer with 3dfa is down so I cant test this but Is it possible to assign more then one element to one variable?
Like
A=ele box
B=ele 1, ele 2, ele 3
Then say
If A collides with B{
show text
}
So basically saying if A collides with any three elements then the text will show. Is this possible? Are there any glitches when you do this? Thanks.
PS: Is there a way to say "If ANYTHING collides with box then show something"?
-
A Senior Newbie - How Odd
If I understand right, you want to perform collision detection on a large number of objects.
The way I did this in my 10 pin bowling game was to use clones, and then use nested 'for' loops to detect collisions between pins.
If you're just testing collision between x things and 1 main character, it would just need 1 'for' loop, running through each clone in turn checking for collisions with your main character.
Let me know if you need an example. I'm unemployed now, so might find time to knock up a demo.
M.
-
Game Master
Well yeh, the problem I'm having is that i want to make a big that doesnt "lag". So I have a few questions, oh and just to tell you I have done very little with clones and the "for" thing, actualy what is the difference between "if" and "for"?
So anyway I want to make a game with little lag, so after doing some experiments I found out most the lag comes from long scripts being repeated fast. The first thing I found out was that if you have a button that makes a gun shoot once (which is usally attacked to a long script) and the player mashes the button it lags up like crazy. My solution was to make a short script that would be played when the button pressed that would lead to the shooting script pending on whether it had already been played.
Okay so anyway the next source of lag I found was "bulk" scripts being run every frame such as collisions. In many of my games I make individual "AI" and many individual chracters instead of just clones of the same "bad guy". Well in doing this I have to make individual collsion scripts for each one and that causes LAG!
My first attempt was to have multiple objects assagned to one variable. So like I could just say
monster=monster1, monster 2, monster 3
and the i could say
if main character collide with monster equals main character hide
but I found out that doesnt work.
Anyone have any sugestions?
Also ANTHER source of lag is having to load all the pictures and all the scripts and movies at once. Is there a way to create a movie inside a movie and not have it loaded until it needs to be?
Thanks
-
Game Master
oh and what I meant by the movie inside the movie thing is like "youve reached level 2!! now loading level...". you kno like that. and i kno i could do it by having external .swfs but id rather do it all in the same sfw
-
I've never used this, I think I've tried it, and I'm not sure where I read it but...
If I recall correctly 3DFA already has the ability to handle large movies on its own. 3DFA was built with the idea of 1 large movie with many smaller movies in it. If you select in you secondary movie to "Download external SWF" instead of "Export inside SWF" (the default) 3DFA will create an external SWF of the secondary movie and automatically load it when it's needed.
The external SWF must be located in the same place as the main movie in order for 3DFA to find it.
I'm not sure if you get a loading movie message though (I don't think so).
As far as multiple elements I would suggest you use an array then you only have to loop through it to detect a collision.
for example:
PHP Code:
elements = new Array();
elements.push(element("1"));
elements.push(element("2"));
elements.push(element("3"));
for(i=0;i<elements.length;i++) {
if (elements[i].collideRect(element("test"))) {
// do something
}
}
-
Game Master
 Originally Posted by ConnELITE
and i kno i could do it by having external .swfs but id rather do it all in the same sfw
but thanks anyway.
also wat are you saying with that code, i dont get it.
-
Originally Posted by ConnELITE
and i kno i could do it by having external .swfs but id rather do it all in the same sfw
I was not thinking about swf's but of movie and your right you would get multiple swf's.
Originally Posted by ConnELITE
also wat are you saying with that code, i dont get it.
What I was trying to say is..
That if you put all your elements into an array (in my example I used 3 elements element("1"), element("2"),element("3") and put them into an array called elements).
To check for collisions is easier since you just have to loop through the array for(i=0;i<elements.length;i++).
Then do something if your element (in my example I used element test) collides with anything in the array
[I]if (elements.collideRect(element("test"))) {
// do something
}
If you do collision checking this way you could make an ANYTHING function out of it so that any element could be checked against all the other elements or clones in the array.
I hope this helps.
Last edited by ppedz; 11-14-2005 at 05:25 PM.
-
Game Master
k thanks, that does help cause I have like fifty things colliding with 50 things and it sucks to write it all out.
-
A Senior Newbie - How Odd
Word of warning:
If your movie is checking for any of 50 items, colliding with each other, it is likely to slow down quite a lot.
My 10 pin bowling involved 11 items colliding with each other.
Mathematically, that involves making between 55 and 121 tests per frame, (depending on how well coded it was). I think I was lazy in coding so it does about 100 tests per frame.
If your movie is checking 50 items colliding with each other, you may end up with between 1225 and 2500 tests per frame, which is likely to slow down your game rather a lot.
It might be worth thinking of some clever way to ensure that many of the characters don't touch each other, so you can avoid testing for collisions between them.
eg. If you have 10 bad guys of one sort, have them come onto the screen in waves, and follow a particular pattern of movements so those bad guys never collide with each other. That will save some time in collision detection between those characters.
M.
-
Morgan has a very very good point, try to minimize your collision detection.
Your ANYTHING(element, elements) function could pass the element to be checked along with an array of elements which has a subset of items to be checked against based on some logic (like a wave as Morgan mentioned).
-
Game Master
yeh I know. Its not literally 50 elements and I asked about multple elements to one variable in the first place because I'm wokring on anti lag sytems so I kno all about collision lag . But thanks for the script thing. One of the top reasons for lag is too much script being run too often.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|