GMS 2 Why start at 0?

C

Canamla

Guest
Not sure if this is the right forum for this, but...

I haven't had an issue with the whole starting at integer '0' until creating sprite resources within GMS2. I'll show my hiccup here:

BEFORE realizing that a 32*32 tile is read as 31*31 in sprite editor...


AFTER

I can totally work around this, but I'm wondering why is this a thing? what purpose does it serve? And on a slightly related topic, why does the top left tile in every tile sprite have to be empty?

Sorry if this is a redundant topic, but I did not know how to search for this. I'm super curious to the purpose and function of this case :)
I'm familiar with '0' being absolute null, not upper left. Even in algebra, 0,0 was the center of a grid. The origin, not the upper left... Although, now that I say that, I understand that the origin is default to the upper left of the upper left pixel in the sprite editor. Is that why the numbers are 1 less than the pixel dimensions?

Again, super curious. I want to understand! :)

EDIT1:
flickr won't load, I guess. But basically, I had mad my top-left and bottom-right tiles too wide and the top-right and bottom-left too tall. It looks neat, but won't be in later applications :p
The neighboring tiles would bleed over by one pixel and appear as part of the tile.

Also, how to use flickr to share photos with y'all? That would be nice to know. Photobucket was simple, but I can't find anything wrong with my flickr links. PhotoBullcrap is lame these days...



EDIT2: BTW, totally a non-issue! I was just perplexed when designing and have to adapt.
 
Last edited by a moderator:

Xer0botXer0

Senpai
I have issues with this too now and then. Where I either have one less or one more.

0,0 are Cartesian coordinates, it starts at the top left and we work across and down. Because we're working in a 2D space.

We can also see depth as the third dimension in a sense, for top down.

But that seems a little off topic to what you're enquiring on, I'm a 1.4 kinda guy. Haha. Must be nice to have 2.0 though I saw some nice GUI designs there.
 

FrostyCat

Member
(0, 0) became the top-left corner in 2D graphics because historically that was where text started reading on a console screen, thus the standard raster scan pattern also ran that way (left-right, top-down) and the coordinate system went with it.
 

Roderick

Member
Because, to a computer, 0 is the first number.

There are a lot of things that you need that zero for (like being able to represent any number over 255). For consistency sake, everything starts at zero*, instead of making you remember which ones don't.

*except the ones that wouldn't make sense, like position in a string starts at 1.
 

Roderick

Member
Also imagine 0,0 being st the center of a room.. that would be a headache to work with.
There's no reason you couldn't do that, and in some cases, it might be beneficial.

Game Maker's built in view movement would balk at going above or left of (0, 0), but if you manually move the view, it will work just fine.
 

Perseus

Not Medusa
Forum Staff
Moderator
And on a slightly related topic, why does the top left tile in every tile sprite have to be empty?
Quoting Mike on this one:
Please read the docs on this, tile 0 is "special" in that it's not even drawn. So no matter what you put there it'll always be dropped out of the rendering. This helps optimise tile rendering a lot, and aids when having many overlapping tile layers.

We have discussed changing this so that it'll allow a tileset to be imported better, but it will mean your tiles start at 1, not 0 - which probably isn't a big issue. To me, it's important o know that the first tile on your texture page is 0, especially if your trying to do ant special effects with your tiles, which is why its reserved.
Also, how to use flickr to share photos with y'all?
For [img] BB code tags to work properly, you must make sure that the image URL you're using is a direct link to the image. The URLs that you have used in the main post are not direct links, but links to webpages that contain the images. A direct link always ends in an image file extension (.png, .gif, etc.) -- check out this page to see whatI mean. Getting one from Flickr is sadly a bit of hassle, so I suggest using a different image hosting service (preferably Imgur or Postimage) or the GMC's native attachment system.
 

NicoFIDI

Member
the real answer of why 0 and not 1 goes back to assebly, where you move memory and 0 means no move while 1 means move 1

as help, you can see the index as progress,
when you start you have no progress,
and when you complete the progress you dont need to keep going.

Code:
var complete_task = 32;
for (var progress = 0; progress < complete_task; progress++) {
    //keep going, you didnt make it yet!!
}
XD it's a silly way to see it but i hope it helps
 
C

Canamla

Guest
Very interesting perspective. Thank you all for enlightening me. Makes total sense. Good example, NicoFIDI. I'll also have to keep the strangeness in mind when dealing with strings. Whenever I manage to learn about them xD
At least I'm aware of it now lol
 

NicoFIDI

Member
And if someone cares:
why when you decalre a 5 slots array goes from 0 to 4?.

when you declare a 5 length array of "something"
the program takes the size in bits of the "something" 5 times in a row

so if somethig weight 32bits the program takes 160bits from the ram
and saves the start point of those bits in ram position
(sounds crazy but the ram position it's actually a number).

when you call array[ i] the machine literally makes:

go to the bit( start point + i * sizeof(something) ) and (take sizeof(something) bits)

and as you see, if i=0 takes the start point
and the value 5, takes bits that the array dont own.

:3 may be heavy, but with this theres no question about why it's like that.
 

Hyomoto

Member
Because 0, 1, 2, 3, 4 is five spaces. Instead of thinking of 0 as being nothing, it's easier to think of it as a position. Sure, it may seem odd before you understand how binary numbers work, but ignoring 0 is basically ignoring 1/2 bit, and doing so means 4 spaces would require 3 bits instead of 2. This is probably less essential now, but it would have been ridiculously wasteful with earlier computers and is likely not just a best practice, but at least somewhat influenced by that. Programming often deals with efficiency and starting at one would be far less efficient.
 
Last edited:
Top