Comment afficher un sprite dans un OpenWindowedScreen?

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
bernard13
Messages : 1221
Inscription : mer. 05/janv./2005 21:30

Comment afficher un sprite dans un OpenWindowedScreen?

Message par bernard13 »

bonjour
je sais afficher un sprite en plein ecran avec la commande OpenScreen
mais j'arrive a recrée le meme programme avec la commande OpenWindowedScreen
qui peux m'expliquer et m'aider svp

merci


Code : Tout sélectionner


;test  de sprite sous fenetre window 


 #curseur=0
 
;initialisation de DirectX
 
 If InitSprite()=0 Or InitKeyboard()=0 Or InitMouse()=0
 MessageRequester("ERREUR","Impossible d'initialiser DirectX",0)
 End
 
 ElseIf OpenWindowedScreen(WindowID(),0,0,800,600,0,0,0)=0
   MessageRequester("Erreur","impossible d'ouvrir l'ecran",0)
   End
   EndIf

 
 

  
 
   
   Repeat 
   ClearScreen(0,0,0)
   ExamineKeyboard()
   ExamineMouse()
   FlipBuffers()
   Until KeyboardPushed(#PB_Key_Escape)
   




 
 
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

Message par Backup »

un exemple vaut mieux qu'un long discourt ! :D

Code : Tout sélectionner

  LoadFont(1, "arial", 50 ,#PB_Font_Italic )
LoadFont(2, "arial", 50 )
UseFont(1)
Resultat = InitSprite()
Global angle,amplitude
amplitude=2
Texte.s="Le Lac d'annecy !"





WindowID = OpenWindow(1, 50, 50, 640, 200,  #PB_Window_SystemMenu|#PB_Window_MinimizeGadget  , "hello")

OpenWindowedScreen(WindowID, 0, 0, 640, 200, 1, 0, 0)



CreateImage(100, 640, 100)
StartDrawing( ImageOutput())
FrontColor($0,$FF,$FF)
BackColor(0, 0, 0)

UseFont(1)
DrawingFont(FontID())
DrawingMode(1)
Locate(0, 0)
DrawText(Texte.s)
StopDrawing()

For t=0 To 100
    GrabImage(100, t, 0, t, 640,1) 
Next t
   
Repeat
    
    For y= 0 To 100
        StartDrawing( ScreenOutput())
        UseFont(2)
        DrawingFont(FontID())
        DrawingMode(1)
        
        FrontColor($95,$25,$BA)
        BackColor(0, 0, 0)
        Locate(40, 0)
        DrawText(Texte.s)
        
        angle+1 :If angle=360*10: angle=0 :EndIf
        x+(Sin(angle*2*3.1415926/50)* amplitude)
        DrawImage( UseImage(y), x+y, y+50,640,1)
        StopDrawing()           
    Next y
    
    
    FlipBuffers(50)
    
    ClearScreen(0, 0, 0)
    Event=WindowEvent()
    Delay(1)
    
    
Until Event=#PB_Event_CloseWindow
Dr. Dri
Messages : 2527
Inscription : ven. 23/janv./2004 18:10

Message par Dr. Dri »

euh dobro, il parle de sprites pas d'images
sinon les sprites s'utilisent de la même manière quelque soit la nature de l'écran ;)

Dri
bernard13
Messages : 1221
Inscription : mer. 05/janv./2005 21:30

Message par bernard13 »

pas grave
merci je demandez pas temps que ça
juste un little exemple apres je me debrouille

merci a vous 2
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

Message par Backup »

ben c'est pareille sauf que t'utilise des sprites ! :D

ps : on quitte avec ESC

Code : Tout sélectionner

#Window = 0
#Width = 300
#Height = 300

Enumeration
    #brique
    #balle
EndEnumeration

Global xbrique,ybrique,xpas,ypas,xb,yb,flag
dep = 1


Procedure Sprites()
    ; Procedure de création des sprites
    If CreateSprite(#brique,128,24,0)           ; Sprite Fixe
        StartDrawing(SpriteOutput(#brique))
        Box(0,0,128,24,RGB($FF,$0,$0))
        StopDrawing()
    EndIf
    
    If CreateSprite(#balle,20,20,0)           ; Sprite Mobile
        StartDrawing(SpriteOutput(#balle))
        Circle(10,10,10,RGB($0,$0,$FF))
        StopDrawing()
    EndIf
EndProcedure


;- Initialisation de DirectX
If InitSprite() = 0 Or InitKeyboard() = 0
    End
EndIf

;- Ouverture de la fenêtre et de l'écran
hwnd = OpenWindow(#Window, 0, 0, #Width, #Height, #PB_Window_TitleBar | #PB_Window_ScreenCentered, "")
OpenWindowedScreen(hwnd, 0, 0, #Width, #Height, 0, 0, 0)

Sprites()

;- Initialisation des sprites
xbrique = 86 : ybrique = 138
xb= 0 : yb= 0
xpas = 5 : ypas = 5

;- Boucle des évènements
Repeat
    ClearScreen(0, 0, 0) : ExamineKeyboard()
    
    ; Affichage des sprites
    DisplayTransparentSprite(#brique, xbrique, ybrique)
    DisplayTransparentSprite(#balle, xb, yb)
    
    
    
    FlipBuffers()
    
    xb=xb + xpas
    yb=yb + ypas
    
    
    
    If SpritePixelCollision(#balle, xb, yb, #brique, xbrique-5, ybrique)<>0 And flag=0
        flag=1
        SetWindowTitle(#Window,"Collision à gauche")
        xpas=-xpas
        Goto su ; sort du test !!!
    EndIf
    If SpritePixelCollision(#balle, xb, yb, #brique, xbrique+5, ybrique)<>0 And flag=0
        flag=1
        SetWindowTitle(#Window,"Collision à droite")
        xpas=-xpas
        Goto su ; sort du test !!!
    EndIf 
    If SpritePixelCollision(#balle, xb, yb, #brique, xbrique, ybrique-5)<>0  And flag=0
        flag=1
        SetWindowTitle(#Window,"Collision au dessus")
        ypas=-ypas
        Goto su ; sort du test !!! 
    EndIf
    If SpritePixelCollision(#balle, xb, yb, #brique, xbrique, ybrique+5)<>0  And flag=0
        flag=1
        SetWindowTitle(#Window,"Collision au dessous")
        ypas=-ypas
        Goto su ; sort du test !!!         
    EndIf
    
    su:
    If flag=1
        attente+1
    EndIf
    If attente>4
        attente=0
        flag=0
    EndIf
    
    
    ;Delay(2)
    If KeyboardPushed(#PB_Key_Escape) : quit = 1    : EndIf
    
    If KeyboardPushed(#PB_Key_Left)   : xbrique - dep : EndIf
    If KeyboardPushed(#PB_Key_Right)  : xbrique + dep : EndIf
    If KeyboardPushed(#PB_Key_Up)     : ybrique - dep : EndIf
    If KeyboardPushed(#PB_Key_Down)   : ybrique + dep : EndIf
    
    If xb <=0   : xpas= -xpas  : EndIf
    If yb <=0   : ypas= -ypas  : EndIf
    If xb >=280 : xpas= -xpas  : EndIf
    If yb >=280 : ypas= -ypas  : EndIf
    
    While WindowEvent() : Wend
Until quit = 1 
bernard13
Messages : 1221
Inscription : mer. 05/janv./2005 21:30

Message par bernard13 »

j'ai compris il faut mettre openwindow en premier et OpenWindowedScreen en deuxieme
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

Message par Backup »

ben voui ! :D
Avatar de l’utilisateur
Chris
Messages : 3731
Inscription : sam. 24/janv./2004 14:54
Contact :

Message par Chris »

:cry:
Répondre