UnderwareDesign
September 08, 2010, 05:22:00 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Meals Of The Dragon by Laskiapina (19,June,2010)
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: 500 balloons demo , as in PB 500 bubble demo  (Read 207 times)
micky4fun
Sr. Member
****
Offline Offline

Posts: 422


« on: March 27, 2010, 04:14:41 PM »

hi all

just quickly making a birthday welcome for my niece for putting on her computer in the start up , as she turns it on for her 18th birthday ,
i started with a few balloons darting around a happy birthday background , i will be adding to this with pics of her over the years and some differant wipes with the balloons
but this post is just a quick re-write of the 500 bubble demo in PB , think this maybe a little easier to follow for newbies , and it was the 500 bubble demo that got me into PB in the first
place

enjoy , change the how_many to as many as your pc can handle , im on 1500 no probs
mick Grin

* 500 balloons.rar (568.55 KB - downloaded 20 times.)

* balloons.jpg (247.71 KB, 1024x768 - viewed 38 times.)
Logged
kevin
Development Team
Administrator
Hero Member
*****
Offline Offline

Posts: 9416



WWW
« Reply #1 on: March 27, 2010, 04:43:46 PM »

  Here's a slightly tweaked version of the code that rotates the sprites, or does it ? Smiley  

Code:

   screenvsync on

LoadfxImage "balloon1.bmp",1
LoadfxImage "balloon2.bmp",2
   LoadfxImage "balloon3.bmp",3
   LoadImage "back.jpg",8


CacheImageSize=256+128
CreateIMage 11,CacheImageSize,CacheImageSize
CreateIMage 12,CacheImageSize,CacheImageSize
CreateIMage 13,CacheImageSize,CacheImageSize

          
how_many = 50

Type Bubble
x#,y#,XSpeed#,Yspeed#
EndType
Dim balloons(how_many) As Bubble

   ;  set up how_many balloons , there start x,y position and there xspeed and yspeed
For amount=1 To how_many
balloons(amount).x# = Rnd(1000)
balloons(amount).y# = Rnd(700)
balloons(amount).xspeed# = RndRange#(1,4)
balloons(amount).yspeed# = RndRange#(1,4)
CreateSprite amount
SpriteImage amount,10+rndrange(1,3)
centerspritehandle amount
   Next amount


// create an extra sprite we'll use to pre-render the balloon images rotating
Spr=NewSprite( CacheImageSize/2, CacheImageSize/2,11)
spritedrawmode spr,2
spritefilter spr,true

   ; main loop , draw background then the amount of balloons set by how_many
Do

        drawimage 8,0,0,0

// draw rotated versions to 3 balloon images,to 3 different images
spritevisible spr,true
rendertoimage 11
cls 0
spriteimage spr,1
centerspritehandle spr
drawsprite spr

rendertoimage 12
cls 0
spriteimage spr,2
centerspritehandle spr
drawsprite spr

// draw the
rendertoimage 13
cls 0
spriteimage spr,3
centerspritehandle spr
drawsprite spr


turnsprite Spr,1

spritevisible spr,false
rendertoscreen

For amount=1 To how_many
balloons(amount).x#=balloons(amount).x#+balloons(amount).xspeed#
balloons(amount).y#=balloons(amount).y#+balloons(amount).Yspeed#
If balloons(amount).x#<-200 Or balloons(amount).x#>1200 then balloons(amount).xspeed#=balloons(amount).xspeed#*-1
If balloons(amount).y#<-200 Or balloons(amount).y#>1000  Then balloons(amount).yspeed#=balloons(amount).yspeed#*-1
PositionSprite amount,balloons(amount).x#,balloons(amount).y#
Next amount

 DrawAllSprites
 Sync

Loop




* Micks_HappyBirthday_Rotating_Sprites.jpg (88.04 KB, 1024x768 - viewed 26 times.)
« Last Edit: March 27, 2010, 04:53:49 PM by kevin » Logged

micky4fun
Sr. Member
****
Offline Offline

Posts: 422


« Reply #2 on: March 27, 2010, 05:35:07 PM »

hi kevin ,

so your rotating the image of the sprite and not the sprite itself , i did do the sprites rotating at one stage but with 500 it was ok on this fast pc , but on another it was quite slow
but i had control so all the sprites and they could have differant rotating speeds each , but would your way be faster? ,
 

mick Smiley
« Last Edit: March 27, 2010, 05:45:00 PM by micky4fun » Logged
kevin
Development Team
Administrator
Hero Member
*****
Offline Offline

Posts: 9416



WWW
« Reply #3 on: March 28, 2010, 02:40:10 PM »


   There's a great old saying, there's more than one way to skin a cat  - This is very true In programming, as 99.99999% of the time,  the most obvious solution, just happens to also  be the slowest solution !     

   Above, all the code does is rotate/render the 3 seperate textures to some cache images.  So these cache hold the rotated state of the image this frame.   It does this, because drawing none rotated images is faster than drawing a rotated image, in particular with filtering    So rather than drawing them all dynamically,  we use a slight of hand trick to cull the work load down dramatically.     So rather than rotating 50 sprites, we're rotating 3 of them.    This type of illusion is very common in games..   
 
   See Blog -> Think Better Design

Logged

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.10 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!