in this case, the screen is 1920x1080, the size of most standard phones. the cloud spawns offscreen, and reveals itself when the player moves up.
the issue is, when i spawn it out of bounds (lets say the X point is 300, and the Y point is -100) the cloud stays stationary and doesn’t come in the camera’s view as the player moves up. how can i achieve this?
to clarify, the cloud is stationary
Calculate the current player Y so now you can create an object like Create PowerUp at RandomX, Player.Y-300 where 300 is a distance from the new object to the player you can change that to fit your needs
Other option is just to create the object knowing the height of your screen. if you set your game for instance to 720x1280 so you know the point 0,0 is the top of your game and the width will be 720 then you create an object at (RandomInRange(0,720)), (-yourobjectHeight)
this will create the object at any random between 0 and 720 in X axis.
And for the Y if your object suppose it’s height is 32px then will be created at Y -32 so when is created is not visible on the screen.
i’m running into an issue with both of the options you listed. for the first option, the player is moving up constantly as high speeds, so player.Y-300() won’t always guarantee that the object will spawn offscreen. i tested this, and sometimes, the objects will spawn on the screen, which isn’t good.
with the second option, the player is moving up constantly (like i said before), so -32px will be far below the player after some point. picture below:
i already have a randominrange for the x position, thankfully. the fact that the negative y coordinate is the same is my problem.
since the character is moving up, y=-45 for example won’t always be above the player. the player can start at y=20, then go up to y=0, then y= -20, then y= -50. at this point, y=-45 is below the player, and not offscreen. i want the spawned item to always be above the player, and offscreen.
thanks for the response. i adjusted the “ScreenHeight()/2” and instead divided by 1.25. worked like a charm–notably, though, if the number was lower then 1.25 (say 1, for example) the cloud wouldn’t spawn at all.