I'm currently trying to put a lightsource on my player when nighttime hits, but I can't seem to map player X coordinates proper. Ive set Player Map X and Map Y into a variable, and they almost work. I've tried Screen X and Y too, but similar failures.
The light source will appear either up in the corner with MAP X, and will appear to the bottom right below my character with Screen X (and does not stay on the Player if I get close to the edge of the map.
Any ideas would much appreciated. Thanks!
it would have helped if you showed a picture of how you try to use them, because they're working correctly for everyone else.
I assume the problem is that you have wrong assumptions on what map x and screen x is.
1) map xy are the on-map-coordinates in tiles. If you have a map of 100x50 tiles for example your return would be 1-100 for the x-coordinate and 1-50 for the y-coordinate. And that would be based on map position independend on where on the map your screen display currently is.
2) screen xy are the screen-coordinates in pixels. These will completely ignore the map size or where on the map the current display is, but count the pixels to a position on the current screen and depend on the screen size you set with a plugin (if you did so).
depending on how you create light sources, you might need to recalculate between tile coordinates and pixel coordinates.
By default .x and .y tell which tile you're on (counting from tile 0 at the top/left side of the screen). So when you go from a tile at (0,1) to (0,2), it just changes immediately without intervening values
._realX and ._realY will give the location of the character when moving between tiles (so when you walk from a tile at (0,1) to (0,2), you'll see (0,1.25) at some point
.screenX() and .screenY() point at the middle of the bottom of your character's sprite, and show where it is onscreen
(so for a default 48 x 48 pixel sprite, it's going to point at pixel 24 horizontally, and pixel 48 vertically - but NOTE that all sprites are displaced up by 6 pixels relative to the map)
Based on your description, are you using an event as a light, and teleporting it around to your player's location?
You need to use Control Variables to set the X and Y position based on the player's MAP X and MAP Y and then immediately position your event. The X and Y position variables have to be updated with each frame. You can't just set them once and then expect them to continually update themselves as the player moves.
This is just a guess, based on other people doing this in the past. If this is not what you've done, then we need to see what you've done, in order to see what's wrong with it. Are you only using events, or are you using a plugin? Which one? What order are they in? Show us your event that is moving the light source.
Hey everyone, thanks for the responses, here's a simple shot of how I declared these variables, and how I'm using them to draw my lightsource. When I get more time I will go over in depth what everyone has shared with me and try it out, thanks!
You can set the Variables 5 and 6 to the Player Screen Coordinates X and Y, instead of Map Coordinates X and Y.
Than your code could maybe work.
You are setting the variables to a certain value at that point in the game. You are not linking the variable to some other thing so that it will get updated whenever that other thing changes.
So in a parallel event, you should set the two variables (use ScreenX and ScreenY because that's what Show Picture uses) and then your Show Picture command. In the Show Picture command, assuming the centre of the picture is the centre of the light image, make sure you set the Origin to Centre, and not Upper Left, which is what I see in your screenshot. Depending on the size of the image, using Upper Left will cause the light itself to not be centred on your player.
the loop in that event will break everything - why do you have that? especially with move picture commands? That makes absolutely no sense.
Yes, I think that could certainly cause problems. Loops within parallel process events aren't a good idea.
Can you redesign this event so it can be done over multiple event pages, using event page conditions rather than conditional branches, and only set the ones that actually do something to parallel process?
You also have a combination of things that only need to run once and not repeat, along with things that do need to repeat. It's usually better to have two events for this rather than using loops - one that runs once then erases itself, and another that continues to run while on the map. Might be a bit tricky as depending on your time system, you could be on this map when the time changes, so you might want that "run once" event to trigger again.
I would recomment to make the Mechanic first on a new Map.
When all works fine, than try to implement it to your main Parallel Event or let it run when needed in an
extra parallel Event or common Event.
The Time Branches will most likely mess up the picture movement (Just a Guess, cant tell for sure).
Edit: A Loop in a Parallel Event is absolutly fine if it's done correctly. In an earlier MV Version the loop caused trouble when changing eventpage without breaking the loop earlier, that bug got fixed as far as i know.
Thats why you could use the above code in a parallel common Event. When you turn on your Flashlight, you also turn on the condition switch for the common event. But we would need to adjust the code to be able to turn the Flashlight properly off again.
Please show a Picture of your new Eventpage which shows your Code. There should be no delay. That lets me guess that you made a mistake somewhere, or it indicates that the error is happening because something else messes it up.
You could adjust the Picture position like this:
...
◆Control Variables:#0061 var_pl_screenx = Screen X of Player
◆Control Variables:#0061 var_pl_screenx - 20
◆Control Variables:#0062 var_pl_screeny = Screen Y of Player
◆Control Variables:#0062 var_pl_screeny - 40 just experiment with the numbers.
Another Solution would be to make a Picture the same size as visible Screen size and make light source in the middle.
Than show that Picture on coordinates 0 and 0, and make it "Top left" , than it looks if the light is always on your Player because both are in the middle of the screen, but you need to make sure
that the player never reaches the map boarders, because than this solution would stop working. Thats why the solution with the parallel Event centering a Picture on Player is more flexible in my Opinion.