Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by davidx

Hi,
I have a simple game, sprite travels forward at set speed. Hold the mouse down and it accends, release the mouse and it falls again.

I want to introduce a replay button when the level ends, my thought is to create an array in the sprite entity and push a 1 every time the mouse is down else a 0. The when replay is pressed, POP the value from the array every update iteration and accend if 1 else nothing.

Does this sound like a good approach? I think that even if the frame rate changes during replay, i.e. is different than game play, this should still work as the x position will only change on the update call anyway?

Or is there a better way to achieve this? Btw, I have no enemies to consider.

Thanks.

1 decade ago by Vlad

You could end up with a really huge array. I mean at 30 fps this means 1800 entries per minute.

I'd track the frame count so when you replay, just check if next entry in your array has the current frame count, and if does, apply it (pop it or whatever you wanted). For example:

this.replayArray.push({frame : ig.game.currentFrame, action : ...});

Of course, this.currentFrame++ in your game's update() method.

1 decade ago by dominic

From my experience, saving the actual position is much easier and has much less problems than relying on timing and exact "reproducibility".

So, I'd save the current timestamp and position of the entity:
this.replayArray.push( [ig.Timer.time, ig.game.player.pos.x] );

I wouldn't worry too much about the size of the resulting array. 1800 entries per minute seems reasonable, imho. You could also just save the position 10 times per second and then interpolate all the frames in between in your replay.

1 decade ago by davidx

Thanks for the replies. I am not worried about the size of the array as each level short enough.

Dominic, I like your idea, qlthough I would be concerned that the time would not nessesarily be correct either if the framerate drops/increases a lot.

I might try and push just the x pos in and use that as the lookup to decide to fly or not.

What do Ye think?
Page 1 of 1
« first « previous next › last »