Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C# / VB.NET - XNA: Disegnare Texture2D in un secondo momento
Forum - C# / VB.NET - XNA: Disegnare Texture2D in un secondo momento

Avatar
fabi3194 (Ex-Member)
Expert


Messaggi: 206
Iscritto: 11/10/2008

Segnala al moderatore
Postato alle 18:25
Giovedė, 02/07/2009
Salve a tutti!
Sto studiando l'xna e stavo facendo un videogame, Snake.
Ora, sono riuscito a scrivere il metodo che crea la mela (CreateApple) e il metodo che crea il serpente con 5 pezzi di corpo attaccati.
Il problema arriva quando controllo se la testa colpisce la mela. Ecco il codice che avevo scritto:
Codice sorgente - presumibilmente VB.NET

  1. Public Sub Impacted()
  2.  
  3.         Dim HeadRect As New Rectangle
  4.         HeadRect = GetBounds(Head)
  5.         Dim AppleRect As New Rectangle
  6.         AppleRect = GetBounds(Apple)
  7.         If HeadRect.Intersects(AppleRect) Then
  8.             CreateApple()
  9.             score += 50
  10.             Dim AddPiece As New GameObject
  11.             AddPiece = New GameObject(GetTexture("body.png"))
  12.             AddPiece.Position = New Vector2(LastPiece.Position.X - 10,  _LastPiece.Position.Y)
  13.             AddPiece.Enabled = True
  14.             Batch.Begin()
  15.             AddPiece.Draw(Batch)
  16.             Batch.End()
  17.             LastPiece = AddPiece
  18.         End If
  19.         For Each obj As GameObject In Body
  20.             Dim ObjRect As Rectangle = GetBounds(obj)
  21.             If ObjRect.Intersects(AppleRect) Then
  22.                 CreateApple()
  23.                 score += 50
  24.                 Dim AddPiece As New GameObject
  25.                 AddPiece = New GameObject(GetTexture("body.png"))
  26.                 AddPiece.Position = New Vector2(LastPiece.Position.X - 10, _LastPiece.Position.Y)
  27.                 AddPiece.Enabled = True
  28.                 Batch.Begin()
  29.                 AddPiece.Draw(Batch)
  30.                 Batch.End()
  31.                 LastPiece = AddPiece
  32.             End If
  33.         Next
  34.     End Sub


Ora, dovrebbe funzionare tutto, tranne una cosa: pultroppo non ho la minima idea di come posso aggiungere il pezzetto ottenuto mangiando la mela in un secondo momento.
Io ho provato con
Codice sorgente - presumibilmente Plain Text

  1. Batch.Begin()
  2.                 AddPiece.Draw(Batch)
  3.                 Batch.End()
  4.                 Me.graphics.ApplyChanges()



PS: Body č una List (of GameObject).
Spero che abbiate capito il mio problema e mi sappiate aiutare. Grazie :hail:

Ultima modifica effettuata da fabi3194 il 02/07/2009 alle 18:27
PM Quote
Avatar
ruggy94 (Member)
Guru


Messaggi: 890
Iscritto: 21/04/2008

Segnala al moderatore
Postato alle 19:13
Giovedė, 02/07/2009
Basta che, al momento dell'impatto con la mela, aggiungi alla list Body un pezzo (nel tuo caso addpiece), poi nel metodo Draw con un For Each disegni tutti i pezzi del serpente contenuti in body, quindi:
Codice sorgente - presumibilmente VB.NET

  1. 'Quando si scontra con la mela
  2. Body.Add(AddPiece)
  3.  
  4. 'Nel metodo Draw
  5. For Each obj As GameObject In Body
  6. obj.Draw(Batch)
  7. Next


;)

PS: Comunque aggiungendolo come hai fatto tu, il pezzo va a posizionarsi sempre a sinistra dell'ultimo, mentre non dovrebbe essere sempre cosė

PM Quote
Avatar
fabi3194 (Ex-Member)
Expert


Messaggi: 206
Iscritto: 11/10/2008

Segnala al moderatore
Postato alle 19:16
Giovedė, 02/07/2009
Testo quotato

Postato originariamente da ruggy94:
PS: Comunque aggiungendolo come hai fatto tu, il pezzo va a posizionarsi sempre a sinistra dell'ultimo, mentre non dovrebbe essere sempre cosė


Ah č vero :d

PM Quote