December 04, 2020, 02:22:59 PM

Author Topic: FLIP... FLIP...  (Read 1258 times)

Offline drfloyd

  • Jr. Member
  • **
  • Posts: 35
FLIP... FLIP...
« on: April 29, 2019, 06:34:01 PM »
Hello
Dr Floyd, french casual coder ! Sorry again for my english :/ I speak english like a spanish cow.

My last release in BLITZ 3D :
http://www.gamopat.com/2018/12/cosmos-the-secret-melody-v.10.html

All is ok in windowed mode, NO PROBLEMO, but when i come in fullscreen I have problem with FLIP. command.. Because I use sometimes 2 FLIPS in the same process.... because i add some images/animations in another loop

Exemple :

Graphics 320,240,32,1
setbuffer backbuffer()
do
   cls
   ;display images&animations
    gosub minigame                 ;or function minigame()   
    FLIP
loop


.minigame           ; or minigame() if function
do
    ;display additionnal images in a little part of the main image (a mini game)
    FLIP
    if keydown(28) then return
loop




So there is a FLIP into a FLIP... the result is bug display : vibrate image between 2 screens

how can i solve this ?

Thank you very much if you can help

Offline Derron

  • Hero Member
  • *****
  • Posts: 3275
Re: FLIP... FLIP...
« Reply #1 on: April 29, 2019, 07:06:37 PM »
only flip in the "main loop" if you did not do this "gosub" ?


bye
Ron

Offline Qube

  • Administrator
  • Hero Member
  • *****
  • Posts: 2567
  • I mostly code at night... Mostly.
    • SyntaxBomb - Indie Coders
Re: FLIP... FLIP...
« Reply #2 on: April 29, 2019, 07:36:02 PM »
Do your main loop something easy like :

Code: BlitzBasic
  1. Graphics 320,240,32,1
  2. SetBuffer BackBuffer()
  3.  
  4. Do
  5.    Cls
  6.  
  7.    Animations()
  8.    MiniGame()
  9.  
  10.    Flip
  11. Loop
  12.  
  13. Function Animations()
  14.     ' draw cool stuff
  15. End Function
  16.  
  17. Function MiniGame()
  18.    ' draw more cool stuff
  19. End Function
  20.  

That way you'll only get one FLIP command in your main loop :)
Mac mini ( 2018 / 2020 ), 3 GHz 6-Core Intel Core i5, 16 GB 2667 MHz DDR4, 1TB NVMe, eGPU Radeon Pro 580 8 GB, LG Ultragear 27GL83A-B 27 Inch
Commodore VIC-20, 1.1Mhz MOS 6502 CPU, 5KB RAM, VIC ( 6560 ) GPU

Until the next time...

Offline drfloyd

  • Jr. Member
  • **
  • Posts: 35
Re: FLIP... FLIP...
« Reply #3 on: April 29, 2019, 07:42:23 PM »
yes,of course...

But I want to stop/freeze the animations/game when there is a windowed mini game.... the program is big (1000ko) and i don't want to recode lot of things.

There is no easy solution ? Like stopping the backbuffering when the function minigame start ?????

Offline Derron

  • Hero Member
  • *****
  • Posts: 3275
Re: FLIP... FLIP...
« Reply #4 on: April 29, 2019, 09:40:31 PM »
You only need the flip once - as Qube already suggested.

If you want to stop animations/game then have

Code: [Select]
if minigameActive
 DoMinigameStuff()
else
 DoNormalStuff()
endif

Flip

Qube's proposal even allows for more sophisticated stuff: like having the main game rendering in the background with the mini game in the foreground. Of course the physics/logic of the maingame should be set to "paused" then.


This is the benefit of splitting Logic and Rendering into two parts - it allows to render stuff (like a static screen) or to just update the game without even having to render out something (think of a headless server).

1mb of source code is ... manageable as most of the code will NOT handle your "maingame + minigame"-split.

bye
Ron

Offline drfloyd

  • Jr. Member
  • **
  • Posts: 35
Re: FLIP... FLIP...
« Reply #5 on: May 01, 2019, 09:28:47 AM »
I know that.

I try to explain in other way :

is it possible, just after a FLIP, to copy the new image (the frontbuffer image) into the backbuffer. I want the same image in front and back.

 ;D

Offline TomToad

  • Hero Member
  • *****
  • Posts: 517
Re: FLIP... FLIP...
« Reply #6 on: May 01, 2019, 01:01:21 PM »
You could just take a "snapshot" of the back buffer just before the mini-game starts using GrabImage.  Then. while your mini-game is running, draw the image onto the screen instead of Cls, then set your viewport to the mini-game and render.

Code: BlitzBasic
  1. Graphics 800,600
  2. SetBuffer BackBuffer()
  3.  
  4. backImage = CreateImage(800,600) ;image for "Snapshot"
  5.  
  6. ;create a bunch of balls for the "main game"
  7. Type TBall
  8.         Field x#, y#, dx#, dy#
  9. End Type
  10.  
  11. For i = 1 To 100
  12.         Ball.TBall = New TBall
  13.         Ball\x = Rnd(0,799)
  14.         Ball\y = Rnd(0,599)
  15.         Ball\dx = Rnd(-1,1)
  16.         Ball\dy = Rnd(-1,1)
  17. Next
  18.  
  19. ;create a bunch of squares for the "mini-game"
  20. Type TSquare
  21.         Field x#, y#, dx#, dy#
  22. End Type
  23.  
  24. For i = 1 To 100
  25.         Square.TSquare = New TSquare
  26.         Square\x = Rnd(0,319)
  27.         Square\y = Rnd(0,239)
  28.         Square\dx = Rnd(-1,1)
  29.         Square\dy = Rnd(-1,1)
  30. Next
  31. minigame = False
  32.  
  33. While Not KeyHit(1)
  34.         Viewport 0,0,800,600 ;set viewport for entire screen
  35.        
  36.         ;main game
  37.         If Not minigame Then
  38.                 Cls ;clear the main screen
  39.                 For Ball.TBall=Each TBall
  40.                         Oval Ball\x-10,Ball\y-10,20,20,True
  41.                         Ball\x = Ball\x + Ball\dx
  42.                         If Ball\x > 809 Then Ball\X = -9
  43.                         If Ball\x < -9 Then Ball\x = 809
  44.                         Ball\y = Ball\y + Ball\dy
  45.                         If Ball\y > 609 Then Ball\y = -9
  46.                         If Ball\y < -9 Then Ball\y = 609
  47.                 Next
  48.                 ;when space is hit, switch to mini-game
  49.                 If KeyHit(57) Then
  50.                         minigame = True
  51.                         GrabImage backImage,0,0 ;this grabs the current back buffer
  52.                        
  53.                 EndIf
  54.                
  55.         ;Mini-game
  56.         Else
  57.                 DrawImage backImage,0,0 ;draw the "snapshot". No need to clear the screen as
  58.                                                                 ; the snapshot will cover anything previously drawn
  59.                 Viewport 240,180,320,240 ;set the viewport to the mini-game
  60.                 Cls ;clear the mini-game screen
  61.                 For Square.TSquare=Each TSquare
  62.                         Rect Square\x+230,Square\y+170,20,20,True
  63.                         Square\x = Square\x + Square\dx
  64.                         If Square\x > 329 Then Square\X = -9
  65.                         If Square\x < -9 Then Square\x = 329
  66.                         Square\y = Square\y + Square\dy
  67.                         If Square\y > 249 Then Square\y = -9
  68.                         If Square\y < -9 Then Square\y = 249
  69.                 Next
  70.                 If KeyHit(57) Then minigame = False ;when space is hit, end mini-game
  71.         EndIf
  72.         Flip True
  73. Wend
  74.  
------------------------------------------------
8 rabbits equals 1 rabbyte.

Offline drfloyd

  • Jr. Member
  • **
  • Posts: 35
Re: FLIP... FLIP...
« Reply #7 on: May 01, 2019, 02:10:19 PM »
thank you very much, i will try to understand your exemple...

it's crazy...

2 question relating to this :

- There is no possibility to do just a "refresh" in BLITZ ? instead of a flip between 2 images ???
- Why there is no problem in windowed mode ? (i can put FLIP everywhere just to refresh images)

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal