Gamemaker Studio2, Draw GUI layer conflict - game-maker-studio-2

I would like to preface this by saying I am still quite new to gameMakerstudio and I do not know all there is to know about how the software works and this is probably the root cause of my problem as I do not know why I am having this current layering issue.
I have been having an issue where I have TWO DrawGUI events in separate objects within the same room.
The first object is a Fog Of War that draws a GUI and reveals the map as the player moves, and keeps explored places visible but not in view.
The second object is the joystick where a player will use their thumb to drag the stick to move the player.
Ever since I have implemented the Fog of War. I have been unable to view the joystick. It appears that the fog of war draws overtop of it and I am unable to use it.
I understand there are other draw events where I can do this.
Draw
Draw GUI
Draw Begin
Draw End
Draw GUI BEGIN
Draw GUI END
After changing where I have the code drawing.
Example: At first the joystick and the fog were both in Draw GUI, After moving one from Draw GUI to Draw GUI Begin, the same issue appears.
I have made sure to place the joystick at the top most level in the room and the fog of war at the bottom most layer.
I have tried to apply depth the object
oJoystick_Stick.depth = -100;
this does not achieve anything.
Is there another way to force two objects on the GUI layer to be on top of the other?

To my understanding, DrawGUI always prioritises the objects drawn there above anything in Draw, including Begin Draw and End Draw. This is because DrawGUI is for an interface (like the stats you see about your character like health, ammo ect.), and objects drawn there aren't part of the room itself. You may also have noticed that the objects drawn in DrawGUI also follows the camera/Viewpoint.
So, to clear up the draw priority:
First is the DrawGUI layer that places objects in front of everything, like an interface.
After that, the depth variable and layers inside the room has priority, each layer has also given a depth value, with an interval of 100.
If the depth is also the same (for example when they're in the same layer), then the order of the objects and code loaded decides the order drawn.
The latter is not always reliable when multiple objects are overlapping at the same depth, because if the objects are redrawn in-game again (e.g. a persistent object been loaded into a new room, or pause and unpause using instance_activate_all), then the order of objects drawn may differ. Keep in mind when overlapping objects, that they are placed in different layers to prevent mixed priorities.
I've however not used a Fog of War system myself, so I don't know if it's build-in or not, but I wouldn't recommend placing them in the DrawGUI, as that should be reserved for the interface layout. With the default Draw options, you'll have more flexibility to the layers inside the room.

Some advice about DrawGUI
DrawGUI Begin --> call the event before every drawGUI in that moment
DrawGUI --------> the event is called sync with the screen refresh rate
DrawGUI End ----> call the event after every drawGUI in that moment
so GM-Studio "pipeline" for the DrawGUI is like the step event, we have a BEGIN, a CURRENT, an END.
To prioritize the object render, GM-Studio use the depth in-build variabile. Take the 0 as the reference value. Object with depth value > 0 are rendering as last. Object with depth value < 0 are rendering infront everything.
Check the depth during the calling of the instance_create_depth() function, check where the depth variabile is changing, check in the room editor for each instance layer the depth value. and z-order.

Related

Create pop menu Sims's style when click on Character in Unity3D

I'm trying to build a game that uses a concept from the known game "The Sims". Right now I'm building the AI for a 3d Character, and I need the player to be able to tell where the character should go or do. I want to know the best ways to create a pop up menu with animations, kind of to show some choices, so that when the player clicks over the 3d Character he can pick wherever he wants to do. I know this must be using UI elements under a Canvas that's placed over the player. However I can not have 2 Canvas in a Scene and I don't know how to fix them to the character so that it moves with him. Thanks in advance.
Here you can see what I mean, this is the Sims Game
You have two main approaches here:
1) Use a world space UI.
2) Use a screen space UI and position it in real time using a worldspace to screen space transformation.
Both of these topics will expand substantially when you approach them, so it's not possible to give any more specifics from here.
Having played the Sims a bit before though, I would suggest you use a world space UI system if you're chasing the same style as them.
You can have as many canvases as you want. To control levels of canvases (which one is on top) you use "Order in Layer" parameter in "Canvas" component of your chosen Canvas. The lower the number is the higher interactivity and visibility your canvas has.
You can create one canvas ant parent it to you character. AS the canvas will be smaller your should play with these parameters to get the resolution you want (don't over do it):
To make canvas always facing the camera you should give Canvas a new script, with a command:
canvas.transform.LookAt(camera.transform);
To control canvas' visibility you may use this code line:
canvas.enabled = bool;
Where bool is false when you want to hide it and bool is true when you want to show it.
In the "Sims" the visibility comes with animation which you may do also, but I would leave it after I did all the functionality.

Group of objects on top but added to a camera

As a precision I already noticed threads about this but didn't find a way to achieve exactly what I need.
Basicaly I have a board of objects that I need remaining always on top of everything but also attached to the camera.
I first tried to add the group to the camera and it stayed as wished always in the viewport. But in this configuration the group of objects still be a part of the scene so while zooming to regular objects in the "editor" the board goes into/among these objects of the scene.
My second trial was based on this thread and work wonderfully in order to get all of the board objects rendered above everything. But on such a configuration when rotating around the axis (with orbit control) both scenes rotates. So I tried to update the foreground scene with coordinates of the camera but the update was not immediate and this scene is flickering (I suppose that while rotating the update function is not called immediately).
My best wish would have been to "attach" the foreground scene to the camera so that it would stay on top and sticked on the screen/viewport but I don't even know if it is possible and how to do that (as only groups of objects seem to be capable to be attached to the camera).
I am really stuck on that point. Thanks you for any help!
If this is what you need,
just set object.material.depthTest = false; and object.renderOrder = 1000; for all objects you need to be always on top and attached to the camera.

EaselJS and multi layered canvas system: performance tuning, game developing, event handling

I'm an engineer and we are currently porting our Red5 + Flash game into a Node.js + Easeljs html5 application.
Basicly: it's a board game, not an rpg. The layer system means we have multiple canvasses, based on functionally. For example there is a static background stage, with images. There is a layer for just the timers.
At default, all canvas size is 1920x1080, if needed we downscale to fit to the resolution.
The first approach used kinetic.js, but the performance fallen when the game got complex. Then we switched to easel, because it's abstraction level is lower, so we can decide how to implement some more function, not just use the provided robust one.
I was optimistic, but now it's starting to show slowness again, that's why I want to look deeper inside and do fine performance tuning. (Of course everything is fine in Chrome, Firefox is the problem, but the game must run smoothly on all modern browser).
The main layer (stage) is the map, contains ~30 containers, in each there is a complex custom shape, ~10 images. The containers are listening to mouse events, like mouseover, out, click. Currently, for example on mouseover I refill the shape with gradient.
Somehow, when I use cache, like the way in the tuts the performance get even worse, so I assume I'm messing up something.
I collected some advanced questions:
In the described situation when can I use cache and how? I've already tried cache on init, cacheUpdate after fill with other color or gradient, then stage.update(). No impact.
If I have a static, never changing stage cache doesn't make sense on that layer, right?
What stage.update() exactly do? Triggering the full layer redraw? The doc mentions some kind of intelligent if changed then redraw effect.
If I want to refill a custom shape with new color or gradient I have to completely redraw its graphics, not just use a setFill method, right?
In easel there is no possibility to redraw just a container for example, so how can I manage to not update the whole stage, but just the one container that changed? I thought I can achieve this with caching, cache all containers the just update the one that changed, but this way didn't work at all for me.
Does it make sense to cache bitmap images? If there are custom shapes and images in a container what is better? Cache the container or just the shape in container.
I found a strange bug, or at least an interesting clue. My canvas layers totally overlapping. On the inferior layers the mouseover listening is working well, but the click isn't on the very same container/object.
How can I produce a click event propagation to overlapped layers those have click listeners? I've tried it with simple DOM, jquery, but the event objects were far away from what canvas listeners wanted to get.
In brief, methods and props I've already played with bare success when tried tuning: cache(), updateCache(), update(), mouseEnabled, snapToPixel, clear(), autoClear, enableMouseOver, useRAF, setFPS().
Any answer, suggestion, starting point appreciated.
UPDATE:
This free board game is a strategy game, so you are facing a world map, with ~30 territories. The custom shapes are the territories and a container holds a territory shape and the icons that should be over the territory. This container overlapping is minimal.
An example mouse event is a hover effect. The player navigate over the territory shape then the shape is getting recolored, resized, etc and a bubble showing up with details about the place.
Basically, maximum amount of 1-3 container could change at once (except the init phase -> all at this time). Not just the animations and recoloring slow in FF, but the listener delay is high too.
I wrote a change handler, so I only stage.update() up on tick the modified stages and the stages where an animation is running (tweenjs).
In my first approach I put every image to the container that could be needed at least once during the game, so I only set visible flags on images (not vectors).
Regarding caching:
There are some strange caching-issues, somehow the performance can drop with certain sizes of the caching rectangle: CreateJS / EaselJS Strange Performance with certain size shapes
(2) Depending on how often you call stage.update();
(3)
Each time the update method is called, the stage will tick any
descendants exposing a tick method (ex. BitmapAnimation) and render
its entire display list to the canvas. Any parameters passed to update
will be passed on to any onTick handlers.
=> Afaik it rerenders everything if not cached
(4) Yes.
(5) No. (I don't know of any)
(6) If the content's of the container don't change often, I'd cache the whole container, otherwise the container will be reconstructed every frame.
I have a question though: Why do you use multiple canvases? How many do you use? I could imagine that using multiple canvases might slow down the game.
How many sprites do you use in total?
2: if your layer or stage doesn't change, don't call stage.update() for that layer (so it doesn't gets rerendered, gives me a much lower cpu!)
For example, keep a global "stagechanged" variable and set this to true when something has changed:
createjs.Ticker.addEventListener("tick",
function() {
if (stagechanged)
{
stagechanged = false;
stage.update();
}
});
(or do you already use this, as stated in your "update"?)
4: I found a way to update for example the fill color :)
contaier1.shape1.graphics._fillInstructions[0].params[1] = '#FFFFFF';
(use chrome debugger to look at the _fillInstructions array to see which array position contains your color)
5: I found a way to just paint one container :)
//manual draw 1 component (!)
var a = stage.canvas.getContext("2d");
a.save();
container1.updateContext(a); //set position(x,y) on context
container1.draw(a);
a.restore();

Cocoa drawing issues

I'm working on an application that does some drawing on the screen based on information received over the network. 
My problem is that sometimes those events come in at a rate higher than I can draw and I'm experiencing a delay. Now the problem isn't with the delay it's with the type of delay that builds up. 
If I would draw based on events such as clicking with the mouse and dragging this doesn't happen and I assume it's because of the way events are delivered. How could I find out when the view is "ready" to draw again because then I could discard some of the events received over the network and draw just the most recent ones. 
Right now I have a transparent window that is on "top" of the window hierarchy. 
Im drawing on an NSImage that is the size of the screen an after each drawing operation I make a setneedsdisplayinrect call to the view in which the drawing happens. When I receive the drawrect call I draw the portion of the image which is included in the dirty rect. 
My attempt of solving this is a bit of a hack since I don't know another way to do it. I set a Boolean to true after each setneedsdisplayinrect and I set it to false in drawrect. If I get a subsequent event to draw on the image I just ignore it of the Boolean is set to true. 
What other alternatives of doing this do I have? 
I thought of using cashapelayers and modifying their path but I'm not sure how efficient shape layers are once the path gets big. I also thought of using multiple shape layers for different portions of the path that are separated (not continuous) but if I want to clear the drawing and i remove the layers if there are many I noticed a bit of a performance hog. 
The only other way I could think of is drawing with open gl but considering the nature of the OpenGL view (screen size and transparent) I'm not sure how much of a performance issue will this be. 
Any tips would be greatly appreciated. 
Thanks. 
I figured it out :)
From the object that managed the network connection I was sending events out using the main dispatch queue. Which from what I understand - I might be wrong about this - can span across multiple iterations of the runloop. What I needed was to dispatch events during each iteration of the run loop and by creating a custom run loop source that would signal the main runloop every time I get a new event over the network connection it greatly improved my performance.

Placing objects on scrolling background in XNA

How do I place objects that appear only if the background scrolls to a certain point?
Example- I have this long image that keeps scrolling using the technique above. However, after scrolling to part of the image, I want to add a platform there. How would I do that?
In general, you will probably need to save the locations of your objects in a file and then load that file at the beginning of the level (assuming you are making some kind of platformer game). You can do this by creating a class or a struct containing all the relevant information for the platform (position, size, texture, etc) and then using XML serialization to write an array of those classes/structs to a file.
Your level loader would then load and deserialize the level data, which would end up being a list of all the objects in your level (such as platforms). Now that you have the locations of your platforms in memory you have a couple different options on how to get them to the screen.
Draw all the objects (platforms) all the time, whether or not they are in the view of the camera. If your levels don't contain a lot of objects, this would be simple to implement.
Draw only those in the camera's view. Without knowing how you implemented the horizontal scroller, it's kind of hard to make suggestions for this part. Whatever mechanism you currently have to identify the boundaries of what part of the background to show could be used to determine which objects to draw as well.
I'm working on a game that scrolls vertically right now, and I needed a way to do something similar: place objects in a level and have them appear when the background scrolled to them. I used TorqueX 2D (free engine binaries if you've payed to develop for XNA) and its 2D scene editor to set this up pretty easily. I have my camera scrolling up, the background stays in place. When it gets to an object position defined in the XML level file it spawns the object in the level.

Resources