Autor Beitrag
pigfacejoe
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 332
Erhaltene Danke: 1

Win 10, Ubuntu
Delphi,Javascript, PHP, Java, Python
BeitragVerfasst: Mi 01.08.07 18:21 
Hi,
ich habe folgendes Problem:
Ich habe für mein 2D Spiel ne Map (2000x2000 Pixel), die ich in ein Image geladen habe. Meine Spielfigur ist ebenfalls ein Image und das wird eben bewegt. Das Fenster scrollt immer so mit, das die Spielfigur immer sichtbar ist. Nun der Hacken bei der Sache: Ist die Spielfigur einmal am Rand des Formulars angelangt, so ändert sich beim mitscorllen die Left bzw Top der Spielfigur nicht mehr. Immer Top auf 308 und Left auf 530 oder so.
Wie kann ich das umgehen? Und wieso ist das so?

Gruss
PigfaceJoe
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Mi 01.08.07 21:38 
Hallo,

vermutlich weil in Deinem Code das Erreichen des Randes nicht berücksichtigt ist.

Wie sieht Dein Code denn jetzt aus?
Oder versuch mal die Vorgehensweise etwas genauer zu erklären.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
pigfacejoe Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 332
Erhaltene Danke: 1

Win 10, Ubuntu
Delphi,Javascript, PHP, Java, Python
BeitragVerfasst: Mi 01.08.07 23:25 
Also, ich setze einfach in einem Timer immer wieder die scrollbar auf Position von der Spielfigur, hier mal der Komplette Timer Code:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
procedure TForm1.Timer1Timer(Sender: TObject);

begin
actrec.Left:=image2.Left;   //
actrec.top:=image2.Top;     // Hier wird ein Rect um die Spielfigur
actrec.Right:=image2.Width; //  (image2) gezogen , um sie später
actrec.Bottom:=image2.Height;// auf eine Kollision zu prüfen
if not collision then    //Ausschliessen, dass keine Kollision vorhanden ist
 begin
 x:=image2.Left;  //Sichern des zuletzt
 y:=image2.Top;  //  begehbaren Bereichs
 if rechts then  //Wenn Spielfigur nach rechts will
  begin
  if one then
   begin
   image2.Picture.Bitmap:=figur[6] ;one:=false//Hier ist dann die "Animation"
   end
  else
   begin  image2.Picture.Bitmap:=figur[2];one :=true;
   end  ;
  if image2.Left<=image1.Width then    //Wenn Spielfigur im gültigen Bereich
   begin
   image2.Left:=image2.left+10;
   ScrollInView(image2);//Hier wird gescrollt
   end;
  end else
if links then  //Wenn links...
begin
if one then begin image2.Picture.Bitmap:=figur[8] ;one:=false end else begin  image2.Picture.Bitmap:=figur[4];one :=true; end  ;
if image2.Left>=0 then
begin
image2.Left:=image2.left-10;
ScrollInView(image2);
end;
end else if unten then//unten...
begin
if one then begin image2.Picture.Bitmap:=figur[1] ;one:=false end else begin  image2.Picture.Bitmap:=figur[5];one :=true; end  ;
if image2.Top<=image1.Top+image1.Height-image2.Height then
begin
image2.Top:=image2.Top+10;
ScrollInView(image2);
end ;
end else if oben then //oben...
begin
if one then begin image2.Picture.Bitmap:=figur[3] ;one:=false end else begin  image2.Picture.Bitmap:=figur[7];one :=true; end  ;
if image2.Top>=0 then
begin
image2.Top:=image2.Top-10;
ScrollInView(image2);
end ;
end else image2.Picture.Bitmap:=figur[1];  //Tritt ein, wenn Figur ausserhalb vom güötigen Berreich
end else
  begin
  image2.Picture.Bitmap:=figur[1]; image2.Left:=x; image2.Top:=y  ;//zurücksetzen auf zuletzt beweglichen Punkt
  end;

end;


Nun das eigentliche Problem:
Wenn ich mit meiner Spielfigur nun solange nach rechts gehe, dass sie Scrollbar anfängt mit zu scrollen, dann ändert sich weder Left noch Top. Sie bleiben immer auf den gleichen Werten. Eben auch alle Rects sie verhindern sollen, in best. Bereiche auf der Map zu gelangen, bleiben halt eben an gleicher Stelle und bleiben nicht zurück, so wie ich das wollte..


Gruss
Pigface Joe
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 01.08.07 23:37 
Moin!

Ohne jetzt auf dein eigentliches Problem einzugehen, das hier ist definitiv problematisch: :?
user profile iconpigfacejoe hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
image2.Picture.Bitmap:=figur[6] ;one:=false//Hier ist dann die "Animation"					

Damit überschreibst du immer wieder die Objektreferenz, was eine üble Fehlerquelle sein kann!

Deshalb besser mit:
ausblenden Delphi-Quelltext
1:
image2.Picture.Bitmap.Assign(figur[6]);					

arbeiten. :idea:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
pigfacejoe Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 332
Erhaltene Danke: 1

Win 10, Ubuntu
Delphi,Javascript, PHP, Java, Python
BeitragVerfasst: Mi 01.08.07 23:44 
Vielen Dank Narses!
Ich probier mich zum ersten Mal in so einem 2D Spielchen, da kann ich solche Tipps echt gut gebrauchen! :D
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Do 02.08.07 06:31 
Kleiner Tipp am Rande: Ein TImage hat ein BoundsRect. Das gibt genau das an, was du über das ActRec machst.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
Image1.BoundsRect.Left
Image1.BoundsRect.Right
Image1.BoundsRect.Top
Image1.BoundsRect.Bottom


Du kannst dir demnach die Variable ActRec sparen.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Wolle92
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Do 02.08.07 07:41 
ich sehe nicht, woher das links, oben und unten in deinen if-Abfragen kommt?
Mir fehlt da irgendwie eine Variable
ausblenden Delphi-Quelltext
1:
if collision = links then					

zum Beispiel...
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Do 02.08.07 09:28 
Das sind dann wohl Prozeduren ;-)

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
pigfacejoe Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 332
Erhaltene Danke: 1

Win 10, Ubuntu
Delphi,Javascript, PHP, Java, Python
BeitragVerfasst: Do 02.08.07 16:05 
mmmh, kann mir vlt. jemand bei meinem eigentlichen Problem helfen?^^
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 02.08.07 16:16 
Moin!

Was tut denn ScrollInView(), am besten mal den Code dazu tun. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Corpsman
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 228

KUbuntu 10.4
Lazarus
BeitragVerfasst: Do 02.08.07 16:33 
Hi , auch auf dir Gefahr hin das ich nu misverstanden werde.

Dir ist Klar das du dauerhaft dein Spiel umschreiben must auf Direkt X oder noch besser OpenGL ?

denn mit Images bist du sehr Langsam und ein 2000x2000 bild ist auch icht gerade ohne.

Viel besser ist es wenn du da mit Patterns arbeitest, das bedarf natürlich eines etwas gröseren Aufwandes , das ist klar.

ZU deinem Problem

wenn ich das Richtig verstehe hast du Srollbalken die du extra noch anzeigst, das ist irgendwie komisch, ich würde so was mit einer Plobalen Variable ( leftTop:Tpoint) lösen die immer = (0,0) ist auser eben wenn du Scrollen willst dann wird sie in der entsprechenden Dimm Größer

und wenn du dann backgroundImage.draw machst machst du das mit form1.canvas.draw(-LeftTop.x,lefttop.y,backgroundImage);

_________________
--
Just Try it.