Sorry for the seemingly basic question but I can't find any answer and I've been trying for a couple of hours...
Basically I'm trying to get the hero to reset when his x /y coord is past the stage's x / y coord. What I'm having trouble with is retrieving his x and y coord.
For example, if I wasn't using Box2D I'd just do something like "if hero.x > stage.stageWidth then hero.x = startx and hero.y = starty" but I don't know what I'd call my "hero.x" for Box2D.
This is what introduces hero:
and this is the code before I want the code that resets his position if found outside the stage's bounds:
I thought this would do the trick: (it compiles correctly but does nothing)
I also need help killing the current "hero" when he gets out of bounds and not just having others continuously respawn since I assume that is what would happen if that did work.
Many thanks to any help!
EDIT: Now that I think about it, I'd also have to reset his sprite, his gun, and his gun's skin. Am I going about this in a really bad way?
EDIT 2: Here is the full script: http://fixee.org/paste/2uis9qu/
Basically I'm trying to get the hero to reset when his x /y coord is past the stage's x / y coord. What I'm having trouble with is retrieving his x and y coord.
For example, if I wasn't using Box2D I'd just do something like "if hero.x > stage.stageWidth then hero.x = startx and hero.y = starty" but I don't know what I'd call my "hero.x" for Box2D.
This is what introduces hero:
Code:
public function hero(px:int, py:int, w:int, h:int) {
bodyDef = new b2BodyDef();
bodyDef.position.Set(startx/pixels_in_a_meter, starty/pixels_in_a_meter);
boxDef = new b2PolygonDef();
boxDef.SetAsBox(real_pixels(w), real_pixels(h));
boxDef.density=1.0;
boxDef.friction=.5;
boxDef.restitution=0;
bodyDef.userData = new Sprite();
bodyDef.userData.name="Player";
body=m_world.CreateBody(bodyDef);
body.SetBullet(false);
body.CreateShape(boxDef);
}
bodyDef = new b2BodyDef();
bodyDef.position.Set(startx/pixels_in_a_meter, starty/pixels_in_a_meter);
boxDef = new b2PolygonDef();
boxDef.SetAsBox(real_pixels(w), real_pixels(h));
boxDef.density=1.0;
boxDef.friction=.5;
boxDef.restitution=0;
bodyDef.userData = new Sprite();
bodyDef.userData.name="Player";
body=m_world.CreateBody(bodyDef);
body.SetBullet(false);
body.CreateShape(boxDef);
}
and this is the code before I want the code that resets his position if found outside the stage's bounds:
Code:
public function Update(e:Event):void {
m_world.Step(timestep, 10);
xspeed=0;
for (var bb:b2Body = m_world.m_bodyList; bb; bb = bb.m_next) { // for updating the body list lawl
if (bb.GetUserData()!=null) {
switch (bb.m_userData.name) {
case "Player" :
m_world.Step(timestep, 10);
xspeed=0;
for (var bb:b2Body = m_world.m_bodyList; bb; bb = bb.m_next) { // for updating the body list lawl
if (bb.GetUserData()!=null) {
switch (bb.m_userData.name) {
case "Player" :
I thought this would do the trick: (it compiles correctly but does nothing)
Code:
if (bb.GetPosition().x > stage.stageWidth) {
hero(startx,starty,15,25)
}
hero(startx,starty,15,25)
}
I also need help killing the current "hero" when he gets out of bounds and not just having others continuously respawn since I assume that is what would happen if that did work.
Many thanks to any help!
EDIT: Now that I think about it, I'd also have to reset his sprite, his gun, and his gun's skin. Am I going about this in a really bad way?
EDIT 2: Here is the full script: http://fixee.org/paste/2uis9qu/