Legacy GM Drawing Object sprites from a ds_list[solved]

W

Wild_West

Guest
I need to draw the sprites of objects I store in a list but every time I try for some reason my inventory object draws my sprite above the object writing the code no matter where I put the y value.

I'm just doing a loop and drawing whatever's in the array at the checked position if there's something there to be drawn.

Code:
for( i = 0; i < 7; i += 1; )
{
   draw_sprite(inventory_slot_spr, 0, x, y+100*i);
   
   if( ds_list_find_value(stones_sprites_inventory, i) != sprite_index )
   { draw_sprite( ds_list_find_value(stones_sprites_inventory, i), 0, x+100, y+200*i ); }
}
It draws exactly like I want save for the very top position. I don't know what's wrong with it
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
How a bout a screenshot of the issue so we know exactly what the issue is? Also, just for clarity and to rule it out as an issue, you should explicitly bracket your maths, so this "y + 200 * i" should be "y + (200 * i)".
 
W

Wild_West

Guest
How a bout a screenshot of the issue so we know exactly what the issue is? Also, just for clarity and to rule it out as an issue, you should explicitly bracket your maths, so this "y + 200 * i" should be "y + (200 * i)".
I mean never had any trouble with doing it the way I had it up til now. Not like I'm a math major

Here's the image. Like I said, 1 draws in the box 1 draws above the box
 

chamaeleon

Member
Code:
draw_sprite(inventory_slot_spr, 0, x, y+100*i);
draw_sprite( ds_list_find_value(stones_sprites_inventory, i), 0, x+100, y+200*i );
The two different multipliers, 100 and 200, will produce unequal spacing, one draw statement drawing twice as far apart between items compared to the other. Any reason why they are not the same, either 100 or 200?
 
W

Wild_West

Guest
The two different multipliers, 100 and 200, will produce unequal spacing, one draw statement drawing twice as far apart between items compared to the other. Any reason why they are not the same, either 100 or 200?
Not really I was just getting desperate on ideas to fix the thing.
 
W

Wild_West

Guest
The two different multipliers, 100 and 200, will produce unequal spacing, one draw statement drawing twice as far apart between items compared to the other. Any reason why they are not the same, either 100 or 200?
Okay I've tried everything I can think of, I moved where the inventory object is, I changed the draw Y position to 150 , 400, 200, and the first sprite is still drawing above the inventory. So I can only assume the inventory is ignoring the code for where to draw the first thing it has. I know my loop is set up right because the inventory is drawing ITSELF right just not what goes in it's 1st position. The second thing I add to ti always draws where it should be.

This is still what the code looks like

Code:
for( i = 0; i < 7; i += 1; )
{
   draw_sprite(inventory_slot_spr, 0, x, y+100*i);
   
   if( ds_list_find_value(stones_sprites_inventory, i) != sprite_index )
   { draw_sprite( ds_list_find_value(stones_sprites_inventory, i), 0, x+100, y+100*i ); }
}
 
D

dannyjenn

Guest
I don't know if this is the problem, but you should get rid of the semicolon after the i += 1.

Is the uppermost box drawn at (x+0,y+0)? Or is it drawn at (x+0, y+100)? If the latter, the box sprite's origin is most likely set wrong.
 
W

Wild_West

Guest
I don't know if this is the problem, but you should get rid of the semicolon after the i += 1.

Is the uppermost box drawn at (x+0,y+0)? Or is it drawn at (x+0, y+100)? If the latter, the box sprite's origin is most likely set wrong.
The uppermost box is at like the width of the room and 100 pixels down, it's own sprite height. what does the semi colon have to do with anything that's just proper syntax isn't it? I've used it before in loops fine
 

chamaeleon

Member
The uppermost box is at like the width of the room and 100 pixels down, it's own sprite height. what does the semi colon have to do with anything that's just proper syntax isn't it? I've used it before in loops fine
If the sprite origin is not at the same location for the two different types of sprites for a reason you may want to use something like y+100*i-50,experimenting with the 50 part until it matches your expectations.
 
W

Wild_West

Guest
If the sprite origin is not at the same location for the two different types of sprites for a reason you may want to use something like y+100*i-50,experimenting with the 50 part until it matches your expectations.
But a negative value would move the sprite up, it's already drawing the sprite above the inventory , I need it moved down by 100, and no matter what I do it stays where it is. except for the second item it draws. That's always in the right position
 

chamaeleon

Member
But a negative value would move the sprite up, it's already drawing the sprite above the inventory , I need it moved down by 100, and no matter what I do it stays where it is. except for the second item it draws. That's always in the right position
Lost track of which sprite needed to move in what direction That is why I mentioned experimenting with the value of 50. Didn't mention it could be +50 as well. And I am leaving it up to you to figure out if this offset belongs more for the slot or the stone sprite.
 
W

Wild_West

Guest
Lost track of which sprite needed to move in what direction That is why I mentioned experimenting with the value of 50. Didn't mention it could be +50 as well. And I am leaving it up to you to figure out if this offset belongs more for the slot or the stone sprite.
It's the stone sprite, the very top slot of the inventory is an actual object the slots under it are the object drawing it's own sprite using the same loop I use for for the drawing of objects IN the inventory list
 
W

Wild_West

Guest
Lost track of which sprite needed to move in what direction That is why I mentioned experimenting with the value of 50. Didn't mention it could be +50 as well. And I am leaving it up to you to figure out if this offset belongs more for the slot or the stone sprite.
Okay the y +100 *i +100 finally got it right, I still don't get what was going on with the math but at least it looks right now. Thanks
 
D

dannyjenn

Guest
what does the semi colon have to do with anything that's just proper syntax isn't it? I've used it before in loops fine
Well GameMaker's syntax is pretty flexible, so I don't know. Maybe it's fine. But in most languages, for loops are set up like this:
Code:
for(i=0; i<7; i+=1){ // <-- semicolon after i=0, and semicolon after i<7, but no semicolon after i+=1
    // code
}
 
W

Wild_West

Guest
Well GameMaker's syntax is pretty flexible, so I don't know. Maybe it's fine. But in most languages, for loops are set up like this:
Code:
for(i=0; i<7; i+=1){ // <-- semicolon after i=0, and semicolon after i<7, but no semicolon after i+=1
    // code
}
I mean yeah I've seen them written that way but game maker's doesn't really matter
 
Top