Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Big loop cycle

Hello comunity! Anybody try create game with very much objects? if i create cycle like 100 objects it work good but if i create cycle with 2000 objevts its work slowly/ I try use coroutines but i still don't understand it is possible create much object in game? like 20000 for example/
PS
sorry for my english :)

Tagged:

Comments

  • IgnatzIgnatz Mod
    edited July 2016 Posts: 5,396

    Hi @VictorFR - We like to help, but we need to see some code (so we know what objects you are using, and how you are drawing them)

    PS there is no need to apologise for your English (I'm sure I can't speak your language at all!). Just do your best and we will try to understand.

  • Posts: 2

    i have very symple code function now: Ok i will send code today, now i can't (

  • dave1707dave1707 Mod
    edited July 2016 Posts: 7,613

    @VictorFR You can draw 20,000 objects (mesh items), but depending on what size they are and what they're doing will affect the FPS. For instance, drawing 20,000 mesh items at different sizes runs at these FPS on an iPad Air.

    EDIT: The positions of these items were calculated only once. If the positions don't change, an image can be created and drawn at near 60 FPS. But a lot is going to depend on what you want to do with the objects you draw.

    FPS 59.7   size 2x2
        59.6        5x5
        59.4       10x10
        30         20x20
        11.5       50x50
    

    Here's an example of drawing 20,000 (size 5x5) objects at random screen positions at 19.1 FPS on my iPad Air.

    displayMode(FULLSCREEN)
    
    function setup()
        fill(255)
        fps=60
    end
    
    function draw()
        background(40, 40, 50)
        m=nil
        collectgarbage()
        m=mesh()
        for z=1,20000 do
            m:addRect(math.random(WIDTH),math.random(HEIGHT),5,5)
            m:setRectColor(z,0,100,100,255)
        end
        m:draw()
        fps=.9*fps+.1/DeltaTime
        text(fps,WIDTH/2,HEIGHT-50)
    end
    
  • dave1707dave1707 Mod
    Posts: 7,613

    @VictorFR Here's the above code, but instead of creating a mesh each draw cycle, this creates a mesh 1 time and updates only the screen positions each draw cycle. The result is almost a 2x increase in FPS. The below code runs at approx 37 FPS instead of the original 19 FPS. This just shows that there are different ways to do the same thing, some slow and some fast.

    displayMode(FULLSCREEN)
    
    function setup()
        fill(255)
        fps=60
        m=mesh()
        for z=1,20000 do
            m:addRect(math.random(WIDTH),math.random(HEIGHT),5,5)
            m:setRectColor(z,0,100,100,255)
        end
    end
    
    function draw()
        background(40, 40, 50)
        m:draw()
        fps=.9*fps+.1/DeltaTime
        text(fps,WIDTH/2,HEIGHT-50)
        for z=1,20000 do
            m:setRect(z,math.random(WIDTH),math.random(HEIGHT),5,5)
        end
    end
    
Sign In or Register to comment.