Author Topic: Hi there - Newb Question :)  (Read 6239 times)

Offline Crivens

  • Prof. Inline
  • *****
  • Posts: 913
    • View Profile
Re: Hi there - Newb Question :)
« Reply #15 on: 2011-Jun-14 »
Ampos: You should push onto the array rather than redimming. Is a bit less code and is easier to read IMO.

Cheers
Current fave quote: Cause you like musicians and I like people with boobs.

Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1137
    • View Profile
    • My GLBasic code archiv
Re: Hi there - Newb Question :)
« Reply #16 on: 2011-Jun-14 »
Hi and welcome.
As you can see, there are often many solutions for one problem. As a programer its up to you, to find the one, that fits best to your needs. My solution for your Problem would be GRABSPRITE:
Code: (glbasic) [Select]
REPEAT
      DRAWSPRITE 1, 0,0
      DRAWRECT RND(800), RND(600), RND(100), RND(100), RGB(RND(255), RND(255), RND(255))
      GRABSPRITE 1, 0,0, 800,800
      SHOWSCREEN
UNTIL KEY(28)
MOUSEWAIT
END
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4176
  • On the shoulders of giants.
    • View Profile
    • My Apps
Re: Hi there - Newb Question :)
« Reply #17 on: 2011-Jun-14 »
GRABSPRITE would again grab the whole screen (like USEASBMP) and any action on it. It would be OK on just the rectangles but if you want to add anything else (moving player etc.) then avoid.
I came. I saw. I played.

Offline quangdx

  • Mr. Polyvector
  • ***
  • Posts: 233
  • work hard / play hard
    • View Profile
    • Asobi tech
Re: Hi there - Newb Question :)
« Reply #18 on: 2011-Jun-15 »
Going back to the original question, I've just tested CLEARSCREEN -1 using GLBasic 9.040
and it gives the required effect.

Code: (glbasic) [Select]
CLEARSCREEN -1
REPEAT
      DRAWRECT RND(800), RND(600), RND(100), RND(100), RGB(RND(255), RND(255), RND(255))
      SHOWSCREEN
UNTIL KEY(28)
MOUSEWAIT
END

I know previously it would flicker between odd and even frames of rendering (back and front buffers, as they were swapped with the SHOWSCREEN command) But it now looks like they are one in the same.


I'm trying to display lots of random rectangles on the screen, adding one with each loop but I'm finding the SHOWSCREEN command appears to be getting in the way as its clearing the screen on every loop. What I'm wanting is to add a rectangle to screen on every loop rather than draw, show, clear, repeat.

I don't want the showscreen command to clear the backscreen every time, I want the rectangles to randomly overlap and fill the screen. Is there an alternative command to use to draw to the main screen or prevent the backscreen from wiping?

Any help would be appreciated. :)

Steve.
Asobi tech - the science of play.
Spare time indiegame developer.

Offline Stevester

  • Mc. Print
  • *
  • Posts: 12
    • View Profile
Re: Hi there - Newb Question :)
« Reply #19 on: 2011-Jun-15 »
Thanks for the responses on this one guys.

Looks like there are a few options to achieving what I was looking for, and running through them has led me onto learning some of the other commands.

I like the fading / shrinking effect in particular - adds a bit of style to the program :)

Struggling to understand the 'self' command though. Can't find reference to it in the help doc:

Code: (glbasic) [Select]
FUNCTION Set: l%, t%, w%, h%, colour%
self.left = l
self.top = t
self.width = w
self.height = h
self.colour = colour
  ENDFUNCTION

Cheers,

Steve.

MrTAToad

  • Guest
Re: Hi there - Newb Question :)
« Reply #20 on: 2011-Jun-16 »
Self is used to let a function in a type access a variable defined in it :

Code: (glbasic) [Select]
TYPE TTest
  a%

  FUNCTION test%:
    self.a%=1 // Set the a% value in TTest to 1
  ENDFUNCTION
ENDTYPE

You may be interested in my Programmers Reference Guide, which details it all : http://www.lulu.com/product/paperback/glbasic-programmers-reference-guide-%28second-edition%29/16044005

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4036
    • View Profile
    • Space Fractal
Re: Hi there - Newb Question :)
« Reply #21 on: 2011-Jun-16 »
alternative you can use CREATESCREEN and draw each box into that, and then draw that screen to the backbuffer.

SCREENS other than backbuffer is never clean up, so its can been alternativt to avoid drawing 1000boxes in one frame.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation and The beagle Jam.

Offline Stevester

  • Mc. Print
  • *
  • Posts: 12
    • View Profile
Re: Hi there - Newb Question :)
« Reply #22 on: 2011-Jun-16 »
Quote
You may be interested in my Programmers Reference Guide, which details it all : http://www.lulu.com/product/paperback/glbasic-programmers-reference-guide-%28second-edition%29/16044005

Had a look at this and will definitely be looking into a copy though there's quite a difference (price-wise) between the hardcopy and the download (about £70) - is this correct? The hardcopy seems really expensive but the download seems too cheap!

Quote
Posted by: spacefractal
« on: Today at 01:45:14 pm »
alternative you can use CREATESCREEN and draw each box into that, and then draw that screen to the backbuffer.
SCREENS other than backbuffer is never clean up, so its can been alternativt to avoid drawing 1000boxes in one frame.

Thats very handy to have a screen (or image) that isn't cleared every cycle. You then copy this to the backscreen and flip it to the visible screen using SHOWSCREEN command.

This is slightly different to what I'm used to but I think I'm starting to get the hang of it!! :)

I'd been thinking that having to pass everything through the SHOWSCREEN command at the end of every cycle was a bit of a limitation but thats not looking to be the case with the alternative options available. I think it promotes a bit more structure to the coding as well.

I was also a bit stumped with the explicit declarations (hadn't realised theres a tick box in options) but I can see the benefit of this facility - especially with my dodgy coding! :) Will be very useful in larger programs when I accidentally misspell one of my variables. (Mind, I've turned it off for now!).

Offline Gary

  • Dr. Type
  • ****
  • Posts: 313
    • View Profile
Re: Hi there - Newb Question :)
« Reply #23 on: 2011-Jun-16 »
GRABSPRITE would again grab the whole screen (like USEASBMP) and any action on it. It would be OK on just the rectangles but if you want to add anything else (moving player etc.) then avoid.
but if you drew the sprite, then the new rectangle, then grab it, then draw the player which could move, then showscreen you would keep the rectangles sprite minus any other moving images added after.