Jump to content


Photo

Smoothly Increasing a Variable At A Fixed Rate


  • Please log in to reply
5 replies to this topic

#1 Recreate

Recreate

    Furry

  • GMC Member
  • 2928 posts
  • Version:GM8

Posted 22 February 2012 - 01:01 AM

Hello, I've encountered a bit of a problem in a small program i've been writing for something.
What it does is render a screen of boxes moving at different rates. One at 100 pixels per second, another 200, etc. I've got that figured out.
However, I've encountered a problem. The boxes move at expected speeds if it's running at the target speed, of 30 frames per second. But it breaks, if it runs slower, such as at 6, when rendering it for higher resolutions. The boxes move slower than they should.
(this is supposed to be a simple LCD response time test, for the record)

The relevant code block is as follows.
//define dimensions
global.testAreaWidth = 720;
global.testAreaHeight = 480;

//define block size
blockWidth = global.testAreaWidth/5;
blockHeight = global.testAreaHeight/5;

//define block movement speed(px/s)
blockSpeed[0] = 100;
blockSpeed[1] = 200;
blockSpeed[2] = 400;
blockSpeed[3] = 800;


//spawn blocks
instance_create(global.testAreaWidth/16,global.testAreaHeight/16,block0);
instance_create(global.testAreaWidth/16,(global.testAreaHeight/16)+(blockHeight+(blockHeight/16)),block1);
instance_create(global.testAreaWidth/16,(global.testAreaHeight/16)+((blockHeight+(blockHeight/16))*2),block2);
instance_create(global.testAreaWidth/16,(global.testAreaHeight/16)+((blockHeight+(blockHeight/16))*3),block3);

//initiate their motion
block0.hspeed=blockSpeed[0]/room_speed;
block1.hspeed=blockSpeed[1]/room_speed;
block2.hspeed=blockSpeed[2]/room_speed;
block3.hspeed=blockSpeed[3]/room_speed;
Now, The problem is after the "initiate their motion" comment.
block0.hspeed=blockSpeed[0]/room_speed;
(there are 4, let's just use the first)
I figured, that if i divided the number of pixels to move per second, by the room speed, and set that to the horizontal velocity of the block, that it would work. The blocks would move at the desired speed when the recorded frames are played back at the speed of room_speed. (important, this is my goal) However.. tests have shown otherwise.
You may acquire my GMK hereto test.

Now.. I'm not quite sure what the cause of this is. Is there a flaw in my logic I have not realized? Have I misunderstood how hspeed functions? Can anybody notice what I've done wrong?

Thank you. Apologies in the scenario that the solution/problem is blindingly obvious, and that I missed it. It happens sometimes.
~Re

Edited by Recreate, 22 February 2012 - 01:20 AM.

  • 0

#2 Jazza4Lyf

Jazza4Lyf

    GMC Member

  • GMC Member
  • 240 posts
  • Version:GM:Studio

Posted 22 February 2012 - 01:43 AM

[Edit on account of complete idiocy... =S]

Edited by Jazza4Lyf, 22 February 2012 - 01:49 AM.

  • 0

#3 thegame

thegame

    Flying Penguin

  • GMC Member
  • 1407 posts
  • Version:GM:Studio

Posted 22 February 2012 - 01:45 AM

Nah, your scripts are working perfectly... its because the blocks' final positions are not at a multiple of 100 so your tests appear to be returning false...

Edit: by the way... I think you should use show_message rather than show error when you want to start

Edited by thegame, 22 February 2012 - 01:47 AM.

  • 0

#4 Recreate

Recreate

    Furry

  • GMC Member
  • 2928 posts
  • Version:GM8

Posted 22 February 2012 - 02:37 AM

Huh? My tests weren't scripted. What I did is render a video at 320x240 and then 720x480. and compared the number of frames. with the first it was around 60. with the latter. it was about 140. Speed was cut nearly in half. That's the problem. D:

I also used show_error rather than show_message, because it allows you to cancel easily.
  • 0

#5 thegame

thegame

    Flying Penguin

  • GMC Member
  • 1407 posts
  • Version:GM:Studio

Posted 22 February 2012 - 02:40 AM

Well... in the file I downloaded there was no video, it was all running as a code...
I think they would move slower than they should because a lower FPS will effect the room speed, but room speed doesn't effect the FPS.
  • 0

#6 Recreate

Recreate

    Furry

  • GMC Member
  • 2928 posts
  • Version:GM8

Posted 22 February 2012 - 03:51 AM

Well... in the file I downloaded there was no video, it was all running as a code...
I think they would move slower than they should because a lower FPS will effect the room speed, but room speed doesn't effect the FPS.

Huh? The room speed is fixed. It's the target speed at which the game will run. The FPS is just the actual achieved speed.
http://dl.dropbox.com/u/3676711/lcd_movement_test%20%282%29.gmk (slightly updated now)
Download this, set record in scr_test_init to 1, this will enable recording, create a directory in the same directory that the gmk is stored and name it "frames". now go to scr_init and set the testarea width and height to 320 and 240. run it. then look at the files. Delete them, try again with width and height at a considerably larger resolution so that the FPS when rendering is low. then observe the number of frames increase.

This happens because it's taking more steps to make what (block0.x+blockWidth) evaluates to reach what (global.testAreaWidth-(global.testAreaWidth/16)) evaluates to.

Edit: Maximum Derp. I've realized the blindingly obvious about 2 days ago but just now I updated it.

Edited by Recreate, 24 February 2012 - 09:59 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users