Author Topic: Sprite wird nicht vollständig gelöscht  (Read 3377 times)

Offline Shogun

  • Mr. Drawsprite
  • **
  • Posts: 67
    • View Profile
Hallo alle zusammen, habe folgendes Problem, bei folgendem Code.

Code: (glbasic) [Select]
TYPE SHOT
x
y
ENDTYPE

TYPE ENEMY
x
y
ENDTYPE

GLOBAL shots[] AS SHOT

GLOBAL enemys[] AS ENEMY

WHILE TRUE

IF b1

LOCAL railgun AS SHOT

railgun.x = playerx+20
railgun.y = playery

delay=GETTIMERALL()+500
DIMPUSH shots[], railgun
ENDIF

LOCAL soldier1 AS ENEMY

soldier1.x = 100
soldier1.y = 100

DIMPUSH enemys[], soldier1

FOREACH enemy IN enemys[]

FOREACH shot IN shots[]

IF SPRCOLL(4, shot.x, shot.y, 5, enemy.x, enemy.y)

didhit=TRUE

DELETE shot

ENDIF

NEXT

IF didhit

DELETE enemy

ENDIF

DRAWSPRITE 5, enemy.x, enemy.y

NEXT
FOREACH shot IN shots[]

DEC shot.y, 1

DRAWSPRITE 4, shot.x, shot.y

NEXT
Folgendes Problem, alles funktioniert soweit, nur sobald ich das enemysprite treffe wird das sprite gelöscht, aber der enemy scheint noch da zu sein, denn der schuss bleibt beim sprite hängen. Ich finde den Fehler nicht, würde mich freuen wenn jemand hilft.
« Last Edit: 2010-Jan-14 by BumbleBee »

Offline Shogun

  • Mr. Drawsprite
  • **
  • Posts: 67
    • View Profile
Hat jemand einen Fehler gefunden?

Offline Quentin

  • Prof. Inline
  • *****
  • Posts: 915
    • View Profile
zumindest dein DELETE Enemy macht nur innerhalb der FOR-NEXT-Schleife sind, nicht außerhalb. Probier das mal.

Offline Shogun

  • Mr. Drawsprite
  • **
  • Posts: 67
    • View Profile
Meines erachtens gehört es in die foreach shot. Wie gesagt das sprite verschwindet ja wenn ich es treffe, nur bleiben die schüsse danach an der sprite Position hängen. Ich habe beim shoot em up video von Gernot geschaut, habe es eigentlich genauso gemacht.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10859
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Du musst "didhit" am Anfang wieder auf FALSE setzen.

.... äh.. Du machst in jeder Schleife:
DIMPUSH enemys[], soldier1

also hast Du da ewig viele Enemies.
Mach mal:
PRINT LEN(enemys[]), 0,0
SHOWSCREEN

« Last Edit: 2010-Jan-16 by Kitty Hello »

Offline Shogun

  • Mr. Drawsprite
  • **
  • Posts: 67
    • View Profile
Ach man, hab das didhit=false an jeder Stelle gesetzt, funktioniert aber nicht. Mit Len hast du recht. Da muss irgendwo noch ein Fehler sein. Ich finde ihn nicht.

Offline Shogun

  • Mr. Drawsprite
  • **
  • Posts: 67
    • View Profile
Endlich, einfach nur nicht in die while-Schleife setzten. Danke Gernot.

Mit an welcher Stelle was gehört, habe ich hier und da immer noch Probleme. Muss daran arbeiten.