Autor Beitrag
christian_m
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26



BeitragVerfasst: Di 17.04.07 13:26 
Ich möchte ein 2D-Spielfeld mit arrays erstellen und dann an verschiedene Positionen shapes(später evt. images)erzeugen. Wie kann ich einem array ein shape anhängen und dieses dann in der Unit anzeigen lassen???


Spielfeld :array[0..13, 0 .. 13] of TForm;
//besteht das Feld dann aus x/y Koordinaten?
Shapes:array[1..10] of TForm;
// die shapes im array

-> anzeigen lassen
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Di 17.04.07 13:38 
user profile iconchristian_m hat folgendes geschrieben:

Spielfeld :array[0..13, 0 .. 13] of TForm;
//besteht das Feld dann aus x/y Koordinaten?
Shapes:array[1..10] of TForm;
// die shapes im array

Warum denn "of TForm" und nicht "of TShape" ?
Übersetz es dir doch mal: Kette[1 bis 10] von TForm - aber du willst doch Shapes in deinem Array haben oder nicht? ;)
christian_m Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26



BeitragVerfasst: Di 17.04.07 14:14 
ok ich hab jetzt
Spielfeld: array [1..10] : of TShape; ,
also 10 Felder in einem Array gespeichert.

Wie kann ich jetzt den Shapes "vorgelegte"/feste Positionen geben
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Di 17.04.07 14:32 
Instanz erzeugen -> Position festlegen mit Left / Top -> Fertig
Kleines Beispiel (hier werden 10 Shapes nebeneinander gereit):
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure shape;
var
 ashape: array [1..10of TShape;
 i: integer;
begin
 for i := 1 to 10 do
 begin
   ashape[i] := TShape.Create(nil);
   ashape[i].Parent := form1;
   ashape[i].Left := i*(ashape[i].Width + 1);
 end;
end;

Parent gibt die Komponente an, auf denen die Shapes später liegen - in diesem Falle auf der Form selbst.
christian_m Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26



BeitragVerfasst: Di 17.04.07 16:11 
Hi @ all!



[quote="user profile iconMarc."](hier werden 10 Shapes nebeneinander gereit):
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure shape;
...
   ashape[i].Left := i*(ashape[i].Width + 1);
 end;
end;


was ist mit
<ashape[i].Left := i*(ashape[i].Width + 1);>

gemeint?
christian_m Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26



BeitragVerfasst: Di 17.04.07 16:13 
muss ich vorher noch shapes als Objekte einfügen, damit position gespeichert werden kann?
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Di 17.04.07 16:24 
user profile iconchristian_m hat folgendes geschrieben:

was ist mit
<ashape[i].Left := i*(ashape[i].Width + 1);>

gemeint?

Das war nur ein Beispiel. Du kannst natürlich jeden anderen Integer-Wert einsetzen. ;)
Left gibt an, wie weit das Objekt von der linken Seite (der Name verräts eigentlich schon) entfernt liegt und Top gibt die Höhe auf der Form an.
Achtung: Top <> Height & Left <> Width ;)

Was meinst du mit "als Objekte einfügen"?
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Di 17.04.07 16:43 
user profile iconchristian_m hat folgendes geschrieben:
muss ich vorher noch shapes als Objekte einfügen, damit position gespeichert werden kann?

Ich schätze, Suche in: Delphi-Forum, Delphi-Library ...KOMPONENTEN DYNAMISCH IM ARRAY VERWALTEN? hilft dir weiter.

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
christian_m Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26



BeitragVerfasst: Di 17.04.07 16:49 
"als Objekte einfügen":

-> das Shape als grafisches Objekt aus der Bibliothek in das Formular einfügen

kann ich z.B. ein Shape an eine selbstgewählte Position platzieren(soll dort bleiben) und diese Position dann in einem Array speichern//MUSS ICH DAS ÜBERHAUPT MACHEN ODER KANN ICH AUCH DIE POSITION EINES SHAPES MIT shape1.position abrufen
z.B. figur1.top:= shape1.top;

...

...damit ich später wieder auf die Koordinaten zugreifen kann, um ein zweites Objekt(z.B. ein Image/ eine Figur) an diese Stelle zu platzieren;


mfg christian_m


Zuletzt bearbeitet von christian_m am Di 17.04.07 17:11, insgesamt 1-mal bearbeitet
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Di 17.04.07 16:53 
user profile iconchristian_m hat folgendes geschrieben:
"kann ich z.B. ein Shape an eine selbstgewählte Position platzieren(soll dort bleiben) und diese Position dann in einem Array speichern ...
was hindert dich daran...? :roll: Ich meine, wo hast du dabei Probleme? (Aber eigentlich ... Neue Frage => Neuer Thread ... :/ )

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
christian_m Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26



BeitragVerfasst: Di 17.04.07 17:12 
k danke für die antworten mach dann einen neuen thread auf


mfg christian_m
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Di 17.04.07 20:28 
user profile iconchristian_m hat folgendes geschrieben:
MUSS ICH DAS ÜBERHAUPT MACHEN ODER KANN ICH AUCH DIE POSITION EINES SHAPES MIT shape1.position abrufen
z.B. figur1.top:= shape1.top;

Nun, da du deine Shapes (wenn du meinem Link gefolgt bist) in einem Array verwaltest, kannst du so auf die Position zugreifen: Image1.Left := myShapeArray[1].Left;
Wenn's das nicht löst, mach einen neuen Thread und poste den Code den du schon hast^^

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.