-
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).
-
M.D.
shadow.y = 200 - shadow.parent.y;
-
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.
-
M.D.
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.
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|