A Flash Developer Resource Site

Results 1 to 14 of 14

Thread: How do I make certain pictures on top?

  1. #1
    Member
    Join Date
    Jul 2006
    Posts
    56

    How do I make certain pictures on top?

    How do I make a certain picture above other pictures at times and below them at other times?

    (I want car.png to be on top of obstacle1.pgn when the car's below the obstacle, and behind the obstacle when the car is above it.)

    I don't need a lengthy script, just the code for dropping and raising a picture on the screen, giving it picture priority over one picture and less over another.

    Also, why can't I seem to horizontally tile images without there being a small gap between them, is there a way around this, its been pretty important in the past too

    Ok, I fixed the horizontal part, when i rendered to swf it looked fine, just didn't look right in the test renderer great!

    Maybe there is something more I need to learn about flash so I can just implement my ideas by coding?
    Last edited by Seas_Comander; 01-20-2007 at 10:28 AM.

  2. #2
    Game Master ConnELITE's Avatar
    Join Date
    Apr 2005
    Location
    United States, DC
    Posts
    474
    Your going to want to use the Swap depths command.

    Code:
    car.swapDepths (obstacle)
    Last edited by ConnELITE; 01-19-2007 at 06:46 PM.
    BC

  3. #3
    Member
    Join Date
    Jul 2006
    Posts
    56
    This does not work for some reason...
    Code:
    if ((getTimer() % 13000 > 12900)){
    
    	if (idle_blockade.length){
    		new_blockade = idle_blockade.pop();
    		new_blockade.x = random(400);
    		new_blockade.y = random(100);
    	if (car.y > new_blockade.y){
    	car.swapDepths (new_blockade)
    	}
    		new_blockade.velocity.x = landscape.velocity.x;
    		new_blockade.acceleration.x = landscape.acceleration.x;
    		new_blockade.relative_acceleration.x = landscape.relative_acceleration.x;
    		new_blockade.show();
    		active_blockade.push (new_blockade);
    		
    		}{
    The code that makes this work is in the startup script.
    Last edited by Seas_Comander; 01-20-2007 at 11:14 AM.

  4. #4
    Member
    Join Date
    Jul 2006
    Posts
    56
    This does not swap depths for some reason...
    Code:
    if (car.y > blockade2.y){
    	car.swapDepths (blockade2)
    	}
    Last edited by Seas_Comander; 01-20-2007 at 10:51 AM.

  5. #5
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    if the object has properties it should work.

  6. #6
    Senior Member
    Join Date
    Dec 2006
    Posts
    274
    Hard to say why it wouldn't work.. you just have to add some debugging in your code to find out what really bugs it..

    example:
    Code:
    if ((getTimer() % 13000 > 12900)){
    
          trace("got past getTimer>12900");  
    
          if (idle_blockade.length){
    		new_blockade = idle_blockade.pop();
    		new_blockade.x = random(400);
    		new_blockade.y = random(100);
          
                     trace("yep, new blockade..");  
    
    	if (car.y > new_blockade.y){
    	   car.swapDepths (new_blockade)
               trace("yep, swapdepths done..car.y = " + car.y + " block.y=" + new_blockade.y);  
    	}
    		new_blockade.velocity.x = landscape.velocity.x;
    		new_blockade.acceleration.x = landscape.acceleration.x;
    		new_blockade.relative_acceleration.x = landscape.relative_acceleration.x;
    		new_blockade.show();
    		active_blockade.push (new_blockade);
    		
    		}{

  7. #7
    Member
    Join Date
    Jul 2006
    Posts
    56
    This is what I have now, but it still doesn't work... new_blockade2 is a clone of blockade2 and car is just itself. I have been unsuccessful at swapping depths of anything, especially this clone. They're slightly off center so I've had to add around 50 Y and 50 X to the car through the code. However.... after tracing car.y and newblockade.y inside the first if here, I see that when the blockade is greater Y there is no swapdepth that I can see

    Code:
    if (new_blockade2){
    		
    		if ((car.y+46) < (new_blockade2.y))  {
    			car.swapDepths(new_blockade2);
    		}
    	}
    Last edited by Seas_Comander; 01-24-2007 at 12:59 AM.

  8. #8
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    test the if statement
    Code:
     if (new_blockade2){
    		trace("yep it should swap")
    		if ((car.y+46) < new_blockade2.y)  {
    			car.swapDepths(new_blockade2);
    		}
    	}
    Betcha the if isn't firing

  9. #9
    Member
    Join Date
    Jul 2006
    Posts
    56
    actually, it traced, "yep it should swap" just fine

    edit: I also tested for swapdepth and it says it did.

    Here is my site if you want to see that the car does not go behind the obstacle www.chessclubfriend.com

    The car just covers the obstacle no matter what. Is there a way to control the z axis?
    Last edited by Seas_Comander; 01-24-2007 at 02:19 AM.

  10. #10
    Senior Member
    Join Date
    Dec 2006
    Posts
    274
    Well, I'm not sure I got your logic of swapping as you show only tiny part of you code. It looks like your code checks at new_blockage creation time if it should swap with the car (3'rd post code) It should happen every frame and somehow you should keep track which one is on top.
    Could you outline your game logic little more like:
    - do you have more than 1 obstacle on the screen ?
    - if more than 1 then can those obstacles overlap ?

    anyway, it might be easier to handle correct swapping if you use a layer that contains your obstacles and variable that would hold information which one, layer or car, is on top. Even with layer you still check car vs. obstacle y but swapping is only done with car and whole layer...

    But hmm... where clones go? to the movie/layer where the original one is/was??

  11. #11
    Senior Member
    Join Date
    Dec 2006
    Posts
    274
    Here is one example how to do car & obstacle swapping.. (no layers or multiple obstacles yet) See starting script & action.

    edit: one idea came to my mind... it seems that you want car to be behind that "top" part of obstacle.. how about making obstacte on two parts, "tops" that would be in topmost layer and "collision" parts that would be in "bottom" layer?
    And car in between them.? -> no swapping at all.
    Attached Files Attached Files
    Last edited by Finjogi; 01-24-2007 at 04:01 AM.

  12. #12
    Member
    Join Date
    Jul 2006
    Posts
    56
    This at least swaps depths, I didn't know you had to specify the layer, so I added that in there. Now the problem with it is it blinks on and off...
    Code:
     if (new_blockade2){
    		
    		if (((car.y+46) < (new_blockade2.y)))  {
    			car.swapDepths(layer2);
    		}
    	}
    I tried what you gave me sorda, using 4 ifs, one for when greater than and one for when lesser than, which I thought would work, and it just stayed on top all the time again for some reason?
    Code:
    if (new_blockade2){
    		
    		if (((car.y+46) < (new_blockade2.y)) && (is_on_top=true))  {
    			car.swapDepths(layer2);
    			is_on_top=false;
    		}
    	}
    
    if (new_blockade2){
    		
    		if (((car.y+46) < (new_blockade2.y)) && (is_on_top=false))  {
    			car.swapDepths(layer2);
    			is_on_top=true;
    		}
    	}
    I'm trying to make the car behind the obstacle(above it visually) and in front of the obstacle(below it visually) for those just now reading, and my site is listed with the latest build always.
    Last edited by Seas_Comander; 01-24-2007 at 06:31 AM.

  13. #13
    Senior Member
    Join Date
    Dec 2006
    Posts
    274
    Quote Originally Posted by Seas_Comander
    This at least swaps depths, I didn't know you had to specify the layer, so I added that in there. Now the problem with it is it blinks on and off...
    You do not have to have a layer, It just can make sometimes easier to just swap 2 objects and you know then which one is on top etc...

    Quote Originally Posted by Seas_Comander
    I tried what you gave me sorda, using 4 ifs, one for when greater than and one for when lesser than, which I thought would work, and it just stayed on top all the time again for some reason?
    Code:
    if (new_blockade2){
    		
    		if (((car.y+46) < (new_blockade2.y)) && (is_on_top=true))  {
    			car.swapDepths(layer2);
    			is_on_top=false;
    		}
    	}
    
    if (new_blockade2){
    		
    		if (((car.y+46) < (new_blockade2.y)) && (is_on_top=false))  {
    			car.swapDepths(layer2);
    			is_on_top=true;
    		}
    	}
    Some typo I quess... you have both Y comparisons using "<" less than expression later one IF used originally ">"

    Anyway, if you want I can have a little peek on your movie to check out what bugs if you attach the movie.

  14. #14
    Member
    Join Date
    Jul 2006
    Posts
    56
    This problem has been resolved and the game can be viewed at www.chessclubfriend.com, Thanks

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