Thema: Delphi Sprite andockbar

Einzelnen Beitrag anzeigen

Benutzerbild von XXcD
XXcD

Registriert seit: 19. Sep 2006
581 Beiträge
 
Delphi 2007 Professional
 
#1

Sprite andockbar

  Alt 9. Aug 2008, 01:48
Hallo,
ich möchte gerne zwei Sprite miteinander andockbar machen.
Das ganze soll ein Map Editor werden.

Bei meinem jetzigen Quellcode springen die Sprites zu einer ganz falschen Stellen wenn mehrere Sprites drum herum sind.

Hier mal der Quellcode:
Delphi-Quellcode:
procedure TForm2.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
  p:TAdPoint;
  spritet, spritet2, spriteb, spriteb2, spritel, spritel2, spriter, spriter2: TSprite;
begin
  if ssLeft in Shift then
  begin
 if (Selected.Item<>nil) and (Selected.Item is TTexture) then
begin
       spritet := nil;
       spritet2 := nil;
       spriteb := nil;
       spriteb2 := nil;
       spritel := nil;
       spritel2 := nil;
       spriter := nil;
       spriter2 := nil;
      p := AdSpriteEngine.ScreenPointToSpriteCoords(AdPoint(X,Y));
       spritet := AdSpriteEngine.GetSpriteAt(round(Selected.Item.WorldX) + 1, round(Selected.Item.WorldY) -10);
      spritet2 := AdSpriteEngine.GetSpriteAt(round(Selected.Item.WorldX) + round(Selected.Item.width) - 1, round(Selected.Item.WorldY-10));
       spriteb := AdSpriteEngine.GetSpriteAt(round(Selected.Item.WorldX) + 1, round(Selected.Item.WorldY) + round(Selected.Item.height)+10);
      spriteb2 := AdSpriteEngine.GetSpriteAt(round(Selected.Item.WorldX) + round(Selected.Item.width) - 1, round(Selected.Item.WorldY+round(Selected.Item.height)+10));
       spritel := AdSpriteEngine.GetSpriteAt(round(Selected.Item.WorldX) - 10,round(Selected.Item.WorldY) + 1);
      spritel2 := AdSpriteEngine.GetSpriteAt(round(Selected.Item.WorldX) - 10,round(Selected.Item.WorldY) + round(Selected.Item.height) - 1);
       spriter := AdSpriteEngine.GetSpriteAt(round(Selected.Item.WorldX) + round(Selected.Item.width) +10, round(Selected.Item.WorldY) + 1);
      spriter2 := AdSpriteEngine.GetSpriteAt(round(Selected.Item.WorldX) + round(Selected.Item.width) +10, round(Selected.Item.WorldY)+round(Selected.Item.height) - 1);

      if (spritet is TTexture) or (spritet2 is TTexture) or (spriteb is TTexture) or (spriteb2 is TTexture) or (spritel is TTexture) or (spritel2 is TTexture) or (spriter is TTexture) or (spriter2 is TTexture) then
       begin
       if ((spritet<>nil) and (spritet is TTexture)) or ((spritet2<>nil) and (spritet2 is TTexture)) then
       begin
         if (spritet<>nil) and (spritet is TTexture) then
          begin
           Selected.Item.X:=spritet.X;
           Selected.Item.Y:=spritet.Y+128;
          end
         else
          begin
           Selected.Item.X:=spritet.X;
           Selected.Item.Y:=spritet.Y+128;
          end;
       Label12.Caption:='top';
       end;

       if ((spriteb<>nil) and (spriteb is TTexture)) or ((spriteb2<>nil) and (spriteb2 is TTexture)) then
       begin
        if (spriteb<>nil) and (spriteb is TTexture) then
          begin
           Selected.Item.X:=spriteb.X;
           Selected.Item.Y:=spriteb.Y-128;
          end
         else
          begin
           Selected.Item.X:=spriteb.X;
           Selected.Item.Y:=spriteb.Y-128;
          end;
       Label12.Caption:='bottom';
       end;

       if ((spritel<>nil) and (spritel is TTexture)) or ((spritel2<>nil) and (spritel2 is TTexture)) then
       begin
         if (spritel<>nil) and (spritel is TTexture) then
          begin
           Selected.Item.X:=spritel.X+128;
           Selected.Item.Y:=spritel.Y;
          end
         else
          begin
           Selected.Item.X:=spritel.X+128;
           Selected.Item.Y:=spritel.Y;
          end;
       Label12.Caption:='left';
       end;

       if ((spriter<>nil) and (spriter is TTexture)) or ((spriter2<>nil) and (spriter2 is TTexture)) then
       begin
         if (spriter<>nil) and (spriter is TTexture) then
          begin
           Selected.Item.X:=spriter.X-128;
           Selected.Item.Y:=spriter.Y;
          end
         else
          begin
           Selected.Item.X:=spriter.X-128;
           Selected.Item.Y:=spriter.Y;
          end;
       Label12.Caption:='right';
       end;
       end
       else
       begin
       Selected.Item.X := p.x - Selected.dx;
       Selected.Item.Y := p.y - Selected.dy;
       end;
end
else
begin
//Code zum bewegen der Welt(unwichtig)
end;
  end;
end;
Und im Anhang noch die Anwendung mit dem Fehler.
Angehängte Dateien
Dateityp: rar map_editor_116.rar (2,24 MB, 17x aufgerufen)
  Mit Zitat antworten Zitat