How do I determine all objects in the viewport?

  • I had asked a question about how to detect an object in the viewport (https://www.construct.net/en/forum/construct-3/how-do-i-8/detect-sprite-viewport-148001). I have a similar question about how to detect all objects currently in the viewport.

    I have a scrolling background with eight windows visible at any given time:

    I learned from my first question that the "Is on-screen" condition will determine if an object is on the screen. What I would like is, every two seconds, determine which windows are on the viewport. Currently, each window is a separate instance and has "Name" property, though if it's easier, I could just copy so it is the same instance with a different UID value.

    The purpose of wanting to see which windows are in the viewport is to randomly have an image appear in one of the eight windows that is visible. Since the "Is on-screen" is condition, not an event, I'm not sure how to do this without having to hack something together by checking every window. What is a better way to do this?

    Tagged:

  • "Is on screen" condition picks instances. You can use it inside any triggered event (for example, Every X seconds, On button pressed etc.)

    And after "Is on screen" you can pick instances further to narrow down the picked scope. If you need a random instance you can do this:

    Every 5 seconds
     WindowSprite is on-screen
    	System pick random instance of WindowSprite
    	.......WindowSprite spawn object
    
  • That was helpful, thank you. I think I am on the right track, but the images I want to spawn are not appearing on the image point on each Window. I have highlighted what I think are the relevant spots:

    So on the image in my first post, those windows are now all "Window6" instances. They are all on Layer 1. I have also tried Layer 0. The result I would like is for the "Guy" sprite to appear on the image point (there is only one) in the center of a randomly selected "Window6" instance. (I have done nothing to the image point - they all have a name of "Origin" and "Number" of 0.) However, nothing is happening.

    What is the piece that I am missing?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • You are doing "Guy spawn Guy". What you need is "Window6 spawn Guy".

    Also, a word of advice - use layer names instead of layer numbers. This way if you need to insert another layer at the bottom in the future, you'll not have to update layer numbers in many events.

  • Thank you so much! That was it - when I had the "Window6" object spawn the "Guy", it worked. And I will take your advice on the layers as well.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)