|
-
Senior Member
Maybe if I counted to random(40)? Would that produce the same pattern as testing 5>random(100) each time?
No, the results will be different. random(100) could potentially produce >50 many times in a row. If Thing[x].P were equal to 50, then the if statement would be true often. If you use your random(40) and then a smaller Thing[x].P you will much less often see repeats.
With that said, what you describe is a common way to make random things less "twitchy". You simply establish a "duration" that determines how long before "thing" can be updated again. Generally this is done after the previous update. You will probably want to do this independently for each Thing though rather then for all of em. It will make it "feel" better when people play.
-
But, I would not always count to random(40), but to random(2*100/P)... So, if P=50, I would count to random(4).... And hey, isn't that a good example? The chance of flipping a coin and get "head" twice in a row is 1/4. And only 1/4 of the times, with the counting-method, I would get to count from 0 to 0, i.e. it would happen in a row. Right?
Or, maybe you're still right, that it's not the same pattern, somehow...
-
Game optimization
Hi! I’m a new member and this is my first post!
I've developed an Actraiser's remake (from the SNES) using sprites I've found on the web. This is a platform game and is 1 level long which includes boss. However, the game looks and feels a little “slow”. I spent yesterday’s afternoon reading about AS Optimization Tips (I also read all posts in this thread) and I noticed that I didn’t apply most of the optimization issues mentioned in this great article. For example, I’m using loops instead of ASBoradcaster, every baddie has his own OnEnterFrame where most of its actions are performed and I’m using complex if-else’s. Also, I use the movie’s main OnEnterFrame to perform Hero’s actions, collisions, background and platform movement, etc… using loops and arrays, of course. By the way, I used FlashMX 2004, I suppose it uses ActionScript 1.0 (sorry for not using a newer version, but I have a low budget… $$$).
I’m planning to restructure my game applying the optimization tips, but I have a question: Should I place all the actions on a single OnEnterFrame event? I mean, place collisions, scenery movement, hero actions, baddies actions, all to be executed in the movie’s main OnEnterFrame, just like in the old school programming where you placed all in a single main loop. I also read that I could use a MovieClip as a handler, but I want to choose the best option that will boost my game’s performance so I can continue with the next levels.
Here’s the game’s demo:
http://www.mediafire.com/?sharekey=1...db6fb9a8902bda
I hope I can read your recommendations.
Thanks a lot guys!!!
GT
-
Senior Member
A long time has passed since I wrote that article that you have mentioned I think those tips are still valid if you're using Actionscript 1, however the Flash Player (the "flash runtime") has evolved alot since then, it has gained better overall perforamance and it finally provides JIT compilation if used in conjunction with Actionscript 3.
If you're looking for the ultimate performance for browser based games I would definitely recommend to invest some time and learn AS 3, it will provide a huge performance increase over your AS1 code no matter how many performance tricks you apply 
Hope it helps
p.s. = btw, you don't need to buy any new Flash to start studying/working with AS3. Adobe nicely provides the Flex SDK for free here -> http://opensource.adobe.com/wiki/dis...exsdk/Flex+SDK
Lapo
-
-
Any optimisation improvements for this code appreciated
I am having a stab at making a game for the iPhone and its a bit sluggish on the iPhone 3G.
I have been trying to optimise the following code and would therefore appreciate any further suggestions to improve this code if anyone has any?
Code:
function moveBallObjects(e:Event):void {
var sqrt = Math.sqrt;
for each(var ballObject in objGame.ballObjects) {
if (ballObject.alpha < 1) {
var newScale:Number = ballObject.scaleX * 0.98;
ballObject.alpha = ballObject.alpha - 0.1;
ballObject.scaleX = ballObject.scaleY = newScale;
if (ballObject.alpha <= 0) {
ballObject.horizontalVelocity = ballObject.verticalVelocity = 0;
ballObject.visible = false;
continue;
}
} else if (returnIfBallOnTheBoard(ballObject) == false) {
ballObject.alpha = ballObject.alpha - 0.08;
}
var horizontalVelocity:Number = ballObject.horizontalVelocity;
var verticalVelocity:Number = ballObject.verticalVelocity;
var V:Number = (horizontalVelocity * horizontalVelocity) + (verticalVelocity * verticalVelocity);
// ----------------------------------------------------------
// Only do calculations on this ball if it is actually moving
// ----------------------------------------------------------
if (V == 0) {
continue;
}
V = sqrt(V);
var k:Number = (V - objGame.dV) / V;
if (k < 0) {
k = 0;
}
horizontalVelocity = horizontalVelocity * k;
verticalVelocity = verticalVelocity * k;
ballObject.tempX = ballObject.tempX + horizontalVelocity;
ballObject.tempY = ballObject.tempY + verticalVelocity;
ballObject.horizontalVelocity = horizontalVelocity;
ballObject.verticalVelocity = verticalVelocity;
// ---------------------------------
// Update Position of Ball On Screen
// ---------------------------------
ballObject.x = ballObject.tempX;
ballObject.y = ballObject.tempY;
}
}
function returnIfBallOnTheBoard(passedMC:MovieClip):Boolean {
if (passedMC.x < objGame.numBoardMinX) {
return false;
}
if (passedMC.x > objGame.numBoardMaxX) {
return false;
}
if (passedMC.y < objGame.numBoardMinY) {
return false;
}
if (passedMC.y > objGame.numBoardMaxY) {
return false;
}
return true;
}
Thanks
Paul
Paul Steven
http://www.mediakitchen.co.uk
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
|