00:00
00:00
Newgrounds Background Image Theme

TheADHX just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Player above all? (AS3)

457 Views | 13 Replies
New Topic Respond to this Topic

Player above all? (AS3) 2013-09-05 15:21:22


So I have a game class that adds my player and my level, then in the level I add tiles to the stage. The problem I'm having is the player won't go on top of the tiles no matter what I try. I've tried doing addChildAt and other methods, but I can't seem to get it to work.

Response to Player above all? (AS3) 2013-09-05 15:25:20


post code

Response to Player above all? (AS3) 2013-09-05 15:26:24


At 9/5/13 03:21 PM, reiger wrote: So I have a game class that adds my player and my level, then in the level I add tiles to the stage. The problem I'm having is the player won't go on top of the tiles no matter what I try. I've tried doing addChildAt and other methods, but I can't seem to get it to work.

addChildAt doesn't do anything if you add the player first. You want to use setChildIndex(hero, numChildren - 1) to bring him to the top. The higher index is closer to the top. Or addChild the player last. You might want to have a function that gets run every time you addChild something which places the player at the top.

Response to Player above all? (AS3) 2013-09-05 15:30:39


At 9/5/13 03:26 PM, MSGhero wrote:
At 9/5/13 03:21 PM, reiger wrote: So I have a game class that adds my player and my level, then in the level I add tiles to the stage. The problem I'm having is the player won't go on top of the tiles no matter what I try. I've tried doing addChildAt and other methods, but I can't seem to get it to work.
addChildAt doesn't do anything if you add the player first. You want to use setChildIndex(hero, numChildren - 1) to bring him to the top. The higher index is closer to the top. Or addChild the player last. You might want to have a function that gets run every time you addChild something which places the player at the top.

Hmm, still having the same issue.

public function Game() 
		{
			addChild(levelOne);
			
			addChild(hero);
			hero.x = 150;
			hero.y = 100;
			setChildIndex(hero, numChildren + 1)
			
			addEventListener(Event.ENTER_FRAME, oef);
		}

I'm guessing it's because the tiles are place in the LevelOne class or something. Any ideas?

Response to Player above all? (AS3) 2013-09-05 15:34:37


At 9/5/13 03:30 PM, reiger wrote: I'm guessing it's because the tiles are place in the LevelOne class or something. Any ideas?

That should have nothing to do with it. And I said minus 1, not plus 1. Didn't that throw an error when you tried it?

You need to give more code than 2 addChilds, because just from that, your code should work fine. Are you addChilding things later or moving the player offscreen or something?

Response to Player above all? (AS3) 2013-09-05 15:36:43


At 9/5/13 03:34 PM, MSGhero wrote:
At 9/5/13 03:30 PM, reiger wrote: I'm guessing it's because the tiles are place in the LevelOne class or something. Any ideas?
That should have nothing to do with it. And I said minus 1, not plus 1. Didn't that throw an error when you tried it?

You need to give more code than 2 addChilds, because just from that, your code should work fine. Are you addChilding things later or moving the player offscreen or something?

The only other addChild is from my tiles from inside the LevelOne class:

var tile:Tile = new Tile();
					tile.type = myMap[i][u];
					tile.gotoAndStop(tile.type + 1);
					tile.x = tileSide * u;
					tile.y = tileSide * i;
					addChildAt(tile, 0);
                    tiles[i][u] = tile;

Oh, and yeah I did do - 1, but I tried + 1 after I didn't work haha.

Response to Player above all? (AS3) 2013-09-05 15:44:19


At 9/5/13 03:36 PM, reiger wrote: The only other addChild is from my tiles from inside the LevelOne class:

If you comment out the addChild(levelOne) line, is the player there? It sounds like you're removing the player, he's offscreen, or there's no content in the player sprite.

Response to Player above all? (AS3) 2013-09-05 15:47:47


At 9/5/13 03:44 PM, MSGhero wrote: If you comment out the addChild(levelOne) line, is the player there? It sounds like you're removing the player, he's offscreen, or there's no content in the player sprite.

Actually, no, he doesn't appear. Originally I had him INSIDE the LevelOne class, and it worked fine, but I figured it would be better to have him in the Game class if I was going to be swapping out levels. The only thing I changed was where I add him, so I'm not sure why he isn't showing up.

What else is weird is that I can still move him and when I trace his x and y it reads normal...but there is no display for him.

Response to Player above all? (AS3) 2013-09-05 16:10:53


At 9/5/13 03:47 PM, reiger wrote: What else is weird is that I can still move him and when I trace his x and y it reads normal...but there is no display for him.

x and y are properties of the DisplayObject
It doesn't matter if the object is added to the display list or not.

What is "hero" and what is "levelOne"?
Where are they defined and how?
post more code

Response to Player above all? (AS3) 2013-09-05 16:16:48


At 9/5/13 04:10 PM, milchreis wrote:
At 9/5/13 03:47 PM, reiger wrote: What else is weird is that I can still move him and when I trace his x and y it reads normal...but there is no display for him.
x and y are properties of the DisplayObject
It doesn't matter if the object is added to the display list or not.

What is "hero" and what is "levelOne"?
Where are they defined and how?
post more code

They are just classes that are linked to movie clips.

public static var hero:Hero = new Hero();
		private var levelOne:LevelOne = new LevelOne();

Response to Player above all? (AS3) 2013-09-05 16:43:42


Hide everything except for Hero.
Then gradually start showing more and more stuff.
As soon as you stop seeing Hero during one of the tests, there lies your problem.

Response to Player above all? (AS3) 2013-09-05 16:55:06


At 9/5/13 04:43 PM, kkots wrote: Hide everything except for Hero.
Then gradually start showing more and more stuff.
As soon as you stop seeing Hero during one of the tests, there lies your problem.

Got it :)

Thank you guys for your help!

Response to Player above all? (AS3) 2013-09-05 16:58:10


At 9/5/13 04:16 PM, reiger wrote: They are just classes that are linked to movie clips.

public static var hero:Hero = new Hero();
private var levelOne:LevelOne = new LevelOne();

Both should be private, neither one static.
This probably not solve your problem, but prevents headaches later.

As recommended, add one at a time to the display list.
Does level show up if displayed alone?
Does player show up alone?

Now try to add both.
Do both show up?