Comments (17)
The images only ever go as high as they have atleast 1 pixel in them. As you can see from below the pink cells show the bottom of each image (where its physically placed).
So all you need to do is get the height of the image, divide is by the constant cell height - that'll give you the cells tall an image is.
then as you loop down your Y coord - you check if the player coord is greater than the Y coord minus the image height. If it is, you know the player is over it.
player Y = 100
checking Y coord = 105
105's image height = 5
if (100 > 105 - 5) Player is behind image.
image height will always be minimum of 1. So in most cases for a single cell image
if (100 > 101 - 1) player not behind
(you'll need to do this on front and middle layers)
Should be as simple as that. Obviously you're not going to be able to know if just a foot is behind the image, but you're still massively reducing when you have to double draw the player.
from zircon.
I feel like this should be handled as part of PlayerObject Draw() method.
Imo maybe I should just reimplement that whole Draw method while i'm touching it :|
from zircon.
Yes double drawing has always been a requirement to see yourself behind objects.
I don't think you lose the colour when you hover if that's what you meant. Just a side effect of the draw blend / opacity making the image brighter and losing colour I think.
I'm not sure how you'd plan to get around needing to double draw. The simplest fix would be to just double draw the wings too - I can't think of any other way you can resolve it in a single draw.
from zircon.
It seems like a waste to process twice, i was hoping to be able to determine whether the character is hidden whilst processing in the PlayerObject.Draw but because the map object spans over multiple cells whilst only actually being assigned to one cell that the player isn't likely on makes it not possible like you said :/
from zircon.
To be honest you probably can work it out. You'd have to look at the current X coord, and all Y coordinates directly below the player (plus maybe +/- 1 X due to overflowing image to out cells). Then you'd need to look at all 3 layer images to see if the cell height reaches the player.
It'll certainly be an expensive calculation to constantly do, so you'd need to ensure its cached - which might use abit of memory after a certain period.
from zircon.
Thinking about it, you're really only going to need to calculate 3 cells below you - each time you move. So maybe not that expensive and worth looking in to. Certainly would be better than drawing opacity over the player constantly
from zircon.
I thought some map objects were quite tall, let me see if I can investigate that as a separate thing.
from zircon.
They are, but there's only 3 cells below you. Any objects lower than that won't get drawn, even if they're more than 3 cells tall. I think.
from zircon.
Here is the same example. This particular object is 1x13 size.
from zircon.
Do you think it's still possible to be able to calculate a top image that is up to maybe 10 cells away from your character?
Sorry for the horrible pink lines, i don't know where i found this program but it does the job for viewing the map😅
from zircon.
The more I think about it, the more I think it's not possible, how would you also handle a character half under shelter and half not? The double draw handles this, but would you end up with the draw fully oqaue not opaque at all if you had this situation with manually worked out solution?
from zircon.
You'd have to just double draw as soon as the feet/player cell is in the area. But it still means 99% of the time you're not double drawing.
Maybe write the function to search for 10 coords below you and see how the performance is. Since you only need to do it once every time you move, it'll probably be fine
from zircon.
I may be thinking about this too simply, but using the cell positions I don't think is enough to work.
Maybe you have something in mind that i don't, when you say:
Then you'd need to look at all 3 layer images to see if the cell height reaches the player.
How would I know if the map object image overflow lands on top of the player fully or not? The only way I can see this being achieved is if you check whether the images intersect, not by cells but by pixel maybe?
from zircon.
I've given this a quick go, and although it does kind of work - it certainly not perfect.
public bool IsBehindObject()
{
if (User == null) return false;
var location = User.CurrentLocation;
IsBehind = false;
for (int offset = 0; offset < 20; offset++)
{
var y = location.Y + offset;
var cell = Cells[location.X, y];
if (cell == null) continue;
LibraryFile file;
MirLibrary library;
if (Libraries.KROrder.TryGetValue(cell.MiddleFile, out file) && file != LibraryFile.Tilesc && CEnvir.LibraryList.TryGetValue(file, out library))
{
int index = cell.MiddleImage - 1;
Size s = library.GetSize(index);
var cellsTall = s.Height / CellHeight;
if (location.Y > (location.Y + offset - cellsTall))
{
IsBehind = true;
break;
}
}
if (Libraries.KROrder.TryGetValue(cell.FrontFile, out file) && file != LibraryFile.Tilesc && CEnvir.LibraryList.TryGetValue(file, out library))
{
int index = cell.FrontImage - 1;
Size s = library.GetSize(index);
var cellsTall = s.Height / CellHeight;
if (location.Y > (location.Y + offset - cellsTall))
{
IsBehind = true;
break;
}
}
}
System.Diagnostics.Debug.WriteLine(IsBehind ? "true" : "false");
return IsBehind;
}
Then add an "IsBehind" variable to map control
call this line inside LocationChanged()
GameScene.Game.MapControl.IsBehindObject();
and finally wrap drawPlayer around the check
if (IsBehind)
{
MapObject.User.DrawPlayer(false);
}
It would probably be much better just doing this check when the map gets drawn itself - and it doesn't always look to work, often i find myself double drawing when i'm not behind anything.
Ideally checking if there is a visible pixel on the image would be much better - but i can only think performance on that would be an issue.
from zircon.
I didn't have much time to look myself but i was thinking more along this train of thought, but it didn't work.. maybe i missed something simple.
from zircon.
Ah it does kind of work if I change this code a bit.
if (!playerOverlap)
{
if (s.Width == 0 || s.Height == 0) continue;
Rectangle MidImage = new Rectangle(drawX, drawY, s.Width, s.Height);
bool result = !Rectangle.Intersect(MidImage, playerRectangle).IsEmpty;
playerOverlap = result;
}
It still has issues though.
- Flickering when transitioning between cells
- Not drawing if the head is showing, weirdly it works if the head is hidden and bottom half of body is showing.
Maybe easier to see without the huge armour wings.
from zircon.
That sounds like a much better approach
i think you'll need to cache it though so it only rechecks once per player move.
Also, the player dimensions are alot more than just body - if you look in DrawBody theres an l/t/r/b value which gets used to create the shadows - maybe you can store this as a rectangle to reuse it for intersecting?
from zircon.
Related Issues (20)
- DrawBlend on player always breaks after 10 secondsof being logged in
- spells not locking on HOT 1
- accessory upgrade HOT 3
- Sin blooms does normal damage HOT 1
- DanceOfSwallow crashes all client connections when in visible range HOT 1
- Parasite Explosion Crashes Server if used on a player HOT 3
- Can Not Kick Guild Members From Guild
- Companion window cannot fit all item types in view
- cant choose a quest reaward in the Choice section
- Quest QoL Updates
- Menue Button dont work (click+N hotkey) HOT 2
- Confirmation for Sorting Button
- Wizard Skill Burning dont level
- Plz do update on gm commands and fix HOT 2
- Item link from equip Crash server
- PoisonDust technique issues
- Guild bonus removed while in grp with member of another guild HOT 2
- Some skill elements attack color settings without effect HOT 1
- linking items to chat in character menu HOT 2
- companion issue HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zircon.