Question - Code Need help with random cursor

Discussion in 'GameMaker Studio 2 Community Tech Support' started by Joshua Hotchin, Apr 17, 2019 at 11:27 AM.

  1. Joshua Hotchin

    Joshua Hotchin Member

    Joined:
    Jan 19, 2017
    Posts:
    39
    Hey guys,
    So I have a sprite with 10 images, all different coloured cursors.
    Here is my code:
    Code:
    if (room != rMenu) and (room != rControls) and (room != rUpdatesAndNotes) and (room != rShop) and (room != rEnding) and (room != rCredits)
    {
        cursor_sprite = sCursorGun;
    }
    else
    {
        cursor_sprite = sCursor;
        with (sCursor)
        {
            image_speed = 0;
            image_index = (choose(0,1,2,3,4,5,6,7,8,9));
        }
    }
    The idea is that every time a room is started the cursor is a random colour. At the moment the cursor keeps changing colours as if animated for the cursor is enabled.
    The code is in a "oGame" object which controls the game and is inside the "Room Start" event. You can see here that I have set the image_speed to 0 and also in my sprite the image speed is 0.
    Someone please help, it is probably something really simple that I mussed.
     
  2. IndianaBones

    IndianaBones Member

    Joined:
    Jul 5, 2016
    Posts:
    2,048
    sCursor is a sprite, you can only use with on instances.
     
  3. Mick

    Mick Member

    Joined:
    Jun 30, 2016
    Posts:
    699
    What @IndianaBones said and also you can't control the image_speed o rimage_index of cursor_sprite. You could instead make a oMouse object and set x and y to mouse_x and mouse_y in the begin step event. Then your code would be:

    Code:
    if (room != rMenu) and (room != rControls) and (room != rUpdatesAndNotes) and (room != rShop) and (room != rEnding) and (room != rCredits)
    {
        with(oMouse)
            sprite_index = other.sCursorGun;
    }
    else
    {
        with (oMouse)
        {
            sprite_index = other.sCursorGun;
            image_speed = 0;
            image_index = (choose(0,1,2,3,4,5,6,7,8,9));
        }
    }
    
    You will need to have an instance of oMouse in all your rooms or have it set as a persistent object and create an instance at the start of the game.
     
    Last edited: Apr 17, 2019 at 12:28 PM
  4. Joshua Hotchin

    Joshua Hotchin Member

    Joined:
    Jan 19, 2017
    Posts:
    39
    I fixed it by doing:

    cursor_sprite = choose(1,2,3,4,5)

    And just made the sprites individual.
     

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