1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

Objects Id connected to draw sprite

Discussion in 'Programming' started by Two_kings_Games, Aug 26, 2019.

  1. Two_kings_Games

    Two_kings_Games Member

    Joined:
    May 19, 2019
    Posts:
    13
    Hello everyone. Have a cool person who used pseudo code to help me understand. I'm pretty sure im getting it but something isnt working right and Im not sure. Been reading in on for loops, with statements and ds_list for days. Been on this issue a little long and think it's time to ask for help. Hopefully they'll get back to me soon but I'd like the opinion of the community to.


    ///obj_controller Draw event//

    if (obj_game_controller.state == "Battle"){

    draw_rectangle_color(Battel_Bar.Bar_Start,300, Battel_Bar.Bar_End,310,c_white,c_white,c_white,c_white,true)
    for (var i = 0; i < ds_list_size(global.Add_ally); i++){
    with (ds_list_find_value(global.Add_ally,i)){
    draw_sprite(spr_player_icon,0,ix,290)
    }
    }
    }

    ok so what I want. When the game state equals battle. draw a rectangle. then for every ally within the ds_list, take their value (the objects id), then with the ds_list_find_value draw a sprite with the objects Id.

    This is what I'm getting from that with the code above. But the only problem seems to be that the icon will not be drawn. i thought it may have been the ds_list. But that cant be it. I have a method for testing if the ds_list exist and it works.

    So anyone who reads please help me out. I am new to this and Im happy that my friend is using pseudo code to help me start thinking in the way that I need. But I've only ever been stuck for a day at the most before getting it.



    at 24 second bottom 2 right corner is what I'm going for
     
  2. marasovec

    marasovec Member

    Joined:
    Sep 15, 2016
    Posts:
    333
    Hmm... aren't the objects set as invisible?
    Because that would disable their Draw events
     
  3. Two_kings_Games

    Two_kings_Games Member

    Joined:
    May 19, 2019
    Posts:
    13
    well it's all being drawn in the obj_game controller with nothing attached to it. The player and enemies have their own objects. The icon itself is just a sprite and seems to be the only thing not appearing
     
  4. the_dude_abides

    the_dude_abides Member

    Joined:
    Jun 23, 2016
    Posts:
    673
    if (obj_game_controller.state == "Battle"){

    draw_rectangle_color(Battel_Bar.Bar_Start,300, Battel_Bar.Bar_End,310,c_white,c_white,c_white,c_white,true)
    for (var i = 0; i < ds_list_size(global.Add_ally); i++){
    with (ds_list_find_value(global.Add_ally,i)){
    draw_sprite(spr_player_icon,0,ix,290) <<<< ix? if 'i' is an id being drawn from the list it should be i.x
    }
    }
    }
     
  5. Two_kings_Games

    Two_kings_Games Member

    Joined:
    May 19, 2019
    Posts:
    13
    ah my bad. ix is another variable in a create event for the x position.
     
  6. the_dude_abides

    the_dude_abides Member

    Joined:
    Jun 23, 2016
    Posts:
    673
    I realised I read that wrong...my bad!

    So....you're reading a ds list with id's on it, and then using that in a with statement. Have you tried doing it so that the calling object draws it instead?


    Code:
    if (obj_game_controller.state == "Battle")
    {
    
    draw_rectangle_color(Battel_Bar.Bar_Start,300, Battel_Bar.Bar_End,310,c_white,c_white,c_white,c_white,true)
    for (var i = 0; i < ds_list_size(global.Add_ally); i++)
    {
    is_id = ds_list_find_value(global.Add_ally, i);
    draw_sprite(is_id.spr_player_icon, 0, is_id.ix, 290) // ??
    }
    }
    
    Not sure if that's correct for how you've implemented things, but I'm trying to have obj_Controller get the sprite info and position from 'is_id' and then just draw it itself within the same event.

    A possibility might be that the draw depth for obj_Controller means its drawing the bar over the character images, so by having it draw all of them you wouldn't have that happen...I think, can't say for sure.

    EDIT: Draw depth doesn't seem to matter.
    Code:
    if do_draw
    {draw_rectangle(x - 200, y - 200, x + 200, y + 200, false)
    with (object10)
    {draw_sprite(sprite3, 0, x, y)
    }
    }
    Regardless of which draw event I had this in, or the depth of object10 / the calling object, it still drew the sprites over the rectangle. Perhaps manually drawing sprites ignores draw depth, and instead works on the order in which they are drawn?

    But your original code should work the same as above, so what is different?

    You say the ds list exists, but have you confirmed it has any content - using ds_list_size to make sure it has any info to begin with?
     
    Last edited: Aug 28, 2019

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice