coding help

Game Editor comments and discussion.

coding help

Postby nightFall16 » Sun Nov 27, 2016 5:50 am

ok guyz i want to know how to use the xprevious and yprevious ??? i tried to make a game that u can rewind ur x and y position using the r key pressed but it didn't work !!
this is how i made it :
when r is down : rewind = 1; when it is up : rewind = 0;
player --> draw actor : if rewind = 1 --> player.x = xprevious and the y too
knowing that u should hold down the r so rewind value be 1 to activate the rewind every frame but when u release it the code inside the draw actor : esle : player.x = player.x and the y too
and if the engine is not suitable for this and the xprevious do not do this kind of work tell me so i can go and try using another program and please recommend me with engine that support this kind of programming or with other words this kind of abilities
User avatar
nightFall16
 
Posts: 41
Joined: Wed Jun 22, 2016 4:24 am
Score: 2 Give a positive score

Re: coding help

Postby lcl » Sun Nov 27, 2016 1:43 pm

Hello! :)

According to the Game Editor Script Reference xprevious and yprevious hold the actor's x and y coordinate from the last frame. Now, this means only the last position of the actor is stored somewhere and that alone doesn't allow rewinding the actor's position further than to the previous frame.

But the good news is that what you're trying to achieve can easily be made in Game Editor. All you need to do is to have an array of x and y positions, where you store the actor's x and y every frame. Then when rewinding, just loop backwards through the array and set the actor's position accordingly. Of course this method requires some kind of a limit for the size of the array. You could calculate it so, that the amount of previous positions stored in the array would be equal to a certain amount of seconds in game time. For example, if your game runs at 30 frames per second and you want the player to be able to rewind a maximum of 5 seconds backwards, the array sizes would be: 30 * 5 = 150. For half a minute, i.e. 30 seconds, the size would be 30 * 30 = 900. And so forth.

I think this information should get you started. This idea sounds like a great twist for a game! :) If you have any further questions, you can ask me and I'll help you. If needed, I can also provide an example .ged of the rewinding effect.
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest

cron