Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / Input update interval
- - By kyonides Date 2017-08-30 02:26 Edited 2017-08-30 02:55
So far I've seen and read Gosu (for Ruby) usually updates its contents or its input info every 16.6 milliseconds unless you change that right at the beginning. I've been having an issue with the input update stuff because I need the game to update images every 40 milliseconds or less to make them run smoothly or decently at least, but then I see that handling input becomes a pain you know where. It updates the button_down? method too often for my needs and the only thing I could do was to make my game ignore a button that has not released so far, forcing the player to keep pushing the button once and again. Most of the time it might work if I'm working with menus but not when walking on a map with my playable characters. How can I alter the input update frequency while keeping the refresh update frequency intact? I need it to ignore a pressed button that is not released for a few extra milliseconds...

I'd also be grateful if you could share some ideas on how to implement graphical transitions on Gosu (for Ruby).
Parent - - By jlnr (dev) Date 2017-09-02 16:02 Edited 2017-09-02 16:50
You'll have to implement input delays in your game code. For example, if the player can hold the spacebar to keep shooting, you shouldn't create a new projectile every tick in Window#update when button_down? Gosu::KB_SPACE, since 60 bullets per second are probably too many. Instead, you should have a counter variable like @reload_time that you set to 30 when the player shoots, and then you decrement it every time update is called, and only when it reaches 0, you create another projectile. Now the player can shoot twice per second, and it will feel much nicer than if Gosu would only update button_down? every 500ms, because the first shot still happens immediately after pressing the button.

It's quite common for game objects in Gosu to have counter variables that count up or down until something happens.
Parent - - By kyonides Date 2017-09-02 16:34
I see, but I HATE to implement such counters, they look weird and I can't place it in button_down? method that's the one that gets updated often. Isn't there any other alternative? It had become a nuisance to update the counter info every time I had to change the update interval... Besides I have already noticed that even the counter blocks some attempts to press a different button that should trigger different methods...
Parent - - By jlnr (dev) Date 2017-09-02 16:54
There is no alternative, but of course you can write a helper method/class that wraps this and reuse it throughout your game.
Parent - - By kyonides Date 2017-09-02 17:06
Sounds bad... What can you tell me about the transitions? What should I learn to implement them in my Ruby Gosu projects? (Don't tell me I can only do that via C extensions... -_-)
Parent - - By jlnr (dev) Date 2017-09-02 18:27
I'm not sure what kind of transition you are looking for, but this video shows a game that I've built with pure Gosu (in C++, but the code would look the same in Ruby - no C necessary):

https://www.youtube.com/watch?v=HyNmL_PogKE

(The first ten seconds are basically just different screens transitioning into each other. Ignore the rest, the game is dead now :))

The way I usually do it is that each screen (menu, dialog box, ...) is a different class/object and when a transition happens, I divide the number of ticks by total duration so that I end up with a number t between 0.0 and 1.0 as the "position" inside of the current transition. For example, if I wanted one screen to zoom in while another fades out, I would do this in draw:

def draw
  t = position_in_transition() # 0.0...0.1
  @previous_screen.draw
  overlay_color = Gosu::Color.argb(t * 255, 0, 0, 0)
  Gosu.draw_rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, overlay_color, 999999)
  Gosu.scale(t) { @next_screen.draw }
end


So...it's all possible, but you also have to do it all by yourself.
Parent - By kyonides Date 2017-09-05 02:24
OK, it seems to be something I need to carefully analyze in hopes of finding a not so heavy solution to make it happen... Perhaps I could use a Module to avoid using global variables...
Parent - - By kyonides Date 2017-09-19 18:49
What I was thinking had to do more with black and white graphics (or grayish gradients) that could let you perform the transitions in many ways. Let's say I've got a graphic for a box transition, meaning there is a box inside another box and even another inside the last one and so on, then you'd see that half of the boxes make parts of the previous screen disappear and the next scene shows up slowly...
Parent - - By lol_o2 Date 2017-09-20 13:04 Edited 2017-09-20 14:22
If you mean something like in RPG Maker XP, where you have grayscale transition effects that go transparent from white to black, that's something you can do with shaders, which are sadly not supported natively by Gosu. You'd need to use Ashton extension library.


If you want the shader: http://lpaste.net/6797344972136775680

You could probably achieve this with pure Gosu, but that requires two images and shifting between them with default/multiply drawing mode.

EDIT:
Well, I was right. Perfectly doable in pure Gosu, although you lose non-smooth effect option (where pixels are either fully opaque or transparent).
Have fun: https://www.mediafire.com/file/55s5yc55e6x09w5/gosu_transintion_example.zip
Parent - - By kyonides Date 2017-09-23 03:25
Thanks for your assistance, lol_o2, I'll be checking it out once I get some spare time, storms kept me busy lately, but why do you call yourself an anonymous coward on the first link you posted? O.o
Parent - - By lol_o2 Date 2017-09-23 14:12
Uh, what link? Wut? >_>
Parent - By kyonides Date 2017-09-25 21:29
The lpaste.net link XD

I couldn't make it work with just fake images, the ones recorded by window.record feature, so I had to create black rectangles to simulate a transition. Now my issue is that it gets stuck for a few seconds especially while transitioning between maps...
Up Topic Gosu / Gosu Exchange / Input update interval

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill