D
DomiShop
Guest
Hello everyone,
I am posting in the hopes that some kind soul out there can assist with a problem that has me thoroughly stumped. I'm having some issues with a bit of code I've intended to use for a weather system.
I'm tinkering with a basic top-down project where the character can move 8 directions on a 2D plane. The camera scrolls around the room to follow the player. I want to have a rain/snow/etc. system where the rain or snow sprites follow the camera instead of just spawning the rain objects in the entire room, since the rooms can get pretty large and it would become really inefficient. I made two very basic scripts to check the View's current X positions on both the leftmost part of the screen and the rightmost part of the screen, since I need to check these values all the time anyway:
Script "GetViewX":
Script "GetViewWidthX":
These scripts seem to work fine. As a debugging tool, I have both of these scripts print to the screen as int values, and they always show that no matter where the camera goes, the difference between "GetViewX" and "GetViewWidthX" is always 640. When the camera is as far left as it can go, the debug printing shows "GetViewX" is 0, and "GetViewWidthX" is 640. When shifted one pixel to the right, "GetViewX" instantly changes to 1, and "GetViewWidthX" changes to 641.
The trouble comes when I try to spawn a set number of raindrops between the values of GetViewX and GetViewWidthX, by using "random_range". Before I spawn the rain objects, I store the rain's x position in what is supposed to be a random variable:
When running the game and printing rain_x's value to the screen, rain_x is always between -2 and -1 for every instance of the rain object spawned, and therefore, it doesn't even show up on the screen. I've tried all kinds of variants on the code, but nothing seems to work. I have used random_range elsewhere with success, so I know I must be doing something incorrectly here. It's probably blindingly obvious, but I just don't know what the problem is.
The debug print shows with all the above code, when the character is standing as far left as possible "GetViewX" is 0, "GetViewWidthX" is 640, but rain_x is always some random value between -1 and -2. How is this possible?
Thank you all in advance for your assistance, and thank you for taking the time to read through what is probably a really obvious problem.
I am posting in the hopes that some kind soul out there can assist with a problem that has me thoroughly stumped. I'm having some issues with a bit of code I've intended to use for a weather system.
I'm tinkering with a basic top-down project where the character can move 8 directions on a 2D plane. The camera scrolls around the room to follow the player. I want to have a rain/snow/etc. system where the rain or snow sprites follow the camera instead of just spawning the rain objects in the entire room, since the rooms can get pretty large and it would become really inefficient. I made two very basic scripts to check the View's current X positions on both the leftmost part of the screen and the rightmost part of the screen, since I need to check these values all the time anyway:
Script "GetViewX":
Code:
return camera_get_view_x(camera_get_active());
Code:
return camera_get_view_width(camera_get_active()) + GetViewX();
The trouble comes when I try to spawn a set number of raindrops between the values of GetViewX and GetViewWidthX, by using "random_range". Before I spawn the rain objects, I store the rain's x position in what is supposed to be a random variable:
Code:
rain_x = random_range(GetViewX(), GetViewWidthX());
The debug print shows with all the above code, when the character is standing as far left as possible "GetViewX" is 0, "GetViewWidthX" is 640, but rain_x is always some random value between -1 and -2. How is this possible?
Thank you all in advance for your assistance, and thank you for taking the time to read through what is probably a really obvious problem.