Author Topic: Teleport player to location of FlxObject  (Read 1674 times)

Radstronomical

  • Member
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
    • tuhmblur
Teleport player to location of FlxObject
« on: Sat, Oct 16, 2010 »
Hey all,

I'm working on my first flixel game (and game in general sort of), looked through the forums, couldn't really find a good answer to this. I'm trying to teleport my player to the location of a FlxObject.

Here's the code from inside the FlxSprite class of the object...

Code: [Select]
public function getBallLocation():FlxPoint
{
var l: FlxPoint = new FlxPoint(x, y);
return l;
}

and here's what I have in my PlayState...

Code: [Select]
public function teleport(l: FlxPoint):void
{
_tosser.x = l.x
_tosser.y = l.y;
_ballspace.destroy();
ballIsDeployed = false;
}



override public function update():void
{
if(FlxG.keys.justPressed("C"))
{
if(ballIsDeployed){
teleport(_ballspace._teleball.getBallLocation());
}
}


super.update();
}

I'm posting in here, so needless to say it isn't working. Any ideas?

zuperxtreme

  • Contributor
  • ****
  • Posts: 254
  • Karma: +0/-0
    • View Profile
    • Buddah
Re: Teleport player to location of FlxObject
« Reply #1 on: Sat, Oct 16, 2010 »
How about using the reset() function? ???
..."without order nothing exists, without chaos nothing evolves"... 
Zoklet.net

Billy

  • Active Member
  • ***
  • Posts: 159
  • Karma: +0/-0
  • Herper of Derps
    • View Profile
    • billy.wenge-murphy.com
Re: Teleport player to location of FlxObject
« Reply #2 on: Sat, Oct 16, 2010 »
You can't start a variable (or function, or constant, etc) name with a number. "1" is not valid. You can put a number anywhere else though, like a1, myvar1, point1, etc. The compiler should notify you about this.

edit: Ah, Omega's right, that's an L. They're practically indistinguishable on my screen
« Last Edit: Sat, Oct 16, 2010 by Billy »

OmegaStorm

  • Member
  • **
  • Posts: 36
  • Karma: +0/-0
    • View Profile
    • OmegaStorm Productions
Re: Teleport player to location of FlxObject
« Reply #3 on: Sat, Oct 16, 2010 »
I think that's a lower case L, not a one. Did you run a trace to see if the function is even firing?

Radstronomical

  • Member
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
    • tuhmblur
Re: Teleport player to location of FlxObject
« Reply #4 on: Sat, Oct 16, 2010 »
yeah, it's executing -- _ballspace is being destroyed and the boolean is being set to false.

Radstronomical

  • Member
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
    • tuhmblur
Re: Teleport player to location of FlxObject
« Reply #5 on: Sat, Oct 16, 2010 »
I should probably have noted that I'm getting an error 1119 on "    teleport(_ballspace._teleball.getBallLocation()); "

is it a problem that I'm trying to get this from an object within a flxGroup?

OmegaStorm

  • Member
  • **
  • Posts: 36
  • Karma: +0/-0
    • View Profile
    • OmegaStorm Productions
Re: Teleport player to location of FlxObject
« Reply #6 on: Sat, Oct 16, 2010 »
Maybe just " teleport(_teleball.getBallLocation()); " would work

Radstronomical

  • Member
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
    • tuhmblur
Re: Teleport player to location of FlxObject
« Reply #7 on: Sat, Oct 16, 2010 »
Nope, no good. I am so confused!

Radstronomical

  • Member
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
    • tuhmblur
Re: Teleport player to location of FlxObject
« Reply #8 on: Sat, Oct 16, 2010 »
Fixed! I needed to sort _ballspace and then move the player to (_ballspace.members[0].x, _ballspace.members[0].y)