Results 1 to 7 of 7

Thread: Int round

  1. #1
    Join Date
    Jul 2008
    Posts
    65
    Thanks
    42
    Thanked 0 Times in 0 Posts

    Default Int round

    I'm programming a simple app that has a circle in it. You can select the circle with the cursor and move it around(Or so I'm hoping to achieve one day :P). To handle a gradual acceleration PART of my code is:

    Code:
    function accelerate(velvar:int, maxspeed:int):int
    			{
    				if( velvar < maxspeed )
    				{
    					if(!brakes)
    					{
    						velvar += 0.5;
    					}
    				}
    				trace(velvar);
    				return velvar;
    			}

    then later I have:
    Code:
    velocity = accelerate(velocity, 5);
    mycirc.x += velocity;
    (mycirc being the sprite)

    The weird thing is that velocity never gets over 1. :P If you need anymore code from my program I'll be happy to post it. Thanks

  2. #2
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    What is brakes referring to? How and when is it set?

    Try placing a trace within the !brakes condition and see if it's being run.

    I'm assuming that you're feeding the function a value for maxspeed that's greater than 1. Is that correct? What are you feeding for the velvar value?

    My guess is the trouble is with the !brakes condition. If it's true, it should be throwing an error. If there is no error, my guess is that it's not being run. You might try replacing it with if(brakes == "") or something similar.
    Last edited by Medyman; 09-08-2008 at 01:28 AM.

  3. The Following User Says Thank You to Medyman For This Useful Post:

    hosdank (09-08-2008)

  4. #3
    Join Date
    Jul 2008
    Posts
    65
    Thanks
    42
    Thanked 0 Times in 0 Posts

    Default

    Brakes is a boolean value that decides if the ship should start to slow down(Basically if the it get within its (destination point - velocity))
    I'll try out what you said. Thanks

  5. #4
    Join Date
    Jul 2008
    Posts
    65
    Thanks
    42
    Thanked 0 Times in 0 Posts

    Default

    Yeah, it is getting in the if

    Heres all the code
    Code:
    package spacetrade
    {
    	import flash.display.*;
    	import flash.events.*;
    	import flash.geom.ColorTransform;
    	import flash.net.*;
    	import flash.text.*;
    
    	public class ship extends Sprite
    	{
    		internal var mycirc:Sprite = new Sprite();
    		private var dirx:int;
    		private var diry:int;
    		private var selected:Boolean = false;
    		private var regged:Boolean = false;
    		private var velocity:int = 0;
    		private var slowdown:Boolean = false;
    		private var stopped:Boolean = true;
    		private var loader:Loader; // The bitmap loader
    		private var brakes:Boolean=false;
    		private var velocity:int = 1;
    		//private var shiphit:String;
    		
    		
    		function ship():void
    		{
    			mycirc.graphics.beginFill(0x00FF00, 1);
    			mycirc.graphics.drawCircle(0,0,10);
    			addChildAt(mycirc,0);
    			mycirc.addEventListener(MouseEvent.CLICK, select);
    			mycirc.addEventListener(MouseEvent.MOUSE_OVER, hoveron);
    			mycirc.addEventListener(MouseEvent.MOUSE_OUT, hoveroff);
    			//mycirc.addEventListener(MouseEvent.CLICK, move);
    			addEventListener(MouseEvent.CLICK, move);
    			
    			function select(e:MouseEvent):void
    			{
    				stage.addEventListener(MouseEvent.CLICK, move);
    				mycirc.removeEventListener(MouseEvent.MOUSE_OVER, hoveron);
    				mycirc.removeEventListener(MouseEvent.MOUSE_OUT, hoveroff);
    				selected = true;
    				var selcolor:ColorTransform = new ColorTransform( );
    				selcolor.color = 0xFFFF00;
    				mycirc.transform.colorTransform = selcolor;
    				//stage.addEventListener(MouseEvent.CLICK, deselect);
    				e.stopPropagation();
    			}
    			
    			
    			function deselect(e:MouseEvent):void
    			{
    				if( selected == true )
    				{
    					mycirc.addEventListener(MouseEvent.CLICK, select);
    					selected = false;
    					var selcolor:ColorTransform = new ColorTransform( );
    					selcolor.color = 0x00FF00;
    					mycirc.transform.colorTransform = selcolor;
    					mycirc.addEventListener(MouseEvent.MOUSE_OVER, hoveron);
    					mycirc.addEventListener(MouseEvent.MOUSE_OUT, hoveroff);
    				}
    			}
    
    
    			function hoveron(e:MouseEvent):void
    			{
    				if(selected == false)
    				{
    					var selcolor:ColorTransform = new ColorTransform( );
    					selcolor.color = 0x0000FF;
    					mycirc.transform.colorTransform = selcolor;
    					stage.removeEventListener(MouseEvent.CLICK, deselect);
    				}
    			}
    			
    			function accelerate(velvar:int, maxspeed:int):int
    			{
    				if( velvar < maxspeed )
    				{
    					if(!brakes)
    					{
    						velvar += .2;
    						trace("It got in!");
    					}
    				}
    				trace(velvar);
    				return velvar;
    			}
    			
    	
    			function move(e:MouseEvent):void
    			{
    				stage.frameRate=60;
    				var velocity:int = 1;
    				if(!regged)
    				{
    					addEventListener(Event.ENTER_FRAME, executemove);
    					regged=true;
    				}
    				function executemove(te:Event):void
    				{
    					if( e.stageX > mycirc.x )
    					{
    						velocity = accelerate(velocity, 50);
    						mycirc.x += velocity;
    					}
    					
    					if( e.stageX < mycirc.x )
    					{
    						velocity = accelerate(velocity, 50);
    						mycirc.x -= velocity;
    					}
    					
    					if( e.stageY > mycirc.y )
    					{
    						velocity = accelerate(velocity, 50);
    						mycirc.y += velocity;
    					}
    					
    					if( e.stageY < mycirc.y )
    					{
    						velocity = accelerate(velocity, 50);
    						mycirc.y -= velocity;
    					}
    					
    					if( e.stageY == mycirc.y && e.stageX < mycirc.x )
    					{
    						removeEventListener(Event.ENTER_FRAME, executemove);
    						regged=false;
    					}
    					
    					if( ((e.stageY - velocity) * 10) < mycirc.y || ((e.stageX - velocity) * 10) < mycirc.x )
    					{
    						brakes=true;
    						velocity -= .1;
    					}
    					
    					
    					//if( (e.stageX - velocity) < mycirc.x )
    					//{
    					//	brakes=true;
    					//	velocity -= 1;
    					//}
    				}
    			}	
    			
    			
    			
    			
    			function hoveroff(e:MouseEvent):void
    			{
    				if(selected == false)
    				{
    					var selcolor:ColorTransform = new ColorTransform( );
    					selcolor.color = 0x00FF00;
    					mycirc.transform.colorTransform = selcolor;
    					stage.addEventListener(MouseEvent.CLICK, deselect);
    				}
    			}
    		}
    		}
    }

  6. #5
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    How are you running the function?

    Your logic and coding are fine. I didn't take a very through look at it, but I don't see any glaring errors.

    Try adding a trace to the beginning of the function and make sure the values are what you expect them to be.

  7. #6
    Join Date
    Jul 2008
    Posts
    65
    Thanks
    42
    Thanked 0 Times in 0 Posts

    Default

    Which function?

  8. #7
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Quote Originally Posted by hosdank View Post
    Which function?
    accelerate()

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •