Jump to content


Photo

Change sprite when mouse is on [SOLVED]


  • Please log in to reply
5 replies to this topic

#1 tomudzjeris

tomudzjeris

    GMC Member

  • GMC Member
  • 123 posts

Posted 22 October 2011 - 10:15 AM

Hello,

In all rooms there are some buttons. If I move my mouse on one of them, it changes to a larger button. When I press on that larger button, it goes to a different room. If in that room a button is created under my mouse, this button doesn't change to the larger button. How can I prevent this and tell the button, if the mouse is already on it, then change to the larger button?

Thanks :)

Edited by tomudzjeris, 24 October 2011 - 11:28 AM.

  • 0

#2 Mr B

Mr B

    GMC Member

  • GMC Member
  • 172 posts

Posted 22 October 2011 - 10:41 AM

I do not think there is an easy solution to your loading problem. You will have to make an ini file upon saving.

The button issue is easy to fix. Do not use the enter and leave events; use: if place_meeting(mouse_x,mouse_y,self).
  • 1

#3 tomudzjeris

tomudzjeris

    GMC Member

  • GMC Member
  • 123 posts

Posted 22 October 2011 - 11:35 AM

Thanks for answer. Well, making my own save system complicates everything... how can I save all instance x and y coordinates and load them?
Tried your button solution, but it doesn't seem to work:
//Step event
if place_meeting(mouse_x,mouse_y,self)
{
    sprite_index = spr_button_on;
}
else
{
    sprite_index = spr_button;
}

  • 0

#4 Mr B

Mr B

    GMC Member

  • GMC Member
  • 172 posts

Posted 22 October 2011 - 11:45 AM

Well it should work somewhat, but I made a mistake. It is position_meeting of course. The rest of your code is good.
  • 1

#5 tomudzjeris

tomudzjeris

    GMC Member

  • GMC Member
  • 123 posts

Posted 22 October 2011 - 11:53 AM

Thanks, buttons are now changing correctly. :)
Only problem is, that I need to overwrite all my 30 buttons to use this feature.
  • 0

#6 tomudzjeris

tomudzjeris

    GMC Member

  • GMC Member
  • 123 posts

Posted 24 October 2011 - 10:40 AM

Hi, again!

This solution for my button problem worked well, till I wanted to add a sound effect when changing sprite. It causes the sound to loop for ever:
//This code now works as I needed
if position_meeting(mouse_x,mouse_y,self)
{
    
    sprite_index = spr_on_on;
    if global.sound = 1 
    {
        if allow_sound = 1
        {
            sound_play(global.snd_on);
            allow_sound = 0;
        }
    }
}
else
{
    sprite_index = spr_on;
    if global.sound = 1 
    {
        if allow_sound = 0
        {
            sound_play(global.snd_on);
            allow_sound = 1;
        }
    }
}
}

What can I do to prevent the sound from looping?

EDIT: Well, never mind, I already figured out what I needed, just added new variable allow_sound = 1...

Edited by tomudzjeris, 24 October 2011 - 11:27 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users