Making shadow in platformer
- FiendMachine
-
FiendMachine
- Member since: Jul. 13, 2010
- Offline.
-
- Forum Stats
- Member
- Level 21
- Game Developer
So am making a platformer game.What I want is that when the player is on the ground his shadow movieclip remains as it is but when he jumps his shadow movieclip plays thus becoming bigger and more transparent than before.
But the problem is that when my player jumps on a higher platform,his shadow remains on the ground,below him.
If I put the shadow movieclip inside the player,while jumping his shadow is in the air and when I keep it separate then his shadow leaves him when he gets on a different platform.
???
- Sam
-
Sam
- Member since: Oct. 1, 2005
- Offline.
-
- Forum Stats
- Moderator
- Level 19
- Programmer
Have the shadow as a separate object in your game and have it's properties change based on the distance between it and the object the shadow belongs too. You could use the value of "object.y - shadow.y" to manipulate shadow.scaleX, shadow.scaleY, shadow.alpha etc.
- Pahgawk
-
Pahgawk
- Member since: Feb. 8, 2009
- Offline.
-
- Forum Stats
- Member
- Level 07
- Animator
At 8/9/13 11:21 PM, Sam wrote: Have the shadow as a separate object in your game and have it's properties change based on the distance between it and the object the shadow belongs too. You could use the value of "object.y - shadow.y" to manipulate shadow.scaleX, shadow.scaleY, shadow.alpha etc.
Expanding on this:
At the beginning of each frame, you could set the shadow's position to the player's position and then use a while loop to keep moving it down until it touches something solid. That way it would always end up on the block of ground closest vertically to the player.
- FiendMachine
-
FiendMachine
- Member since: Jul. 13, 2010
- Offline.
-
- Forum Stats
- Member
- Level 21
- Game Developer
Expanding on this:
At the beginning of each frame, you could set the shadow's position to the player's position and then use a while loop to keep moving it down until it touches something solid. That way it would always end up on the block of ground closest vertically to the player.
Thanks!I will try again.But what should I put in the condition?
- Pahgawk
-
Pahgawk
- Member since: Feb. 8, 2009
- Offline.
-
- Forum Stats
- Member
- Level 07
- Animator
At 8/10/13 08:07 PM, MetalBooster wrote: Thanks!I will try again.But what should I put in the condition?
It sort of depends how you've got your ground set up, but for example, let's say you have an array of movieclips called groundArray.
function onEnterFrame(e:Event):void {
//Sets the shadow to the player's position to start
shadow.x=player.x;
shadow.y=player.y;
//Moves shadow down untilit touches ground
var touchingGround:Boolean = false;
while (!touchinGround) {
//Cycle through all ground movieclips to see if any are touching
for (var i:int=0; i<groundArray.length; i++) {
if (shadow.hitTestObject(groundArray[i]) {
//Exit the for and while loops
touchingGround = true;
break;
}
}
//Moves the shadow down for the next iteration. The more
//the shadow moves, the less iterations there will be,
//and therefore the more efficiently this will work.
shadow.y += 5;
}
}
The problem I can see happening is that if you move the shadow down by 10 or something, it might go a little too low. To fix that, once you've got it so that it's touching a piece of ground, you'd need a second while loop to push it back up to align it properly with the top of the ground.
- FiendMachine
-
FiendMachine
- Member since: Jul. 13, 2010
- Offline.
-
- Forum Stats
- Member
- Level 21
- Game Developer
The problem I can see happening is that if you move the shadow down by 10 or something, it might go a little too low. To fix that, once you've got it so that it's touching a piece of ground, you'd need a second while loop to push it back up to align it properly with the top of the ground.
So,does that mean that I have to set the ground's array value(0,1,2) according to the heights they are placed at?
- Pahgawk
-
Pahgawk
- Member since: Feb. 8, 2009
- Offline.
-
- Forum Stats
- Member
- Level 07
- Animator
At 8/11/13 01:36 AM, MetalBooster wrote: So,does that mean that I have to set the ground's array value(0,1,2) according to the heights they are placed at?
Nope, it shouldn't matter what order they're in. Here's the logic behind that:
Let's say groundArray[0] is lower than groundArray[1]. The shadow is moved down, and then it checks: is it touching groundArray[0]? It hasn't been moved low enough to touch that, so it continues: Is it touching groundArray[1]? It could be touching groundArray[1], and that would complete the loop.
Hopefully that made some sense. I guess it's a fairly abstract thing to try to describe. But basically, the order in the array only matters if the shadow is moved and all of a sudden it's touching two ground blocks, in which case it will stop anyway.


