Janck
254 posts
|
Topic: Programming /
Slowdown, plus any tips?
In your case ithe bullet is ALWAYS going up.
Unfortunately, that’s not true. Two future things that break that rule are spread bombs (Fire in 8 directions when contacting an enemy) and photons (Missile-type weapons, some of which fire backwards and accelerate). Plus, enemies will eventually shoot bullets.
I will try the bin technique, that sounds like it would be the best for this sort of thing. Thanks again for the advice.
|
| |
Janck
254 posts
|
Topic: Programming /
Slowdown, plus any tips?
i believe this code could be made much simpler!
Yeah, it could be the same with half as many blocks, but I didn’t know if asking for something that doesn’t exist takes a while longer to compute. If such was so, I didn’t want to have to do that twice.
|
| |
Janck
254 posts
|
Topic: Programming /
Slowdown, plus any tips?
Ok, now the bullets either:
Don’t work
I’m pressing CTRL and I’m not supposed to even though it says to shoot using CTRL
CTRL is the shoot key. There was a slight XML parsing error at that time, I think, so that might have caused it. If it doesn’t work for you now, I don’t know what to say. Your browser or your OS might be intercepting it?
All right, so I’ve updated a lot of code based on your suggestions, and it ran fine. Then, I added some more stuff. Now, it slows down again. (All the links at the top are up-to-date again.) For those who don’t want to look at the source, here’s my bullet scanning code:
for (var j = 0; j<maxbuls; j++) {
//BULLET MOVEMENT AND ENEMY COLLISION
if (bullets[j].active) {
bullets[j].move();
for (i=0; i<numEnemies; i++) {
if (enemies[i].active) { //Is this not an empty space?
if (!enemies[i].explosion) { //Is this an enemy or actually an explosion?
if (Math.abs((bullets[j]._y)-(enemies[i]._y))<bullets[j].size/2+enemies[i].radius) { //Do they intersect vertically?
if (Math.abs((bullets[j]._x)-(enemies[i]._x))<bullets[j].size/2+enemies[i].radius) { //Do they intersect horizontally?
if (distance(bullets[j], enemies[i])<bullets[j]._xscale/2+enemies[i].radius) {
enemies[i].HP -= bullets[j].damage;
removeMovieClip(bullets[j]);
if (enemies[i].HP<=0) {
if (Math.random()<1/10) {
itam = findSpace("item");
iterms[itam] = attachMovie("izem", "item"+itam, itam+itemDepth, {type:0, _x:enemies[i]._x, _y:enemies[i]._y});
}
enemies[i] = attachMovie("asplode", "eexplosion"+i, enemies[i].getDepth(), {_x:enemies[i]._x, _y:enemies[i]._y, _xscale:enemies[i].radius*3, _yscale:enemies[i].radius*3});
}
break;
}
}
}
}
}
}
}
}
I know the problem is here because of the list of numbers at the upper right. They’re timing how long each routine takes, and this one is the one that’s jumping up to 50 millaseconds… not pretty.
Here’s a list of things that are NOT the problem:
- Anything inside the ‘if(distance(...) < ...)’ block
- ‘bullets[j].move()’. It’s as efficient as it gets, really.
- ‘distance()’. The majority of the slowdown happens when it doesn’t get called.
|
| |
Janck
254 posts
|
Topic: Programming /
Slowdown, plus any tips?
47 moving bullets aren’t too much for flash, but if you’re hitTesting every bullet with every enemy every frame the load will get too big more quickly. Finding ways to cut down the amount of collision testing you need to do will be really important for a game like this.
You could also separate your collisions checks into tile based areas if you absolutely have to.
Ah, I replaced HitTest with a check to see if the bullet is within colliding distance vertically, and the game runs like a charm now.
To continue Moonkey’s line of thought: If you’re making it test every frame, make it test every 3-4 frames instead.
With the speed of the enemies and the player’s bullets (And yes, I do want them to be that fast), that’s simply not possible. There would have to be too many huge calculations checking if something happened to pass through something else to make this efficient… plus it’d be a headache.
So if I were you I’d just go over the code and rework it – try to think of better algorithms, and how to speed up things that are done many times per frame.
Oh… now that I think about it… every time a bullet is generated, it should be telling the program what its index was, and the program should keep the greatest active index in memory so it won’t have to check the whole array…
I’m no expert on working with classes, but it looks to me like you’re giving each object (including bullets) its own onEnterFrame function, which I understand is something of a performance hit.
Ah, I thought that since all of the movieclips did that regardless of whether or not the event is handled, Flash’s built-in scanning through movieclips and executing onEnterFrame functions would be faster than me coding a for loop which calls the function. (Looking at the source, telling all of the enemies to move would have had to have had a for loop all to itself, and that didn’t seem efficient…)
Then maybe trial cacheAsBitmap on your objects, if you don’t already.
With all the information I provided, I seem to have forgotten one of the most important bits…
Can you use cacheAsBitmap in Flash MX Pro 2004?
Thank you all very much for the advice. It really helped.
|
| |
Janck
254 posts
|
Topic: Programming /
Slowdown, plus any tips?
Well, on mine it only drops to 20 fps from 24. I do have a decently-fast single-core CPU and decent graphics card though. It would definitely affect a lot of casual users. The 47 bullets might be overdoing it. Can you use larger bullets at a lower count? How about a different weapon? At 47 bullets though, the game was kinda boring.
It’s supposed to run at 30 fps…
The game is going to be much more extensive than it is at the moment, and it’s supposed to be 2-player. I seriously hope just 40 bullets isn’t too much to ask of Flash…
This is a remake of a game I previously made in Visual Basic .NET
|
| |
Janck
254 posts
|
Topic: Programming /
Slowdown, plus any tips?
Here’s everything I’ve got:
Published flash, embedded
Published flash, direct
Archive containing source .fla and class .as files
Here’s the problem: It runs fine, and, so far, bug-free. However, when there are 40+ bullets on-screen, it slows down considerably.
I am smarter than the average internet person, or so I like to believe. All code (with the exception of the starry background movie clip) is either in the main, one-layer timeline or in the class files. Bullets, enemies, etc. are MovieClip subclasses linked to symbols in the library. And I use strict typing most of the time.
Also, aside from the main conondrum, I would like to know, from anyone experienced who has the time, do you have any tips? Is there anything that could have been more organized, or could be done more efficiently?
|
| |
Janck
254 posts
|
Topic: Off-topic /
Joystik.net
wow that website kind of seems like a rip-off of kongregate come up with some original ideas
Your use of bolded words must really impress people.
Despite that, I think the OP is well aware of his idea’s similarity to Kongregate. Pointing it out isn’t really helping things.
|
| |
Janck
254 posts
|
Topic: Kongregate /
Suggestions
Did this guy just break the avatar resizer, or is it just me?
|
| |
Janck
254 posts
|
Topic: Off-topic /
The correct pronounciation
According to “Pure Pwnage”, it’s still pronounced “owned”, due to it being a mispelling of the original term.
|
| |
Janck
254 posts
|
Topic: Kongregate /
Multiplayer API suggestion
Plus, anything that drives home the fact of developers’ obvious superiority over normal users is good :P
|
| |
Janck
254 posts
|
Topic: Kongregate /
Seven Deadly Sins uses Highway to Hell
Take action as in how? Tell AC/DC about it, I guess?
It just seems that a band as big as AC/DC would never give permission to some random flash game developer to use one of their biggest hits in a really obscene (and crappy if you ask me) internet game.
Alternatively, it just seems that a band as big as AC/DC wouldn’t even care if one of their hits was sampled in an obscure flash game.
|
| |
Janck
254 posts
|
Topic: Programming /
goto random frame
<pre><code>Code goes here</code></pre>
Code goes here
|
| |
Janck
254 posts
|
Topic: Off-topic /
"A Puzzling Sort" or "What on earth are you doing Windows XP?"
It… may.. have something to do with Microsoft trying to fix that problem where sorting things by name when working with non-padded numbers would result in this:
1
11
12
13
...
2
21
22
etc.
|
| |
Janck
254 posts
|
|
| |
Janck
254 posts
|
Topic: Programming /
[Kongregate API] High Scores
Janck: Showing the high scores in-game is explained in the documentation with a short example (which archbob quoted).
I need to quote people more when I reply to them…
Archbob was asking why that code was even necessary. I answered with another question.
|
| |
Janck
254 posts
|
|
| |
Janck
254 posts
|
Topic: Games /
Live Tetris!
acjones93, I see you’ve adjusted to the rest of the internet rather well, however, I think you’ll need to readjust to Kongregate.
|
| |
Janck
254 posts
|
|
| |
Janck
254 posts
|
Topic: Kongregate /
Problem
Though my name is not Allison, I know why it’s better. Because it’s got hype and lots of eternal fans.
|
| |
Janck
254 posts
|
|
| |
Janck
254 posts
|
Topic: Games /
gd65s glitches eps 4
Those aren’t glitches, those are cheat codes…
You can get those at GameFAQs.
|
| |
Janck
254 posts
|
Topic: Kongregate /
Back of cards
I think he has the card, which has a code, and he wants to know how to find it…
|
| |
Janck
254 posts
|
|
| |
Janck
254 posts
|
Topic: Off-topic /
The epic Find The Thread hurt/heal game (awards have been given and the hurt/heal has ended!)
Everybody hates me =(
Even though you have the most HPs it still manages to somehow be personal.
Hurt Flare_x
Hurt renny141
Heal sprint45_45
|
| |
Janck
254 posts
|
Topic: Kongregate /
August - Greg Month!
We shall all store away our G avatars for next year… when Greg Month starts anew.
|