Author Topic: FlxReplay cant represent mouse position properly  (Read 1131 times)

deadkidsong

  • Member
  • **
  • Posts: 42
  • Karma: +0/-0
    • View Profile
I am using v 2.5 master

In FlxReplay, I noticed that there is a mechanism to record and set screenX and screenY of FlxG.mouse but the recording system doesnt not record when mouse did not move.
Also, we dont have a system to lock mouse(let it not update screenX and Y to real mouse), so we have to let mouse update then call FlxReplay.playNext to overlap all the changes, but in the frames that dont have a mouse position record, its screenX and screenY will not be loaded. So, when replaying, the value of FlxG.mouse.screenX and Y will jump from record to current mouse's position and jump back when record meet new position of mouse position.

To fix these, we need one of these:
Record mouse position all the frames;
Let FlxG.resetInput() to reset mouse's position;
Add a flag to mouse indicate if update mouse.screenX and Y to real mouse position
tell me sth else.

Thanks,
DKS

this is my update of playstate
Code: [Select]
override public function update():void
{
FlxG.collide(simpleTilemap, thePlayer);

//Update the player
thePlayer.acceleration.x = 0;
if(FlxG.keys.LEFT)
{
thePlayer.acceleration.x -= thePlayer.drag.x
}
else if(FlxG.keys.RIGHT)
{
thePlayer.acceleration.x +=thePlayer.drag.x
}
if(FlxG.keys.justPressed("X") && !thePlayer.velocity.y)
{
thePlayer.velocity.y = -200;
}



/**
* Notice that I add "&&isRecording", because recording will recording every input
* so R key for replay will also be recorded at recording and
* be triggered at replaying
* Please pay attention to the inputs that are not supposed to be recorded
*/
if (FlxG.keys.justPressed("R") && isRecording)
{
start_play();
}

super.update();

/**
* In fact, recording is just remembering all the inputs(keyboard and mouse) at every frame.
* When replay, it reads the inputs at each frame and artificially trigger that input
* and let your input handler (the logic above this comment in thsi case) to handle it
* When recording, call replay.recordFrame() at eachframe
* when replaying, call replay.playNextFrame()
*/

if (isRecording)
{
replay.recordFrame();

//set color to dark red
replayText.color = 0xFFBD1A1E;
replayText.text = "R : " + replay.frameCount;
hintText.text = "Recording. Arrow keys : move. 'R' : replay."

FlxG.mouse.show();
theCursor.visible = false;
}
else
{

replay.playNextFrame();

//set color ro blue
replayText.color = 0xFF0080FF;
replayText.text = "P : " + replay.frame +"/" + replay.frameCount;
if (replay.finished) {
start_record();
}
hintText.text = "Replaying. Press wait until it finishes."


theCursor.visible = true;
FlxG.resetInput();
theCursor.x = FlxG.mouse.screenX;
theCursor.y = FlxG.mouse.screenY;

FlxG.mouse.hide();
}


}

FlxG.resetInput did nothing about mouse position
Code: [Select]
static public function resetInput():void
{
keys.reset();
mouse.reset();
}

//mouse
public function reset():void
{
_current = 0;
_last = 0;
}

MouseRecord doest not record when mouse didnot move
Code: [Select]
public function record():MouseRecord
{
if((_lastX == screenX) && (_lastY == screenY) && (_current == 0) && (_lastWheel == wheel))
return null;
_lastX = screenX;
_lastY = screenY;
_lastWheel = wheel;
return new MouseRecord(screenX,screenY,_current,wheel);
}


Adam Atomic

  • Founder
  • Key Contributor
  • *****
  • Posts: 852
  • Karma: +0/-0
  • new dad
    • View Profile
    • Adam Atomic
Re: FlxReplay cant represent mouse position properly
« Reply #1 on: Mon, May 2, 2011 »
if the replay is being played through FlxG's interface, then the mouse stuff should be a non-issue - see FlxG.recordReplay() and FlxG.reloadReplay()

deadkidsong

  • Member
  • **
  • Posts: 42
  • Karma: +0/-0
    • View Profile
Re: FlxReplay cant represent mouse position properly
« Reply #2 on: Mon, May 2, 2011 »
OMG, I didn't notice that!

====LATER====

I am still trying to use FlxG interface for replay, at the meantime, found a bug:

Posted this at github, as it is not fixed at dev branch!

https://github.com/AdamAtomic/flixel/issues/141



Adam Atomic

  • Founder
  • Key Contributor
  • *****
  • Posts: 852
  • Karma: +0/-0
  • new dad
    • View Profile
    • Adam Atomic
Re: FlxReplay cant represent mouse position properly
« Reply #3 on: Mon, May 2, 2011 »
k should be good to go