[Game Maker] Some questions

Comments

  • edited
    Thankyou @pieter and @dislekcia for your input.

  • @Jurgen yesterday we had a similar situation in our maze game we needed to implement, here is exactly what we did:
    NO blend modes, just drawing sprite twice with reduced alpha for sprite higher {lower depth value} (as @dislekcia and @pieter also said). Using GMS new draw events, which each draw depth ordered (Meaning all the objects in room will draw at correct depths in a specific DRAWevent, then at higher depth all objects will DRAW_END event - as would the order of all draw events). The solution:

    in objPlayer DRAW event:
    draw_self();

    as well as in objPlayer DRAW_END event:
    ///Draw player behind Blocks(walls)
    draw_sprite_ext(sprite_index, -1, x, y, 1, 1,0,c_white, 0.3);


    NOTE: This only works for ALPHA channel, as @dislekcia said using this with blend modes will give you results which you may only understand if you read the techblogs here: http://www.yoyogames.com/tech_blog/68
  • @Boysano. it works like a charm:). Thankyou for sharing.
  • Jurgen said:
    @Boysano. it works like a charm:). Thankyou for sharing.
    I'm glad that is what you wanted, since it is a limited solution... Oh the 1, 1, you should also rather change to image_xscale, image_yscale in case you manipulate it, like changing out sprites in code and flipping sprites horizontal and vertical with image_xscale = -1;

    DRAW_END:
    ///Draw player behind Blocks(walls)
    draw_sprite_ext(sprite_index, -1, x, y, image_xscale, image_yscale, image_angle, c_white, 0.3);

    Thanked by 1Jurgen
  • hey guys

    How do i use variables in a text. Example draw_text(x,y,"do something'variable' so many times" so to understand this is what i want a person(in game) to ask my player a question but how do i change the amount of times the player must do what he/she must do.
  • string_1 = "Please put the banana in the bucket ";
    string_2 = " times";
    counter = 3;
    
    draw_text( x, y, string_1 + string( counter) + string_2);


    So the important thing here is when you're adding an integer or float to your output via draw_text with a text element you need to convert it to a string by putting it inside string().

    There is some pretty fun comp-sci stuff behind the why ;) but this should get you where you need to go.
    Thanked by 1cooldudue
  • also check out http://www.gmlscripts.com/ when you want to do more advanced stuff, like wrapping text etc.
  • Boysano said:
    Jurgen said:
    @Boysano. it works like a charm:). Thankyou for sharing.
    I'm glad that is what you wanted, since it is a limited solution... Oh the 1, 1, you should also rather change to image_xscale, image_yscale in case you manipulate it, like changing out sprites in code and flipping sprites horizontal and vertical with image_xscale = -1;

    DRAW_END:
    ///Draw player behind Blocks(walls)
    draw_sprite_ext(sprite_index, -1, x, y, image_xscale, image_yscale, image_angle, c_white, 0.3);

    Here is the complicated surface / shader method youtube tutorial
  • Thanks @Boysano.

    Ive been busy with Benjamin Anderson's Udemy course on how to make a platformer and at the same time I've been working on my own one.
    It's going great:)

    I am having a little trouble with orbiting code in my game.

    In my orbiting object's Create Event:
    target = obj_player;
    rotate_spd = 0;
    length_from = 10;
    place = 90;

    Then in my orbiting state script which I execute in the orbiting object's Step Event:
    rotate_spd = -20;
    place += rotate_spd;

    x = (target.x) + lengthdir_x(length_from, place);
    y = (target.y-40) + lengthdir_y(length_from, place);

    image_angle += 1;

    The problem is that the orbiting object should in the end orbit only 180 degrees from start position, for example:
    If the object is at 90 degrees it should orbit around to 270 degrees and stay there until the keyboard_check_pressed event initiates it to orbit another 180 degrees back to 90 degrees and so on.

    Any help would be awesome.
  • Jurgen said:
    The problem is that the orbiting object should in the end orbit only 180 degrees from start position, for example:
    If the object is at 90 degrees it should orbit around to 270 degrees and stay there until the keyboard_check_pressed event initiates it to orbit another 180 degrees back to 90 degrees and so on.
    You need to introduce the concept of a rotation target and then test your current rotation against that whenever you change the rotation. You should also introduce some sort of wrapping so that your rotation doesn't keep increasing forever...

    So, you should add a variable called desired_rotation to your Create event, set it to the current rotation, ie 90. Also, for clarity I've renamed your "place" variable to current_rotation in the code snippets below, because that's what it is ;)

    Now your step event code should do the following:
    if (rotate_spd != 0) {
      old_rotation = current_rotation;
      current_rotation += rotate_spd;
      
      if (rotate_spd > 0) {
        //rotating anti-clockwise, so test accordingly:
        if ((old_rotation < desired_rotation) && (current_rotation > desired_rotation)) {
          //we should stop rotating now and go back to our rotation target.
          rotate_spd = 0;
          current_rotation = desired_rotation;
        }
      } else {
        //rotating clockwise, so test accordingly:
        if ((old_rotation > desired_rotation) && (current_rotation < desired_rotation)) {
          //again, stop rotating and go back to our rotation target.
          rotate_spd = 0;
          current_rotation = desired_rotation;
        }
      }
      
      current_rotation = current_rotation % 360; //This wraps the rotation to between 0 and 360 degrees, always. Yay modulo.
    
      x = (target.x) + lengthdir_x(length_from, current_rotation);
      y = (target.y-40) + lengthdir_y(length_from, current_rotation);
    
      image_angle += 1; //This doesn't set the rotation correctly, it just makes it "spin". Try image_angle = current_rotation instead.
    }


    Now you've got a system that you can turn on and off simply by changing rotate_spd to a positive or negative number. So when you push whatever key it is you care about, simply set rotate_spd to whatever and desired_rotation to whatever point you want it to stop at.
    Thanked by 2pieter Boysano
  • Dislekcia's code works fine, I'd just consider adding "depth = -y;" to each object step event, so it creates fake 2.5d effect if it orbits over the player.
    Thanked by 1Jurgen
  • Thankyou very much @dislekcia.
    I added a variable called add_rotation and I set it to 90.
    Where I initiate the orbiting code with a key press, I set desired_rotation = add_rotation + current_rotation.
    I have two orbiting objects above the player. With each relative key press they rotate 90 degrees, hence four positions available in total.
    Thanked by 1dislekcia
  • If you need help with game maker let me know i'm more than willing to help a hand.
    Thanked by 1Jurgen
  • I am currently working on a space shooter after completing Benjamin Anderson's course.
    Here is the link: https://udemy.com/make-a-game-in-a-single-afternoon-using-gamemaker-studio/

    In my obj_laserbeam's Create event:
    stretch = 0;

    In the obj_laserbeam's Step Event:
    stretch += 1;

    In obj_laserbeam's Draw Event:
    draw_sprite_ext(spr_laserbeam,0,x,y,image_xscale,image_yscale-stretch,0,c_white,1);

    The problem I am having is the following:
    I have an obj_laserbeam and it has a width:8 height:12 sprite. When I press "Q" the sprite stretches in both positive and negative y directions from where it was created which is the center of my space ship.
    What I am wanting to achieve is to have the beam stretched in "only" a negative y direction from ship origin.

    Any help is appreciated:)
  • @Jurgen set the laserbeam's sprites origin to the bottom middle of the sprite, instead of the centre. Then change your draw code in obj_laserbeam to:
    draw_sprite_ext(spr_laserbeam,0,x,y,image_xscale,image_yscale + stretch,0,c_white,1);
    Thanked by 2Jurgen Boysano
  • @pieter, excellent:) thanks. works like a charm.
    Thanked by 1pieter
  • I need help with the fighting game I'm making. More specifically, when my player character is jumped on and he is close to the left or right wall at the left side and right side of the screen, whilst standing on the floor, he moves into the wall and gets stuck.
    Here is the code I think is causing the problem:
    ///scr_collision()
    //Horizontal collision with left wall and right wall
    if place_meeting(x+hspd,y,obj_wall_left){
        while !place_meeting(x+sign(hspd),y,obj_wall_left){
            x += sign(hspd);
        }
       hspd = 0;
    }
    if place_meeting(x+hspd,y,obj_wall_right){
        while !place_meeting(x+sign(hspd),y,obj_wall_right){
            x += sign(hspd);
        }
       hspd = 0;
    }
    
    //Horizontal collision with ai
    if place_meeting(x+hspd,y,obj_ai){
        while !place_meeting(x+sign(hspd),y,obj_ai){
            x += sign(hspd);
        }
       hspd = 0;
    }
    
    
    //Vertical collisions with floor
    if place_meeting(x,y+vspd,obj_floor){
        while !place_meeting(x,y+sign(vspd),obj_floor){
            y += sign(vspd);
        }
        vspd = 0;
    }
    //Vertical collisions with ai from top
    if place_meeting(x,y+vspd,obj_ai){
        while !place_meeting(x,y+sign(vspd),obj_ai){
            y += sign(vspd);
        }
        vspd = 0;
        //close to left wall
        if image_xscale = 1 || image_xscale = -1 && point_distance(x,y,obj_wall_left.x,obj_wall_left.y) <= 40{
            hspd = -avert_spd;
            
        }
        //close to right wall
        if image_xscale = 1 || image_xscale = -1 && point_distance(x,y,obj_wall_right.x,obj_wall_right.y) <= 40{
            hspd = avert_spd;
        }
        //further from left wall
        if point_distance(x,y,obj_wall_left.x,obj_wall_left.y) > 40{
            if image_xscale = 1{
                hspd = -avert_spd;
            }
            if image_xscale = -1{
                hspd = avert_spd;
            }
        }
        //furhter from right wall
        if point_distance(x,y,obj_wall_right.x,obj_wall_right.y) > 40{
            if image_xscale = -1{
                hspd = avert_spd;
                }
            if image_xscale = 1{
                hspd = -avert_spd;
                }
            }
        
        }
    
    x += hspd;
    y += vspd;


    Any help is awesome:)
    Here is a link to my dropbox for the exe of what I have done so far:
    https://dropbox.com/s/7ezeori5i0atbme/FightingGame.exe?dl=0

    Keys:
    arrow keys to move, Q for punch and W for kick.
    The attacking isn't working yet.
  • I haven't done any super extensive testing: but I'm guessing that it has to do with the enemy's knockbacks taking some kind of priority over the wall check. So make sure that you are running the wall check after the enemy knockbacks. (End Step)

    Alternatively you might be being knocked back so far that you've gone beyond the point of checking there being a wall on your 'back', but I can't see wall thickness in game so that's a bit hard to say for sure. As a bit of a hack you might want to do a kind of box collision check and move the character out of the wall if it's being shown to be in there.
    Thanked by 1Jurgen
  • @Karuji, thanx, I figured it out.

    In the player collision script used in its step event I put this code before all other collision checks:
    //Horizontal collision with ai
    if place_meeting(x+hspd,y,obj_ai){
        while !place_meeting(x+sign(hspd),y,obj_ai){
            x += sign(hspd);
        }
        if !place_meeting(x,y+1,obj_floor) && place_meeting(x,y+1,obj_ai){
        hspd = -(image_xscale*avert_spd);//avert spd is the spd that the object moves just to the side of the other object
        }else{
        hspd = 0;
        }    
    }


    In the ai collision script in its step event the same as above, before all collision checks:
    //Horizontal collision with player
    if place_meeting(x+hspd,y,obj_player){
        while !place_meeting(x+sign(hspd),y,obj_player){
            x += sign(hspd);
        }
        if !place_meeting(x,y+1,obj_floor) && place_meeting(x,y+1,obj_player){
        hspd = (image_xscale*avert_spd);
        }else{
        hspd = 0;
        }    
    }


    Awesome:)
  • I recently bought a Gioteck Vx2 wired controller for PS3 to use in conjunction with Game Maker Studio.
    I tried the advise mentioned at the beginning of this discussion, and I am still having trouble.
    Has anyone been able to get such a controller to work in GMS?

    I know there are joystick functions in GMS, yet I am unsure how to do button_check_pressed type implementations.

    Any help would be awesome:)
  • @Jurgen I just need a little bit more information in order to give you useful advice. Could you please tell me what kind of trouble are you having, and what is it you are trying to achieve?
  • @pieter, Im trying to have GMS recognize directinput for the Gioteck Vx2 controller. For some reason it doesn't recognize the controller in gamepad functions, only joystick functions. I have managed to get a test object moving with the D-pad using joystick_pov functions and the joystick button check function works, yet I am struggling with check pressed type implementations.

    Earlier today I bought a Xbox 360 wireless controller and it works with GMS, so if all else fails, I'm set with xinput.

    It would be awesome if I could use both directinput and xinput controllers with my game, especially when I get to implementing 2 player vs.
  • GameMaker states in their help file that only XInput devices are supported, so that's what we have to work with.

    You can get your PS3 controllers to look like XBox controller by using the SCP Toolkit. It take a few steps to get setup, but it's how I got my PS3 controllers to work with GameMaker.

    Download below, and be sure to read through all the installation requirement.
    SCP Toolkit
    Installation Requirements

    Also, NEVER install MotionJoy, it's a hateful piece of software that you will struggle to get off your PC.
    Thanked by 2Boysano Jurgen
  • you could also mention in a readme or faq that x360ce works pretty well for mapping dinput to xinput,
    as I'm not sure what issues there might be regarding licensing for you to bundle it with the game.
Sign In or Register to comment.