Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7553779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:09:15+00:00 2026-05-30T11:09:15+00:00

I place objects on random positions on the screen (canvas) : public float X=Rnd.nextInt((MainGamePanel.width

  • 0

I place objects on random positions on the screen (canvas) :

 public float X=Rnd.nextInt((MainGamePanel.width - 60) - 20) + 20;
 public float Y=Rnd.nextInt((MainGamePanel.height - 30) - 30) + 30;

This works fine. Now; What if I want to avoid placing objects over (40,50) – (60,80).. for instance, because I have a button there, I don’t want the button to be covered with visible objects.

Ofcourse, I could implement a “checkposition” routine, that re-randomizes if the object-position is placed somewhere within the button-area. But is this the best (cleanest, neatest, fastest) solution? Thanks for your thoughts!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T11:09:16+00:00Added an answer on May 30, 2026 at 11:09 am

    Fixed amount of time to create the objects

    Create the objects in four areas, not one.

    Have more than one set (x,y) of randomized numbers and split the percentage of created objects in each according to the size of each area. If you can picture four rectangles that snugly fit together outside of the button area then you have your areas. Depending on how many objects you are creating and the effect you are looking for this could work.

    This could be a terrible idea though if you sometimes, randomly, want lots of objects in one part of the screen, as you are forcing the distribution. Also what if you want another button somewhere else on the screen, not adjacent to the current one? Might get a bit messy with lots of areas.

    The advantage with this solution is that it takes a predictable amount of time to create all the objects. It should be the same every time.

    Variable amount of time to create the objects

    Use a checkPostion() method.

    It’s probably just easier to use a checkPostion() method and grab a new random number. If you are smart about it, you should realise that in a lot of cases you’ll only need to ‘re-roll’ one coordinate and not both.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in django 1.1.1, Place.objects.in_bulk() does not work and Place.objects.in_bulk(range(1, 100)) works and returns a
We need to place text over objects in a web page, similar to this:
What is everyone's recommendations on where to place database objects (tables, procs, views etc.)
I'm trying to make an array of objects in random, non repeating order. Using
Ok, this is a weird one. The junk data isn't random either, it appears
I'm working on some 2D games with Pygame. I need to place several objects
I have an application in C#/Winforms that lets users place objects on a grid
I am curious if R has the ability to place objects into vectors/lists/arrays/etc. I
I have two threads, a producer thread that places objects into a generic List
Im using the following code to place an object inside a container: testParent =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.