• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Disappearing objects!

M

Mylon

Guest
Hi, I'm new to Game Maker but not to programming.

I'm currently at step 1 of the Turn Based Strategy tutorial (https://forum.yoyogames.com/index.php?threads/turn-based-strategy-101-video-series.3428/) but I went a little off the rails. Rather than limiting myself to a grid drawn at the size of the window, I wanted to make a bigger battlefield. So I added a camera object and made it respond to keys so I can scroll up/down/left/right so I can see a bigger area.

Now this little experiment has left me with a million questions as I'm learning the quirks of GM, such as:
* why does "view_xport[0] + 10" move the view to the left rather than the right? Same behavior seen with view_yport[0].
* Is there a way to not play animations by default? I want a button with a unpressed, hover, and pressed graphic. Are using frames within the same sprite not the right way to do this?
* Why does my button draw twice? If I comment out the draw_self() line on the tile->draw->execute code script, the tile does not get drawn. But my button seems to get drawn during the draw step and the draw_GUI step!
* Why is the area outside of the room black? How strictly are the room boundaries enforced?
* Why is the room not larger? I tried setting the size to 10240 x 7680 but the bottom right corner ( at 1025,769 ) is still black and not the expected background color.
* Attaching code to various objects at various stages seems like it can get crazy to manage and code can end up hidden everywhere. Is there a better way to see/organize my code?

But the real obstacle I ran into is when I scroll up/left, everything is fine. When I scroll down/right such that the top-left corner of the room is no longer visible, all of the tiles disappear! What makes the top/left corner so magical to the "tile->draw->code->draw_self()" step?
 

Attachments

jo-thijs

Member
Hi and welcome to the GMC!

* why does "view_xport[0] + 10" move the view to the left rather than the right? Same behavior seen with view_yport[0].
view_xport holds the x position of where the view should be drawn in the window (can be influenced by scaling settings).
You rather want to use view_xview, which holds the x position of the view inside the room.

* Is there a way to not play animations by default? I want a button with a unpressed, hover, and pressed graphic. Are using frames within the same sprite not the right way to do this?
Set the variable image_speed to 0, this will stop the animation.
Change image_index to decide which image of the current sprite to show.

* Why does my button draw twice? If I comment out the draw_self() line on the tile->draw->execute code script, the tile does not get drawn. But my button seems to get drawn during the draw step and the draw_GUI step!
The draw event has a default code that draws the sprite of the instance.
Put empty code (or any other code, like a comment saying not to delete the action) inside the draw event to get rid of this default draw behaviour for that object.
If you already had code in the draw event of your object, executing draw_self, then that's your problem.
Comment that line away in that case.

* Why is the area outside of the room black? How strictly are the room boundaries enforced?
Are you talking about the regions in your window where no view is being drawn?
That's because in the global game settings, the colour outside the room region is set to black.
You can change it though.

* Why is the room not larger? I tried setting the size to 10240 x 7680 but the bottom right corner ( at 1025,769 ) is still black and not the expected background color.
That's because you're not moving your view, but the port of the view.

* Attaching code to various objects at various stages seems like it can get crazy to manage and code can end up hidden everywhere. Is there a better way to see/organize my code?
It kind of depends. I know many people would argue there is, by using scripts.
However, I would ask how you're managing things right now in order to tell if there's a better way to manage things.

But the real obstacle I ran into is when I scroll up/left, everything is fine. When I scroll down/right such that the top-left corner of the room is no longer visible, all of the tiles disappear! What makes the top/left corner so magical to the "tile->draw->code->draw_self()" step?
If I understand you correctly, this is due to the view port being moved, rather than the view in the room itself.
 
M

Mylon

Guest
Changing to view_xview/view_yview! solved a lot of issues! So many view_* variables, it's hard to keep track of them all!

Moving/drawing outside of the room seems to be a non-issue. So I can probably focus on drawing and pay little attention to absolute coords and roomsize.

My button no longer is cycling through the frames, but I'm still uncomfortable about the idea of having a "on create" event attached to each and every one! Seems messy. I should probably make a comprehensive GUI-building script for maintainability.

I'm still not sure why my button is being drawn twice, once in viewport coords (via the draw_gui event) and once in absolute coords. I only want it to be drawn once in viewport coords. If I attach a "draw->execute code->"//empty code" it goes away, but needing to do this for every GUI element again seems messy!
 

jo-thijs

Member
You can create parent objects.
When editing an object, you can assign it a parent.
Every event that has no code in it, will inherit the code of the parent object for that event.
For example, you can have an object: obj_par_gui
with empty code in its draw event,
then set it as the parent object of every other gui object
and you won't have to repeat the process.
The same for the buttons, just create a parent object that sets image_speed to 0 in its create event.
 
Top