A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Shadow effect problem

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    15

    Shadow effect problem

    Hey FlashKit!

    I'm trying to create a small shadow for an enemy, but I'm having problems with updating the position of it :/ Here's the code...

    This part goes into the constructor:

    Actionscript Code:
    // Draw shadow
                shadow = new Sprite();
                sdw_GFX = shadow.graphics;
                sdw_GFX.beginFill(0x000000, .5);
                sdw_GFX.drawCircle(0, 0, 10);
                sdw_GFX.endFill();
                shadow.scaleY = .3;
                addChild(shadow);
               
                updateShadow();


    This is the updateShadow method:

    Actionscript Code:
    private function updateShadow():void {
               
                if (shadow.y != 200) {
                   
                    shadow.y = 200;
                }
            }

    And also I have an ENTER_FRAME loop that calls updateShadow();

    Here's the problem; the shadow is always positioned 200 pixels below the enemy (the enemies are flying around btw), but what I want is to make the shadow stick to the 200 point on stage (to make it look like it's on the ground).

  2. #2
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    shadow.y = 200 - shadow.parent.y;
    lather yourself up with soap - soap arcade

  3. #3
    Junior Member
    Join Date
    Sep 2010
    Posts
    15
    Thank you, that worked!

    But, can you just explain to me why my code didn't do the trick? I can honestly not see anything wrong with it.

  4. #4
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    your shadow sprite is within your enemy sprite. So where ever the enemy is the shadow will be at that position + 200y. If your were to add the shadow to the stage then it would always appear at 200y. An objects position is relative to its parents position.
    lather yourself up with soap - soap arcade

  5. #5
    Junior Member
    Join Date
    Sep 2010
    Posts
    15
    Okay, I understand. Thanks man!

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