Sayfayı Yazdır | Pencereyi Kapat

Aynı konumda olan pngleri hareket ettirmek sorun

Nereden Yazdırıldığı: Clomosy | Forum
Kategori: Genel Programlama
Forum Adı: Genel İşlemler
Forum Tanımlaması: TRObject dili ile programlama yaparken karşılaşılan genel işlemler
URL: https://forum.clomosy.com.tr/forum_posts.asp?TID=898
Tarih: 06 Ocak 2025 Saat 17:31
Program Versiyonu: Web Wiz Forums 12.07 - https://www.webwizforums.com


Konu: Aynı konumda olan pngleri hareket ettirmek sorun
Mesajı Yazan: steelwing
Konu: Aynı konumda olan pngleri hareket ettirmek sorun
Mesaj Tarihi: 21 Ağustos 2024 Saat 09:36
Aynı konumda olan pngleri sürekli hareket ettirmek istediğimde sorun yaşıyorum. Pnglerden sadece biri hareket ediyor diğeri ise görünmüyor. 

var
  MyForm: TclGameForm;
  myGameEngine: TclGameEngine;
  GameTimer: TClTimer;
  BtnStartGame: TclButton;
  geribtn: TclProButton;
  ImgBack: TclProImage;
  ImgField, ImgField1, ImgRoad, ImgRoad1, ImgLambo, ImgFerrari: TclProImage;
  tPosX, tPosY, tPosY1, tPosY2: Single;
  LamboSpeed: Integer;
  DeviceMotionSensor: TClMotionSensor;

function isLamboCrashed: Boolean;
begin
  Result := False;

  if (ImgLambo.Position.X + ImgLambo.Width > ImgField.Position.X) and
     (ImgLambo.Position.X < ImgField.Position.X + ImgField.Width) and
     (ImgLambo.Position.Y + ImgLambo.Height > ImgField.Position.Y) and
     (ImgLambo.Position.Y < ImgField.Position.Y + ImgField.Height) then
  begin
    Result := True;
    Exit;
  end;

  if (ImgLambo.Position.X + ImgLambo.Width > ImgField1.Position.X) and
     (ImgLambo.Position.X < ImgField1.Position.X + ImgField1.Width) and
     (ImgLambo.Position.Y + ImgLambo.Height > ImgField1.Position.Y) and
     (ImgLambo.Position.Y < ImgField1.Position.Y + ImgField1.Height) then
  begin
    Result := True;
    Exit;
  end;
end;

procedure geriprcdr;
begin
  TclProButton(MyForm.clFindComponent('BtnGoBack')).Click;
end;

procedure ProcOnGameTimer;
begin
  ImgRoad.Visible := True;
  ImgRoad1.Visible := True;
  ImgFerrari.Visible := True;
  
  tPosY := tPosY + 15; // ImgRoad hızı
  tPosY1 := tPosY1 + 15; // ImgRoad1 hızı
  tPosY2 := tPosY2 + 4;
  
  // ImgRoad pozisyonunu sıfırla
  if tPosY >= TForm(MyForm).ClientHeight then
    tPosY := -ImgRoad.Height;

  // ImgRoad1 pozisyonunu sıfırla
  if tPosY1 >= TForm(MyForm).ClientHeight then
    tPosY1 := -ImgRoad1.Height;

  if tPosY2 >= TForm(MyForm).ClientHeight then
    tPosY2 := -ImgFerrari.Height;
    
  ImgRoad.Position.X := tPosX;
  ImgRoad.Position.Y := tPosY;

  ImgRoad1.Position.X := tPosX;
  ImgRoad1.Position.Y := tPosY1;

  ImgFerrari.Position.X := tPosX;
  ImgFerrari.Position.Y := tPosY2;

  // Jiroskop ile ImgLambo hareketi
  if Clomosy.PlatformIsMobile then
  begin
    case DeviceMotionSensor.GetDirectionX of
      1: ImgLambo.Position.X := ImgLambo.Position.X - LamboSpeed; // Sola hareket et
      2: ImgLambo.Position.X := ImgLambo.Position.X + LamboSpeed; // Sağa hareket et
    end;
  end;

  // Çarpışma kontrolü
  if isLamboCrashed then
  begin
    GameTimer.Enabled := False;
    if Clomosy.PlatformIsMobile then
      DeviceMotionSensor.Active := False; // Oyun durduruldu
    ShowMessage('Tekrar deneyin.'); // Mesaj gösteriliyor
    BtnStartGame.Text := 'START GAME';
  end;
end;

procedure BtnStartGameClick;
begin
  GameTimer.Enabled := not GameTimer.Enabled;

  if GameTimer.Enabled then
    BtnStartGame.Text := 'STOP GAME'
  else
    BtnStartGame.Text := 'START GAME';

  if Clomosy.PlatformIsMobile then
    DeviceMotionSensor.Active := GameTimer.Enabled;
end;

begin
  MyForm := TclGameForm.Create(Self);
  ImgField := MyForm.AddNewProImage(MyForm, 'ImgField');
  ImgField.clSetImage(' https://i.imgur.com/8jxbJAj.png" rel="nofollow - https://i.imgur.com/8jxbJAj.png ');
  ImgField.Width := 50;
  ImgField.Height := 50;
  ImgField.Align := alNone;
  ImgField.Position.X := 340;
  ImgField.Position.Y := 440;

  ImgField1 := MyForm.AddNewProImage(MyForm, 'ImgField1');
  ImgField1.clSetImage(' https://i.imgur.com/lAt43Ml.png" rel="nofollow - https://i.imgur.com/lAt43Ml.png ');
  ImgField1.Width := 50;
  ImgField1.Height := 50;
  ImgField1.Align := alNone;
  ImgField1.Position.X := -10;
  ImgField1.Position.Y := 440;

  ImgRoad := MyForm.AddNewProImage(MyForm, 'ImgRoad');
  ImgRoad.clSetImage(' https://i.hizliresim.com/l6z8qre.png" rel="nofollow - https://i.hizliresim.com/l6z8qre.png ');
  ImgRoad.Properties.AutoSize := False;
  ImgRoad.Width := ImgRoad.Width * 8;
  ImgRoad.Height := ImgRoad.Height * 32;
  ImgRoad.Visible := False;
  ImgRoad.Align := alNone;

  ImgRoad1 := MyForm.AddNewProImage(MyForm, 'ImgRoad1');
  ImgRoad1.clSetImage(' https://i.hizliresim.com/l6z8qre.png" rel="nofollow - https://i.hizliresim.com/l6z8qre.png ');
  ImgRoad1.Properties.AutoSize := False;
  ImgRoad1.Width := ImgRoad1.Width * 8;
  ImgRoad1.Height := ImgRoad1.Height * 32;
  ImgRoad1.Visible := False;
  ImgRoad1.Align := alNone;

  ImgLambo := MyForm.AddNewProImage(MyForm, 'ImgLambo');
  ImgLambo.clSetImage(' https://i.imgur.com/y6jIvYx.png" rel="nofollow - https://i.imgur.com/y6jIvYx.png ');
  ImgLambo.Width := 150;
  ImgLambo.Height := 50;
  ImgLambo.Align := alNone;
  ImgLambo.Position.X := 150;
  ImgLambo.Position.Y := 450;

  ImgFerrari := MyForm.AddNewProImage(MyForm, 'ImgFerrari');
  ImgFerrari.clSetImage(' https://i.imgur.com/Bdxodrg.png" rel="nofollow - https://i.imgur.com/Bdxodrg.png ');
  ImgFerrari.Width := 100;
  ImgFerrari.Height := 50;
  ImgFerrari.Align := alNone;
  ImgFerrari.Position.X := 80;
  ImgFerrari.Position.Y := 200;

  tPosX := (TForm(MyForm).ClientWidth - ImgRoad.Width) / 2;
  tPosY := 0;
  tPosY1 := -ImgRoad.Height;
  
  tPosX := (TForm(MyForm).ClientWidth - ImgFerrari.Width) / 2;
  tPosY := 0;
  tPosY2 := -ImgFerrari.Height;
  
  LamboSpeed := 2; // ImgLambo hızı

  // Hareket sensörünü etkinleştir
  DeviceMotionSensor := MyForm.AddNewSensorsMotion(MyForm, 'DeviceMotionSensor');
  DeviceMotionSensor.Active := True;

  BtnStartGame := MyForm.AddNewButton(MyForm, 'BtnStartGame', 'START GAME');
  BtnStartGame.Align := alBottom;
  BtnStartGame.Height := 30;
  BtnStartGame.StyledSettings := ssFamily;
  BtnStartGame.TextSettings.FontColor := clAlphaColor.clHexToColor('#FFFFFF');
  BtnStartGame.Margins.Bottom := 50;
  MyForm.AddNewEvent(BtnStartGame, tbeOnClick, 'BtnStartGameClick');

  geribtn := MyForm.AddNewProButton(MyForm, 'geribtn', '');
  clComponent.SetupComponent(geribtn, '{"Align" : "None","Width":70,"Height":50,"ImgUrl":" https://i.imgur.com/XUYO0A6.png" rel="nofollow - https://i.imgur.com/XUYO0A6.png" }');
  MyForm.AddNewEvent(geribtn, tbeOnClick, 'geriprcdr');
  geribtn.Position.X := 5;
  geribtn.Position.Y := 7;

  GameTimer := MyForm.AddNewTimer(MyForm, 'GameTimer', 20);
  GameTimer.Interval := 1;
  GameTimer.Enabled := True;
  MyForm.AddNewEvent(GameTimer, tbeOnTimer, 'ProcOnGameTimer');

  if Clomosy.PlatformIsMobile then 
    MyForm.Run;
end;




Cevaplar:
Mesajı Yazan: Developer
Mesaj Tarihi: 21 Ağustos 2024 Saat 14:12
Merhaba Steelwing ,
Hatan hala devam ediyor mu?


Mesajı Yazan: steelwing
Mesaj Tarihi: 21 Ağustos 2024 Saat 16:27
Hayır, sorunum çözüldü. Teşekkürler.



Sayfayı Yazdır | Pencereyi Kapat

Forum Software by Web Wiz Forums® version 12.07 - https://www.webwizforums.com
Copyright ©2001-2024 Web Wiz Ltd. - https://www.webwiz.net