(Solved)Detect whether an objects top and bottom graphic is entirely in screen.

Started by FanOfHumor, Wed 05/01/2022 16:48:43

Previous topic - Next topic

FanOfHumor

I have an object that flies by the screen and I need to detect whether the top and bottom of its graphics are entirely on screen.
Code: ags

  if(IsKeyPressed(eKeySpace))
  {
    flash.SetView(3);
    flash.Animate(0, 5, eOnce, eBlock);
    if(eagle.Y<420||eagle.Y>540)
    {
      eagle.StopMoving();
      Display("You Lost!You couldn't get that flawlessly timed snapshot!");
    }  
    else
    {
      eagle.StopMoving();
      Display("You win this level");
    }  
  }  

Does anyone have an idea from this script or does figuring this out require seeing the game.If so here it is.https://www.mediafire.com/file/sjgxzfnjomszbwu/Get+The+Picture.7z/file

Matti

Doesn't your Y-coordinate check work?

In case you have different eagles with different sizes in the game, you can use Game.SpriteHeight[eagle.Graphic] to calculate the correct coordinate check.

Snarky

Yeah, since it seems like you'll be asking a few questions, a handy guide to how to get the most out of Technical Forums help:

1. Explain what you are trying to achieve. (You've done this, though some details must be inferred from your code.)
2. Explain what you have tried. (You've done this too. Great!)
3. Explain, as precisely as possible, what happens when you do this. (You have NOT done this.)
4. Explain what you expected to happen. (You haven't done this either.)

In this case I would suggest to start by testing different conditions in the "if". For example, it can be good to start by just putting "if(true)" (or false, depending) to check that the program logic gets to this point at all. Then you can experiment with different comparison values to see if your calculations are correct, and so on.

FanOfHumor

Sorry for not posting more descriptively.

Anyways I found a simple solution.I just remembered that I don't need any of that script. I could simply use a region and a character instead.It's sure annoying when I forget obvious simple things and go and make unnecessary scripts.(roll)
Thanks Anyways.

SMF spam blocked by CleanTalk