ActionScript 3.0 :: Game Loop - Rounding Causes Inaccuracy
Apr 26, 2010
For my game, I've made an easy-to-use instruction list to program enemies. It works pretty well, except it's inaccurate, and the only reason I can think of is a rounding error.
Here's how my instruction list works:
list[0] = "Right:60";
list[1] = "Left:60";
The game loop calls a function on the object that decides what action to do. Right:60 means it moves right for 60 game loops, then goes to the next item on the list. This works fine, except for the inaccuracy. An object gets his xSpeed altered every game loop, depending on the current instruction. If it's "Right", xSpeed += acceleration, if it's "Left", xSpeed -= acceleration.
The game loop itself multiplies the xSpeed by a friction variable, which is 0.7 (may be changed later, currently this works best). Now what happens is, the object bounces back and forth just fine. But it after so many times it keeps going a couple of pixels further to the left than to the right. Eventually, the object falls off the screen on the left, while the instruction says it should do 60 game loops of "Left" and 60 loops of "Right".
View 1 Replies
Similar Posts:
Oct 12, 2011
I load a bitmap to the stage, it's a GIF and set to lossless compression. I have ensured its coordinates are integers and have not allowed smoothing (smoothing somewhat fixes the issue but reduces quality of the image).The problem is the image appears to shift one pixel to the left and add that pixel on to the right side meaning one side has no border and the other a double border.The original bitmap does not have this issue, and there is no transparency .etc in the image.
View 1 Replies
Feb 24, 2010
Currently, I have all my variable initialization and function definitions in the timeline's first frame, my logic in the second frame, and a command to 'go to the second frame' in the third frame.
View 1 Replies
Feb 19, 2012
I'm developing a Flash game using ActionScript 3 and have this code in my documents class:
package com {
import flash.display.MovieClip;
import flash.display.Stage;
public function Engine() {
// Create a player instance
[Code]...
Is there a library or something I need to import to get this to work? If it's not obvious, I want to run the gameLoop method of my Engine class (the documents class) on every new frame (the document is currently set to 30fps).
View 1 Replies
Mar 15, 2009
I am trying to create a turn base board game. It has four player and out the the four players one is human and the rest are cpu's. The players are number 1,2..4. In the beginning of the game it ask's the user to which player will be the human player. A random number generator function picks a random number between 1-4 and that number player will go first.
There is a while loop that controls the game play something like:
var isNotEndofGame:Boolean = true;
var human:Number; //the user inputs this number.
var aPlayer:Number = getRandomNumber(1,4); //players: 1, 2, 3, 4
while(isNotEndofGame) {
if(aPlayer==human) doHumanMove();
else doCpuMove();
This reset's the player so they can keep on playing until game ends.
if(aPlayer==4) aPlayer = 1;
}
inside function doCpuMove() and doHumanMove() isNotEndofGame will become false when the game objective is met.
The problem I am having is when its the human players turn I want the loop to pause or wait so that the human player can do some interaction such as click a button or drag a movieClip. I tried adding adding mouseclick event listeners and timer neither worked.
View 1 Replies
Aug 5, 2010
I need to take control of how my base game class updates:
package {
import flash.display.Sprite;
import flash.events.KeyboardEvent;
public class Test extends Sprite {
private var sprite:Sprite;
[Code] .....
Here after every key press/release AS3 takes care of automatically drawing a sprite onto screen, but I need to do this manualy. Haw to get my hands on updating mechanism here? I need something like this - all time repeating game loop that is set to be updated/redrawn every time at its end.
View 2 Replies
May 28, 2011
Im making a transition from Java to Flash/Actionscript and Im having sort of a hard time figuring out where to write my code for my flash game loop(or engine) due to flash having "frames" unlike Java.Am I able to put the loop inside the Document class even having like game menus in the game? I havent found a way to put it in there without it always running when the flash application begins.Or should I just have the game loop called every frame? For instance, frame 4 will be level 1 and so the engine will be called out there. And frame 5 will be level 2 and ill call a different instance of the game engine there.Im just having a difficult time due to the "frames". So where would be the best place to put the game loop?
View 4 Replies
Mar 29, 2012
I have a game loop written in Haxe/Flash. For some reason it slows down over time. At first it runs reasonably, but my laptop fan starts spinning up and it gets slower and slower. Why would this happen?
import flash.display.StageDisplayState;
import flash.display.StageScaleMode;
import flash.display.MovieClip;
[code].....
View 1 Replies
Jul 17, 2010
I'm trying to program this code:
public function enemiesDie(){
enemyLoop: for (var k:int = enemies.length -1;k>= 0; k--){
bulletLoop: for (var i:int = bullets.length -1; i>=0; i--){
if (enemies[k].hitTestObject(bullets[i])){
trace("hit");
[Code] ....
To detect when a bullet hits an enemy in a game I'm trying to make and I get this error:
TypeError: Error #1006: hitTestObject is not a function.
at Space_Hooligans/enemiesDie()
at Space_Hooligans/gameLoop()
View 2 Replies
Jan 14, 2012
I have looked everywhere for an example or tutorial on a delta time game loop in AS3. I found many fixed time step examples but very little helpful information on delta time game loops and how it works. I have seen examples that do the calculations in a timer and also seen examples that do the calculations inside the enter_frame event. All the examples I have seen are also incomplete and only provided me with bits and pieces.
View 3 Replies
Jan 19, 2009
I'm trying to use a loadMovie function inside a loop to load external PNG files when my game is loaded. Unfortunately, I can't get even a single loadMovie to work correctly, much less execute a bunch of them.The code is on the root time line, and is targetting an empty movie clip that is nested inside about 3 levels. There is a button, with a movie clip on it, and the empty clip I'm trying to load into on that.so the full target path is myBox_00.smallBox.myLogo(myBox_00 is the button, smallBox is the movie clip, and myLogo is the empty)[code].I even tried using a JPG image instead of a PNG and still no luck. The best I could do was number 4; and that didn't work, all it did was SOMETHING instead of NOTHING... unfortunately that something was to make the button (myBox_00) disappear entirely T_T.I've never had much luck with loading external images. What am I missing here?
View 9 Replies
May 5, 2009
I have a number that looks something like this: 0.552I would like to round it up to a one decimal number like this: 0.6
View 3 Replies
Nov 26, 2009
I've developed a project with the help of kglad in which the user enters in a numerical amount into an input text box and 3 other boxes (dynamic text boxes) display numerical amounts based on that input.With the great help of kglad I have gotten everything to work just perfectly except that those 3 boxes don't round off the results they display.
For example, if I input 265.35 into tf1 (text field 1), tf2 displays 132.675, tf3 displays 66.3375, and tf4 dispalys 132.675. Now according to the math that is programmed, that is correct. But I need them to display: 132.68, 66.34, and 132.68, either rounding up or down accordingly.
View 8 Replies
Mar 8, 2009
How would you round a number between 2 numbers? For example if you have
ball._x = 90;
If(ball._x is closer to 100 then 0){
ball._x = 100;
[code]...
View 2 Replies
Feb 15, 2003
i've tried making a preloader (without any tutorials) by myself, i've done everything, just i've done this:
named text box varibal: loaded
on the maintimeline's first frame i enter:
loaded=_root.getbytestotal();
all i want to do now is round the bytes off to KB. i Assume you multiply by 1000 but where do i put this code? in the brackets? new line? or what.
View 4 Replies
Jun 23, 2008
I know math.round would round a number.
but what if i wanted to round it just up.
so lets say I have 8 thumbnails, my rows are 4 thumbnails long.
so 8/4 = 2 rows.
if I have 1 thumbnail, 1/4 = 0.25 rows. I want this to round up to 1 row.
View 2 Replies
Sep 6, 2000
I have a cost calculator in flash, only the price comes out with about a hundred decimal places... any convenient way to round it up to 2? I was hoping there was some (fairly easy) way to nicely format an output..
View 3 Replies
Aug 3, 2009
I have a BMI calculator that is currently working well, however when calculated, gives a VERY precise result of:Your BMI is: 24.343121332458201.I'd like it to round up/down so it just displays:[code]
View 2 Replies
Aug 3, 2009
I have a BMI calculator that is currently working well, however when calculated, gives a VERY precise result of:Your BMI is: 24.343121332458201I'd like it to round up/down so it just displays:Your BMI is: 24.3
Code:
var totalHeight:Number;
var totalHeightx2:Number;
[code].....
View 3 Replies
May 15, 2011
I've been using a simple function I wrote to numerically round numbers to a specified number of decimal places like the following example:
ActionScript Code:
private function roundNumber(input:Number, decimal:Number):Number {
var multiplier:Number = Math.pow(10, decimal);
return Math.round(input*multiplier)/multiplier;
}
It has worked great, until I came upon the need to round extremely large numbers. When the already large number is multiplied by, say 10 to the 5th power, it can't hold all the decimal places, and strange results can return.The only other option I've thought of would be to convert the number to a string using the Number.toFixed() method, then convert that back into a number. I feel like this is somewhat inefficient as the string conversion has to be done, then the string parsed to "chop off" the extra decimals, then parsed again to convert back to a number.So, my question is, are there any better ways to round large numbers? If not, am I over-thinking the string method's efficiency?
View 2 Replies
Mar 22, 2012
I'm making a game where you level up, and then the amount of EXP you need to level up, gets higher. The problem is, if I have it so the amount of EXP needed to get to the next level just multiply by 2, it just gets to an absurdly high number, and I don't want that. I would rather have it multiply by 1.3 or 1.5, but the problem with that is that the right side of the decimal gets all ugly to something like "60.54902380".
how would I be able to round it so there's no decimal point, or at best just one number to the right?
View 2 Replies
Nov 11, 2005
does anyone have or know of a simple sure fire way to round up a figure to 2 decimal places.
flash has a horible habbit of removing 0's.
I need to round up figures but having to split a number like 100.056 (fine when its a string, but not when its a number)
rounding up the 056 gets complicated as flash will see it as 56.
View 3 Replies
Sep 12, 2006
How can I round off a decimal number upto say three decimal places? The number comes as an output value like 0.98765e^7 for the statement outputvalue = 0.8678/InputValue. How can I make the output value rounded off as 0.988e^7?
View 7 Replies
Jun 26, 2009
I haven't used actionscript 3.0 in a while and I'm finding myself slightly lost.
I have a fully functional calculator but I need it to return numbers with a max of two decimal places. (x.00)
I'm not sure where to input the code and how to make this work.
here's my code:
total_btn.addEventListener(MouseEvent.CLICK, getTotals);
function getTotals(event:MouseEvent):void
{
[Code].....
View 2 Replies
May 24, 2010
I haven't used actionscript 3.0 in a while and I'm finding myself slightly lost.I have a fully functional calculator but I need it to return numbers with a max of two decimal places. (x.00)I'm not sure where to input the code and how to make this work
here's my code:
total_btn.addEventListener(MouseEvent.CLICK, getTotals);
function getTotals(event:MouseEvent):void
[code].....
View 1 Replies
Sep 20, 2010
I want to get the amount of a number after the decimal place in order to round the number in increments of .25, .5, .75, or the next whole number.
For example the number is 5.13 it would produce 13 which I could check if < 25 and then round to 5.25 and so on for .5 .75 and the next whole number.
View 4 Replies
Nov 7, 2009
My friend and I are working on a flash project in actionscript 3, and we are trying to move several movieclips by a portion of a pixel. Since we have filters on these movieclips, flash rounds their location to the nearest pixel, making the motion look jumpy. Is there anything that can be done to stop flash from rounding their location to the nearest pixel?
View 6 Replies
Mar 22, 2011
i have one movieclip in flash player,
when i set x position of movieclip like.. movieclip.x=57.8299
it will automatically rounding off to 57.80
View 1 Replies
Jul 9, 2011
I need to round at only the top or bottom of a border container not all four corners, is their some CSS that I can use or do I have to create two new skins. I was reading their used to be a property for this for HBox back in the old days, is their not a property for BorderContainer now?
View 1 Replies
Oct 20, 2011
I am doing the following in actionscript in Coldfusion Flash Forms:
90 / 3.7
Gives me:
24.3243243243243
Whereas the calculator gives me:
24.32432432432432
Note the extra 2 at the end.
So my problem occurs when I am trying to get the original value of 90 by taking the 24.3243243243243 * 3.7 and then I get 89.9999999999 which is wrong.
Why is Actionscript truncating the value and how do I avoid this so I get the proper amount that the calculator gets?
View 2 Replies