Mixing 2d Sprites and 3D

Advanced game related topics
adshead
User
User
Posts: 14
Joined: Thu Jan 03, 2008 3:06 pm

Mixing 2d Sprites and 3D

Post by adshead »

I notice in the latest beta this apparently is now possible?. I am working on a 2D platform game using 2D sprites and would like to make use of the particle functionality already built into Purebasic 3d Engine alongside my 2d Sprites.

Is this possible?
User avatar
Comtois
Addict
Addict
Posts: 1431
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Post by Comtois »

yes, it is possible

i changed few lines in the particle.pb example

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - Particle
;
;    (c) 2003 - Fantaisie Software
;
; ------------------------------------------------------------
;

#CameraSpeed = 10

IncludeFile "Screen3DRequester.pb"

Define.f KeyX, KeyY, MouseX, MouseY

If InitEngine3D()

  Add3DArchive("Data", #PB_3DArchive_FileSystem)
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  If Screen3DRequester()
    
    CreateSprite(0,64,64)
    StartDrawing(SpriteOutput(0))
      ;Box(0,0,64,64,#Blue)
      Circle(32,32,30,#Red)
    StopDrawing()
    
    
    LoadTexture(0, "flare.png")
    
    CreateMaterial(0, TextureID(0))
      DisableMaterialLighting(0, 1)
      MaterialBlendingMode   (0, #PB_Material_Add)

    CreateParticleEmitter(0, 10, 1, 1, 0)
      ParticleMaterial    (0, MaterialID(0))
      ParticleTimeToLive  (0, 2, 2)
      ParticleEmissionRate(0, 20)
      ParticleSize        (0, 30, 30)
      ParticleColorRange  (0, RGB(255,0,0), RGB(255,0,255))

    CreateCamera(0, 0, 0, 100, 100)
      CameraBackColor(0,-1)
      CameraLocate(0,0,0,100)
          
    Repeat
      Screen3DEvents()
      
      ClearScreen(RGB(0, 0, 0))
            
      If ExamineKeyboard()
        
        If KeyboardPushed(#PB_Key_Left)
          KeyX = -#CameraSpeed 
        ElseIf KeyboardPushed(#PB_Key_Right)
          KeyX = #CameraSpeed 
        Else
          KeyX = 0
        EndIf
                  
        If KeyboardPushed(#PB_Key_Up)
          KeyY = -#CameraSpeed 
        ElseIf KeyboardPushed(#PB_Key_Down)
          KeyY = #CameraSpeed 
        Else
          KeyY = 0
        EndIf

      EndIf
      
      If ExamineMouse()
        InputEvent3D(MouseX(), MouseY(), MouseButton(1), "")
        PointPick(0,MouseX()+32,MouseY()+32)
        MouseX = -(MouseDeltaX()/10)*#CameraSpeed/2
        MouseY = -(MouseDeltaY()/10)*#CameraSpeed/2
      EndIf
      
      ;RotateCamera(0, MouseY, MouseX, RollZ, #PB_Relative)
      ;MoveCamera  (0, KeyX, 0, KeyY)
      ParticleEmitterLocate(0,CameraX(0)+PickX()*100,CameraY(0)+PickY()*100,CameraZ(0)+PickZ()*100)
      
      RenderWorld()
      Screen3DStats()
      DisplayTransparentSprite(0,MouseX(),MouseY()) 
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  EndIf
    
Else
  MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf
  
End
Please correct my english
http://purebasic.developpez.com/
User avatar
IceSoft
Addict
Addict
Posts: 1682
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Post by IceSoft »

Works not here.
Belive! C++ version of Puzzle of Mystralia
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
Fred
Administrator
Administrator
Posts: 18150
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

You need to use DX9 subsystem.
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Post by djes »

This example does not work here.
With directx9 subsystem, in windowed, the 3d seems to be behind a black screen, where's some random transparent pixels (and sometime a big part of the screen) are permitting to see the flares. By removing CameraBackColor(0,-1) it's ok.

In fullscreen, the program is hanging on createsprite(0, 64, 64) (invalid memory access) and we can't come back to the desktop :/
With directx7, the program is hanging on StartDrawing(SpriteOutput(0)) (specified sprite is not initialised), even with changing parameters of createsprite().
Last edited by djes on Tue Oct 07, 2008 12:57 pm, edited 1 time in total.
User avatar
Comtois
Addict
Addict
Posts: 1431
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Post by Comtois »

Well, i use subsystem directx9, and windowed mode (800x600).

I can see a sprite (red circle) and particle behind the sprite.

does original particle.pb example work, using directx9 for you ?
Last edited by Comtois on Tue Oct 07, 2008 12:59 pm, edited 1 time in total.
Please correct my english
http://purebasic.developpez.com/
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Post by djes »

Comtois wrote:Well, i use subsystem directx9, and windowed mode (800x600).
I can see a sprite (red circle) and particle behind the sprite.

does original particle.pb example work, using directx9 for you ?
Yes, and even in fullscreen.
Fred
Administrator
Administrator
Posts: 18150
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

djes wrote:With directx7, the program is hanging on StartDrawing(SpriteOutput(0)) (specified sprite is not initialised), even with changing parameters of createsprite().
DX7 isn't supported with 3d-2d mixing.
User avatar
Comtois
Addict
Addict
Posts: 1431
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Post by Comtois »

i get this, and particle follow the sprite.

Image
Please correct my english
http://purebasic.developpez.com/
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Post by djes »

Here's mine Image
You see the little dots and the fx behind.
Fred
Administrator
Administrator
Posts: 18150
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

CameraBackgroundColor() with -1 parameter isn't useful anymore as you can't put anything behind the 3d scene. It's now removed.
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Post by djes »

Fred wrote:CameraBackgroundColor() with -1 parameter isn't useful anymore as you can't put anything behind the 3d scene. It's now removed.
Ok! Anyway, it still doesn't work in fullscreen, even without CameraBackgroundColor()
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Works beautifully here in windowed mode but causes an IMA at CreateSprite(0,64,64) in fullscreen. PB 4.3(x86) and DX9, latest beta Sprite lib from purebasic.com/beta/
BERESHEIT
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

Is it any slower to draw using 2D commands on the 3D screen than it would be to use actual 3D sprites?
THCM
Enthusiast
Enthusiast
Posts: 276
Joined: Fri Apr 25, 2003 5:06 pm
Location: Gummersbach - Germany
Contact:

Post by THCM »

Seems to work here. I'll get about 2100 fps.
The Human Code Machine / Masters' Design Group
Post Reply