A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: My Rock Array Problem,

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    1

    My Rock Array Problem,

    Basically have no idea What i am doing, I am trying to create a game where the player has to dodge rocks and if he doesn't and the rock collides with him an animation will play for the rock to be destroyed, the player to lose a bit of life and more rocks to come, but this is my problem the rock comes on in, my player hits, but straight away it destroys and the rock no longer comes from the side, i had feeling it was because the whole array was deleted with removeMovieClip(); so i i have no idea, take a look at the code :


    Code:
    onEnterFrame = function() 
    {
    	if (playerLife<0)
    	{
    		gotoAndStop(3);
    	} 
    }
    	
    
    for (i=0; i<numberRock; i++) 
    {
    	newRock = attachMovie("Enemy", "Enemy"+i, i);
    	newRock._y = Math.random()*Stage.height; 
    	newRock.rockSpeed += .5;
    	
    	
    	newRock.onEnterFrame = function()
    	
    	{
    		if(this._x>Stage.width)
    		{
    			
    			this._y = Math.random()*Stage.height;
    			this._x = 20;
    			rockSpeed += .5; 
    		}
    			
    		this._x += rockSpeed; 
    		
    		
    		if(this.hitTest(_root.Player))
    		{
    			    playerLife -= 2; 
    				newRock.play();
    				score += 100;
    				this.removeMovieClip();
    				
    
    		}
    		else
    		{
    			// to add
    		}
    		
    	}
    }
    	
    stop();
    any idea's ? because i have run out of them, if think its literally because of the array itself but i don't know.

  2. #2
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    Im more of a logic kind of guy and just find the easier way out of hard math in flash so i'd just make rock movieclips with preset animations and random timers to trigger them at random times. heh. I suck at arrays, but thats a suggestion ^ if no one else helps.

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center