简体   繁体   English

限制游戏制造者的阻力

[英]Limit drag in gamemaker

Hello I am trying to limit how much a user can drag within Gamemaker. 您好我试图限制用户可以在Gamemaker中拖动多少。

I have created two views within a room. 我在一个房间里创建了两个视图。 The first view is the full room width and size 1250x768 The second view is the area which i would like the user to be able to zoom into and drag which is 955x465. 第一个视图是整个房间的宽度和大小1250x768第二个视图是我希望用户能够放大和拖动的区域,即955x465。 x and y position is 40 by 170. x和y位置是40乘170。

Currently i have set up the zoom for the second view which is: 目前我已经为第二个视图设置了缩放,即:

vmx=(mouse_x-X)-omx;
omx=(mouse_x-X);
vmy=(mouse_y-Y)-omy;
omy=(mouse_y-Y);

if mouse_wheel_up() && view_wview[1] > 600 {
    center_of_space_x=view_xview[1]+view_wview[1]/2;
    center_of_space_y=view_yview[1]+view_hview[1]/2;
    view_wview[1]-=view_wview[1]*0.15;
    view_hview[1]-=view_hview[1]*0.15;
    view_xview[1]=center_of_space_x-view_wview[1]/2;
    view_yview[1]=center_of_space_y-view_hview[1]/2;


}
if mouse_wheel_down(){
    view_xview[1] = 40;
    view_yview[1] = 170;
    view_wview[1] = 955;
    view_hview[1] = 465;}

Below is the code for the drag: 下面是拖动的代码:

if (mouse_check_button_pressed(mb_left)) {
    drag_x = mouse_x
    drag_y = mouse_y
}
// update:
if (mouse_check_button(mb_left)) && view_wview[1] < 700 {
    // actual dragging logic:
    view_xview[1] = drag_x - (mouse_x - view_xview[1])
    view_yview[1] = drag_y - (mouse_y - view_yview[1])
    // make sure view doesn't go outside the room:
    view_xview[1] = max(0, min(view_xview[1], room_width - view_wport[1]))
    view_yview[1] = max(0, min(view_yview[1], room_height - view_hview[1]))

So the limit works for the view to not leave the room but i want it not to leave the specific view which has been set up. 所以限制适用于视图不离开房间,但我希望它不要离开已经设置的特定视图。

Please help 请帮忙

I have modified my code to use a clamp function which works but it is not a clean solution: 我修改了我的代码以使用一个有效的钳位功能,但它不是一个干净的解决方案:

view_xview[1] = clamp(view_xview[1],40,400);
view_yview[1] = clamp(view_yview[1],170,500);

The user has to be fully zoomed in to have the view restricted. 用户必须完全放大才能限制视图。 If he is not then they can still see other areas of the room :( 如果他不是那么他们仍然可以看到房间的其他区域:(

EDIT: I may have misunderstood your question, I will leave the below code for reference if it helps you solve the problem a bit differently. 编辑:我可能误解了你的问题,我将留下以下代码作为参考,如果它可以帮助你解决问题有点不同。

I would probably check that mouse_x and mouse_y are not outside the view you want. 我可能会检查mouse_x和mouse_y是否在你想要的视图之外。

if (mouse_x > view_limit_x || mouse_y > view_limit_y)
{
  return; // Or continue or break however your language of choice goes.
}

If you cannot do a return statement, wrapping your code in a reverse logic of above should work fine. 如果你不能做一个return语句,将代码包装在上面的反向逻辑中应该可以正常工作。

Old Post: 旧帖子:

I am not 100% familiar with game maker. 我不是100%熟悉游戏制作者。 I would implement something like this by skipping the drag logic every x frames. 我会通过每x帧跳过拖动逻辑来实现这样的东西。 Say you are updating at 60fps, and you want the drag to be 6 times slower, you just need to only update the logic 10 x per frame. 假设您以60fps更新,并且您希望拖动速度慢6倍,您只需要每帧更新10 x逻辑。

const int framesToSkip = 6;
int frameCount = 0;

update()
{

  // Will only call when framecount = 0, 6, 12, 18 etc.
  if (frameCount % framesToSkip == 0)
    {
      // Drag Logic.
    }


  frameCount++;
}

This way drag logic only occurs 1/6 the rate as before. 这样,拖动逻辑仅发生1/9速率。 You could also change this around to happen the first x amount of frames and then skip for the rest (but this may appear a bit choppy). 您也可以更改此值以发生前x个帧数,然后跳过其余部分(但这可能看起来有点不连贯)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM