flyinian
Member
I am currently making a scroll system with the mouse wheel and so far so good. However, I can't figure out how I can go about updating an instance's y position when it's created in the create event. I don't think I can move the instance to a step event or another since it's tied to variables in the create event. If I can get the instance's y position to update with the mouse wheel then I think I can do the rest of the scroll system.
The code is below.
Thanks.
The code is below.
button_y = 0;
scroll_amount = 20;
global.scroll_perc = 0;
bar_height = sprite_height;
active = false;
//instance_create_layer(x,y, "Instances", obj_slider2);
slider = obj_slider2;
//TopLimit = y - (sprite_height/2) + (image_xscale*75);
//BottomLimit = y + (sprite_height/2) - (image_xscale*75);
TopLimit = y - (sprite_height/2) + (image_xscale);
BottomLimit = y + (sprite_height/2) - (image_xscale);
a = instance_create_layer(x,y, "Instances", slider); //I want to update this instance's y position. I've tried, "a = instance_create_layer(x,y + button_y, "Instances", slider)".
a.image_xscale = image_xscale;
a.image_yscale = image_yscale;
a.BarLength = sprite_height;
a.TopLimit = TopLimit;
a.BottomLimit = BottomLimit;
a.y = TopLimit;
a.depth = depth - 1;
scroll_amount = 20;
global.scroll_perc = 0;
bar_height = sprite_height;
active = false;
//instance_create_layer(x,y, "Instances", obj_slider2);
slider = obj_slider2;
//TopLimit = y - (sprite_height/2) + (image_xscale*75);
//BottomLimit = y + (sprite_height/2) - (image_xscale*75);
TopLimit = y - (sprite_height/2) + (image_xscale);
BottomLimit = y + (sprite_height/2) - (image_xscale);
a = instance_create_layer(x,y, "Instances", slider); //I want to update this instance's y position. I've tried, "a = instance_create_layer(x,y + button_y, "Instances", slider)".
a.image_xscale = image_xscale;
a.image_yscale = image_yscale;
a.BarLength = sprite_height;
a.TopLimit = TopLimit;
a.BottomLimit = BottomLimit;
a.y = TopLimit;
a.depth = depth - 1;
/// @description Insert description here
global.scroll_perc = button_y/a.BarLength;
if active = false
{
if mouse_wheel_up()
{
if mouse_x < x
{
button_y -= scroll_amount;
}
}
if mouse_wheel_down()
{
if mouse_x < x
{
button_y += scroll_amount;
}
}
}
else if active = true
{
button_y = mouse_y - y;
}
button_y = clamp (button_y,0, a.BarLength);
global.scroll_perc = button_y/a.BarLength;
if active = false
{
if mouse_wheel_up()
{
if mouse_x < x
{
button_y -= scroll_amount;
}
}
if mouse_wheel_down()
{
if mouse_x < x
{
button_y += scroll_amount;
}
}
}
else if active = true
{
button_y = mouse_y - y;
}
button_y = clamp (button_y,0, a.BarLength);
draw_self();
//draw_sprite(spr_slider,0,x,y+button_y); //This code works with the scroll wheel but, majority of my code is coded for the instance and not for a draw event.
//draw_sprite(spr_slider,0,x,y+button_y); //This code works with the scroll wheel but, majority of my code is coded for the instance and not for a draw event.
Thanks.