I'll use "tooltip" to refer to the box with extra information, and "parent" to refer to the window/scene containing the reference that the tooltip is explaining.
This can be split into parts:
- Define the tooltip object, e.g. a custom sprite or game window.
- Unless you really want it to use the windowskin, I suggest defining the tooltip as a new
Sprite subclass rather than a game window. This is because game windows all render in one layer by default, making them poorly-suited to layered elements like this.
- If the tooltip may need to display outside the bounds of the parent, it should generally be a child of the scene or something, not that game window.
- Alternatively, it's all HTML so I'm pretty sure you could use a DOM element if you want. You'd just need to make sure the element displays on top of the canvas.
- Determine when/where to show the tooltip (triggers).
- If the parent inherits from
Window_Selectable, you could hook into its select method and update the tooltip through there. Selectable windows also have an itemRect method that can be referenced for positioning.
- Otherwise, consider hooking into the parent's
update method to check the current screen touch coordinates (TouchInput.x, TouchInput.y) vs the parent's contents each frame, then update the tooltip as needed.
Actually updating the tooltip should be fairly simple: change its position and refresh its contents.
😮💨
Thanks, well I would prefer to use the window skin
😛
For clarity, the tooltip should appear when putting the mouse over the red-circled state.
The reason I can't use DOM elements the way I did with my other game is that each of the icons are a <div>(I think it was div at least), and then I am just using the default onmouseover and onmouoseout functions that are native to the DOM element. But since in RPG maker it's drawn on the canvas I can't access that, since it doesn't exist
😛
**********************************************************************************
I think I will do it something like below, unless I get some objections:
Create a new Window_Tooltip class.
It will appear when hovering any object defined with a showTooltip() function.
The showTooltip function will be added to Scene.prototype.showTooltip(). This way it can always be called from any scene.
If the active Scene uses Window_Tooltip and is
active. Then the TouchInput.isMoved() will trigger and parse the x and y coordinates to BISH.checkMouse(). This will check if the x and y coordinates exist in the array function BISH.tooltip["x, y"].
The x and y coordinates will be compared in BISH.checkMouse(), it will be compared to any value that contains a tooltip area.
The Window_Tooltip will fade in over 0.5(or so) seconds. This will be achieved by modifying the .show() function. The .hide() function will be changed accordingly.
I will try and get the corresponding coordinates from the TouchInput.isMoved() function.
JavaScript:
TouchInput.isMoved = function() {
if (BISH.windowTooltipActive) { //This bool value is set to true upon creating the Window_Tooltip. It is set to false when closing the parent Scene.
BISH.actScene.checkMousePos(TouchInput._mouseOverX, TouchInput._mouseOverY); //Parses the mouse position.
}
return this._moved;
};
BISH.tooltip = [];
BISH.checkMousePos(x, y) {
if (BISH.isTooltip[coord(x,y))) actScene.showTooltip(x, y); //coord(x, y) returns a string: "x, y".
}
};
As it is constantly updating, this might cause some lag issues or some other issues. So far I've not noticed anything, when logging the x and y values. But it remains to be seen whilst it is actively used.
**********************************************************************************
Remember that the above is essentially just a mock up. All the code I've written for this is actually in the code spoiler. This is primarily due to this being more of a side project than a primary project
😛 I am aware that the code is very clunky and that it is doing some redundant stuff. But try to see what concept I am after rather than the exact code
🙂 I am also quite sure I can easily avoid using my own class BISH, that's something I tend to strive for.
@caethyril I am unsure if something you wrote could be utilized for the above. I did use the touchinput, but there might be more things that could be used. Like perhaps the itemRect you mentioned, but it was tied to the selectable, so I do not know actually.