Page 1 of 1

How to Shrink/Grow a sprite?

Posted: Thu Mar 11, 2004 10:07 pm
by Shannara
How can I shrink/grow a 2d sprite? I know there is an example for a 3D sprite, however, use of Start3D, and End3D and Sprite3D commands only work for windows (according to the docs).

Plus another setback is that you cannot mix 2d and 3d commands together as PB requires you to do a FlipBuffer in between the Start3D and End3D, making it impossible to use both :(

Posted: Fri Mar 12, 2004 12:39 pm
by LarsG
You can always code your own zoom function though..
it might not be very fast, but if speed isn't a big issue...

Posted: Fri Mar 12, 2004 1:19 pm
by Kale
Plus another setback is that you cannot mix 2d and 3d commands together as PB requires you to do a FlipBuffer in between the Start3D and End3D, making it impossible to use both
eh? I have coded a little app that uses both. The main loop look likes this:

Code: Select all

...
Start3D()
Repeat
    FlipBuffers()
    ClearScreen(255, 255, 255)
    DisplaySprite(#MAIN_IMAGE, 0, 0)
    calculateAlpha()
    For x = 0 To #NUMBER_OF_FLAKES-1
        DisplaySprite3D(x, flakes(x)\xPos, flakes(x)\yPos, flakes(x)\alpha)
    Next x
    xMoveFlakes()
    yMoveFlakes()
    sleep_(1)
    Select WindowEvent()              
        Case #PB_EventCloseWindow
            quit = 1
        Case #WM_CLOSE
            quit = 1
    EndSelect
    EscapeKey = GetAsyncKeyState_(#VK_ESCAPE)
Until EscapeKey = -32767 Or quit = 1
Stop3D()
...

Posted: Fri Mar 12, 2004 1:29 pm
by scurrier
Kale wrote:
Plus another setback is that you cannot mix 2d and 3d commands together as PB requires you to do a FlipBuffer in between the Start3D and End3D, making it impossible to use both
eh? I have coded a little app that uses both. The main loop look likes this:

Code: Select all

...
Start3D()
Repeat
    FlipBuffers()
    ClearScreen(255, 255, 255)
    DisplaySprite(#MAIN_IMAGE, 0, 0)
    calculateAlpha()
    For x = 0 To #NUMBER_OF_FLAKES-1
        DisplaySprite3D(x, flakes(x)\xPos, flakes(x)\yPos, flakes(x)\alpha)
    Next x
    xMoveFlakes()
    yMoveFlakes()
    sleep_(1)
    Select WindowEvent()              
        Case #PB_EventCloseWindow
            quit = 1
        Case #WM_CLOSE
            quit = 1
    EndSelect
    EscapeKey = GetAsyncKeyState_(#VK_ESCAPE)
Until EscapeKey = -32767 Or quit = 1
Stop3D()
...

your wrong there you can mix 2D and 3D sprite here is some of my code in the 3Dsnow example

;----- Main Loop ----
Repeat
FlipBuffers()
ExamineKeyboard()
ExamineMouse()

mx = MouseX()
my = MouseY()

If mx < lastmx
mousegoingleft = 1
Else
If mx > lastmx
mousegoingleft = 0
Else
; mouse didn't move =)
mousegoingleft = 2
EndIf
EndIf
lastmx = mx
lastmy = my

; show the desktop
DisplaySprite(DeskTopSprite, 0, 0) ****** 2D sprite here

If Start3D()
; show the mouse cursor
If mousegoingleft
DisplaySprite3D(MouseCursor3DL, MouseX()-64, MouseY()-80)
Else
DisplaySprite3D(MouseCursor3DR, MouseX()-44, MouseY()-80)
EndIf

; show the fish
Gosub UpdateFish

; show the website logo
; If waitlogo < 5
; waitlogo = waitlogo + 0.0025
; Else
; waitlogo = waitlogo + 0.2
; EndIf

waitlogo = waitlogo + 0.8
If waitlogo < 200
;waitlogo = waitlogo + 0.25
logoposx = (Width/2)-128
logoposy = (Height/2)-128
Else
If waitlogo > 255
waitlogo = 255
EndIf


; logo hits mouse
If mx > (logoposx+128)-100
If mx < (logoposx+128)+100
If my > (logoposy+128)-50
If my < (logoposy+128)+50
logoxvel = logoxvel + (Random(100)-50)/50.0
logoyvel = logoyvel - (Random(50))/50.0
logozvel = logozvel + (Random(100)-50)/50.0
EndIf
EndIf
EndIf
EndIf

If Random(1000) > 800
logoxvel = logoxvel + (Random(100)-50)/150.0
logoyvel = logoyvel +(Random(100)-50)/150.0
logozvel = logozvel +(Random(100)-50)/150.0
EndIf

; logo darts to side
If logoposy > Height - 40
If Random(1000) > 920
logoxvel = logoxvel + (Random(100)-50)
EndIf
Else
If Random(1000) > 995
logoxvel = logoxvel + (Random(100)-50)
EndIf
EndIf

logoposx = logoposx + logoxvel
logoposy = logoposy + logoyvel
logoposz = logoposz + logozvel


If logoposx > Width-256
logoposx = Width - 256
logoxvel = 0
Else
If logoposx < 0
logoposx = 0
logoxvel = 0
EndIf
EndIf
If logoposy > Height-156
logoposy = Height-156
logoyvel = 0
Else
If logoposy < -250
logoposy = -250
logoyvel = 0
EndIf
EndIf
If logoposz > 120
logoposz = 120
logozvel = 0
Else
If logoposz < -20
logoposz = -20
logozvel = 0
EndIf
EndIf

EndIf
******** 3D sprite here
DisplaySprite3D(vrman3D,logoposx, logoposy, waitlogo)
ZoomSprite3D(vrman3D, 256-logoposz, 256-logoposz)

Stop3D()
EndIf
;---Check Inputs
Event = WindowEvent()
If KeyboardPushed(#PB_Key_Escape)
;#PB_Key_All)
result = CloseSaver(MainHWnd)
EndIf
If KeyboardPushed(#PB_Key_Subtract)
screencapture()
EndIf
; see if mouse moved out of mouse range

; todo - make option in dialog for ignore mouse
; If (mx > origmx + MouseRange) Or (mx < origmx - MouseRange) Or (my > origmy + MouseRange) Or (my > origmy + MouseRange)
; result = CloseSaver(MainHWnd)
; EndIf

ForEver


Sean

Posted: Sat Mar 13, 2004 12:35 am
by Shannara
Scrurrier & Kale: Thanks for the info. According to the code provided, im guessing that the 3D must be done after the 2D and not the other way around due to the flipbuffering.

LarsG: It turns out I have to do it myself since Fred has no plans for Sprite3D support for Linux. (well probably not, he said :) But possible). I'll have to write a linux library to make up for that loss once PB supports native library creation (4.x, I believe, :D). Anyways, speed isnt much of an issue as all sprites should be loaded on startup. The only slowdown I see is when skins are switched at runtime, but that's only on switch :)

Thanks guys.

Posted: Sat Mar 13, 2004 1:55 am
by Paul
@ Shannara

What in the world are you going on about with the flipbuffering??

You use the FlipBuffer() command only once and that is when you are finished all the drawing you need to do.

The order you draw things depends on how you want your sprites layered. You can draw 2D, then 3D or 3D then 2D or mix all you want 2D, 3D, 2D, 3D, etc. Once you have drawn everything in the order you want, then FlipBuffer() to display it on the screen.


Maybe you are confusing OGRE 3D with 2D and 3D Sprites??

Posted: Sat Mar 13, 2004 9:31 am
by Shannara
As mentioned in the PB docs.....
Note: Inside a Start3D() : Stop3D() block there should be no commands of the standard Sprite library (e.g. like DisplaySprite()), only commands of the Sprite3D library. The code inside the block should also be finished with a FlipBuffers().
Siince you only flipbuffer once, and since the docs specifically state you must flip buffer in the 3D blocks, that means the 3D block must be called last... (???)?

Posted: Sat Mar 13, 2004 2:44 pm
by scurrier
I guess you can't believe everything you read :lol:
download my http://www.3dcurrman.com/3DSnow.zip this mixes 2D and 3D sprites. This should show off some of the power of PureBasic.
it's a screensaver with 20,000 snowflakes with a working snowblower and moving logo. just press escape to exit mouse to move snowblower and mouse button to move snow



Sean

Posted: Sat Mar 13, 2004 4:45 pm
by Paul
since the docs specifically state you must flip buffer in the 3D blocks, that means the 3D block must be called last... (???)?
I think you are misunderstanding, possibly from the French/English language conversion ;)

It means when you have finished all your drawing of 3D sprites you use FlipBuffer() to display the results. If you have other 3D or 2D sprites, you can draw them as well... remembering that all 3D Sprites MUST be drawn in a Start3D()/Stop3D() group, and the same goes for 2D sprites which must be drawn outside the 3D group. (or 2D drawing commands must be in a STartDrawing()/StopDrawing() group)

You can have any number of these groups and in any order. The only rule you must respect is keeping 3D Sprites within a 3D group and 2D sprites within a 2D group.

When you have completed all your drawing, then you call FlipBuffer() once. Then do the entire process over again.

Make sense yet?

:)

Like scurrier said, look at other examples to see proper methods of using these commands and you will learn fast.

Posted: Sat Mar 13, 2004 6:56 pm
by Shannara
Ok, I am starting to see how the instructions are very incorrect in several instances. Bleh.. oki dok, thanks... heh, still cant use Sprite3D (due to being limited to windows) but this is good to know ;)

Posted: Sun Mar 14, 2004 5:06 pm
by Andre
@Paul: I will check the docs, to find a better/more clearly description. Maybe its not only a false language conversion.... :wink: