Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Tom Black
    @blacktm
    @Nakilon Good summary of some distribution options. Ruby is great for prototyping, but distribution has been a bit of a pain. MRuby helps a lot, since you can compile everything down to a single binary, but is missing a lot of standard library features. Dragon Ruby (https://dragonruby.itch.io/dragonruby-gtk) has invested a lot into distribution, with binaries for Windows, Linux, and macOS able to created and uploaded to Itch.io (they also use MRuby, AFAIK). I’m pretty intrigued by WebAssembly as a simple way to distribute and run. My dumb Ruby/WASM experiment has gotten a lot of attention: https://github.com/blacktm/ruby-wasm
    Maybe it’s time to bring it to Ruby 2D.
    mklnk
    @mklnk
    Regarding mruby, on Mac, I’m finding my built apps are missing a lot of libraries and won’t run on other machines unless simple2d is installed. Is there a way to avoid that? I thought the whole point would have been that simple2d is bundled with the app.
    Savi
    @TheRealSavi
    What is the part of the code that is calling the update proc every 'x' ms according to the windows fps?
    Sourav Goswami
    @Souravgoswami
    Haven't been here for a while! Hope you guys are doing well!

    As I said above, calling any method, or a proc or any object method can be done with this:

    #!/usr/bin/ruby -w
    require 'ruby2d'
    STDOUT.sync = true
    
    i = 0
    on(:key_held) do |k|
        i += 1
        puts :hi if i.%(get(:fps).div(2)).zero?
    end
    
    on(:key_up) { i = 0 }
    
    show

    You can reduce the .div(2) to something lesser, remove the div and the if block will be true every FPS (better remove the whole thing then...)

    You are increasing i by 1 on every frame
    i.%(get(:fps) Gets the fps, say it's 60, if you want a 0.5 seconds delay, divide 60 / 2, you get 30, when i is 30, that means 0.5 seconds passed, so the if block evals to true
    And so on... Reduce .div(2) to .div(4), the if blocks gets true every quarter of a second...
    the https://github.com/Nakilon/rbtris is kind of done because any new feature will make it larger than 200 loc
    you can add it to the showcase now if you wish
    mikelinke
    @mikelinke
    is 200 lines a magic number? or you just don't want it to be a big file for demo purposes?
    Victor Maslov
    @Nakilon
    the next feature I've added is displaying the next piece but it costed 20 loc so it's a new "loc-250" branch that is yet far from being done -- who knows when and what it'll have at the end
    @mikelinke I just could not make it 150 )
    mikelinke
    @mikelinke
    what is the hard limit? I built my own pre build linker to replace requires with the full text of the referenced file. i had a HUGE data declaration in one file, and mruby failed to build because of "too big code block". I moved that out into a .dat file in the assets folder, but i'm wondering what the actual limit is for a single .rb file when building
    Victor Maslov
    @Nakilon
    initially it was someone's 204 loc gist https://gist.github.com/obelisk68/15ffdf1bfd82953361be0264b5ea4119 that was quickly fully rewritten and fixed and went almost to 150 but it was still barely playable so I've started improving it

    what was added:

    • SRS canonical rotation
    • canonical increase of speed
    • scoreboard stored at $HOME/.rbtris
    • ability to fall down only partially
    • ability to hold keys UP, LEFT and RIGHT
    • pause key
    • restart key
    • Mutex

    and so it reached 200

    Victor Maslov
    @Nakilon
    seeing the next piece helps a lot
    helped me to improve my highscore from 200 to 269 )
    Tom Black
    @blacktm
    @Nakilon The game looks awesome, congrats! Will absolutely add to the showcase.
    @mklnk Dang, I thought I statically added all those libraries to the mruby build, so an app could run totally standalone. Will have to see what’s up.
    Tom Black
    @blacktm
    @TheRealSavi Regarding the update proc, it gets kicked off in the native extension here: https://github.com/ruby2d/ruby2d/blob/master/ext/ruby2d/ruby2d.c#L931
    Also, I saw you sent that PR for some UI elements. Looks really interesting!
    If folks haven’t seen, we now have a Flappy Bird in Ruby! 🐤
    https://github.com/tiagopog/flappy_bird
    Patrick W
    @sickday_gitlab
    Hi! is it possible to change the Ruby2D::Window#viewport_hieght and width dynamically? Like for edge scrolling to areas outside the viewport?
    mikelinke
    @mikelinke
    I bet not. It's VERY common in games that changing resolution requires the program to be restarted. If AAA titles can't figure it out, i doubt it's something we'd expect a library like this to support.
    my suggestion would be to keep a static viewport size, but implement your own scaling within that viewport
    Patrick W
    @sickday_gitlab
    Sounds good. I was going to do that anyway if I couldn't find an answer. I appreciate it though! @mikelinke
    Tom Black
    @blacktm
    I think we’re only setting the OpenGL viewport once (see https://github.com/simple2d/simple2d/blob/master/src/gl.c#L165), but probably possible to set at any time, might not have the expected visual effect though. Creating your own “scene” and moving all objects around will probably be easiest. I was thinking a “screen shake” effect would be best implemented at the viewport level.
    Victor Maslov
    @Nakilon
    image.png
    heh, my tetris is among these 10000-stars and 1000-contributors repos today
    Tom Black
    @blacktm
    Whoa, nice work @Nakilon! 🙌
    Victor Maslov
    @Nakilon
    @blacktm thank you!
    Golden506
    @Golden506

    I have this code:

    update do
      #animate menu buttons
      on :mouse do |event|
        if start.contains? Window.mouse_x, Window.mouse_y
          start.color = "gray"
        else
          start.color = "white"
        end
        if config.contains? Window.mouse_x, Window.mouse_y
          config.color = "gray"
        else
          config.color = "white"
        end
        if quit.contains? Window.mouse_x, Window.mouse_y
          quit.color = "gray"
        else
          quit.color = "white"
        end
      end
    end
    show

    It works fine at first, but after a few seconds of the window being open the whole thing starts to lag unbearably.

    I'm running Ubuntu 18.04 by the way.
    mikelinke
    @mikelinke
    start, config and quit are not defined here. They're surely defined somewhere else.
    can we see that? a mistake i made early one was recreating my 2d objects inside the update loop
    this caused a new copy of the object to be generated at every frame, which quickly burned through system memory
    mikelinke
    @mikelinke
    i deleted a comment that turned out to be incorrect
    Golden506
    @Golden506
    They are defined outside the, or in fact any, loop, yes:
    #menu boxes and text
    main_menu = [
    backing = Rectangle.new(z: 0, x: 70, y: 200, width: 500, height: 195, color: 'black'),
    start = Rectangle.new(z: 1, x: 90, y: 225, width: 460, height: 35, color: 'white'),
    config = Rectangle.new(z: 1, x: 90, y: 280, width: 460, height: 35, color: 'white'),
    quit = Rectangle.new(z: 1, x: 90, y: 335, width: 460, height: 35, color: 'white'),
    mikelinke
    @mikelinke
    my suggestion would be load your system monitor up as well and watch memory allocation to the ruby process
    seeif that ticks up before the app becomes unresponsive
    but, if what you've shared is correct, I don't have an explanation for your issue.
    mikelinke
    @mikelinke
    i don't have access to my source code at the moment, so I can't post the actual example, but consider this pseudocode

    class R2DAssets
    @@image = Hash.new
    def self.getImage image_path, x: 0, y: 0, z: 0, height: 1, width: 1, opacity: 0
    @@image[image_path] = Array.new if @@image[image_path].nil?
    ret_ob = nil
    @@image[image_path].each do |img|
    if img.x > $screen_width
    img.show
    ret_ob = img
    break unless img.nil?
    end
    if ret_ob.nil?
    ret_ob = Image.new( image_path )
    @@image[image_path].push ret_ob
    end
    ret_ob.x = x
    ret_ob.y = y
    ret_ob.z = z
    ret_ob.height = height
    ret_ob.width = width
    ret_ob.opacity = opacity
    return ret_ob
    end
    end

    class SomeGameWidget
    def initialize
    @@visible_ui = Array.new
    @@visible_ui.push R2DAssets.get_image './assets/my_game_widget.png', x: 0, y: 0, height: 64, width: 64, z: 1
    end

    def cleanup
        @@visible_ui.each do |ui|
            ui.remove if ui.respond_to? :remove
            ui.x = $screen_width if ui.respond_to? :x
        end
    end

    end

    i encountered this problem a lot early on. to get a handle on it, i stopped every directly accessing ruby2d, and instead wrapped all requests in such a way that the assets were reused whenever possible
    this was much easier to debug than trying to track down naked ruby2d elements i might have created and lost track of
    i haven't had memory issues since going this route
    but it may mean there's an elegant ruby2d solution that I just never had to learn
    image.png
    here's a screen shot, as gitter's code highlight seems to only care about the function def and not the classes
    mikelinke
    @mikelinke
    change x > $screen_width to x >= $screen_width. but i think you get the gist