How can I get a sprite subimage width inside draw_sprite_ext(for a better centered X positio[SOLVED]

R

RealsLife

Guest
Code:
for(i = 0; i < array_length_1d(menu); i += 1)
{
 if(i == selection)
    {
    
    draw_sprite_ext( spr_startmenu, 0+i, room_width/2-(sprite_get_width(spr_startmenu)/2), 75+(i*space),1 ,1 , 0, kleur,1);
     }
 else
    {
    draw_sprite_ext( spr_startmenu, 0+i, room_width/2-(sprite_get_width(spr_startmenu)/2), 75+(i*space),1 ,1 , 0, kleur,0.4);
    }
  
}
So in the draw_sprite_ext function I want to put in the X position the middle so room_width/2 but then I want to have every image in the middle I want to use (room_width/2)-(sprite_subimagewidth/2) and cycle trough every subimage inside the sprite.

I don't know how I can get the width of every subimage of that sprite my object itself has no sprite. How can I target a specific sprite in the code and say hey game maker give me the width of that subimage from that sprite.
 
Around here the phrase "doesn't work" is possibly the least helpful thing you can say.

Why doesn't it work? How doesn't it work? Show us or tell us why it "doesn't work".

Centering your origin and then drawing the sprite at the center of the room (room_width/2,room_height/2) will absolutely draw it centered.
 
R

RealsLife

Guest
Around here the phrase "doesn't work" is possibly the least helpful thing you can say.

Why doesn't it work? How doesn't it work? Show us or tell us why it "doesn't work".

Centering your origin and then drawing the sprite at the center of the room (room_width/2,room_height/2) will absolutely draw it centered.
Sorry :p I was doing somthing for a familly member so euh when I put the origin in the center all subimages start at the same point in the room and I think I know why xD. When I added my subimages into game maker studio I had only the option to use the same size for the whole series and not the exact width and height of the image(taken from photoshop). So I will have to crop them somehow as subimages or even readd them from the original images into GMS but I don't really know how to give every subimage another width(the originel width)
 
Yeah. You'll want to create all the images in the same photoshop doc, line them all up, and then export each layer individually without cropping. GM will automatically crop the images on your texture sheet so don't worry about the "wasted" space.
 

xDGameStudios

GameMaker Staff
GameMaker Dev.
inside a sprite all sub_images must have the same width. If you need to have different widths, then you must create multiple sprites!
 
Top