User Tools

Site Tools


script_visual_stop_points

====== About the script ====== * Purpose : Allows to create layouts with forbidden places in a visual way, instead of using stop points. * Author : [[https://plus.google.com/u/1/105066926163073195690|TrianguloY]] * Link: https://plus.google.com/u/1/105066926163073195690/posts/NUL5JkuDWVs (with video with instructions) ====== How to use the script ====== This script is a way to implement the idea of forbidden places with a relatively very short script that has limitations and very specific instructions that you must follow, but if you follow them (and they are not so strange) it should work correctly. It can be also a start point in case someone want to improve it and make it more 'universal' The instructions are: Set the script to run in the position change event of a container. Place items that will be the 'prohibited' zones (in the video the red ones) that need to have those properties: Properties of the barrier items: Label set to "barrier" (this can be changed from script if necessary). Scale set to 1,1 and skew and rotation to 0. [Note that it is not necessary to have a red background, but it helps visualizing]. Caveats: If you enable diagonal scrolling it won't slide when touching a barrier, it will simply stop. Consider not using diagonal scrolling. If you enter exit edit mode while a barrier is on view it will jump to the previous saved position, or not move at all if there is no saved one. Consider exiting edit mode always in a 'valid' position. If there are a lot of items in the container it may lag. With seamless mode it won't necessarily work as expected. Consider duplicating the barriers yourself if necessary. Improvements that can be made (for scripters) Save the barrier's rects instead of calculating them each time. Slide instead of stopping when diagonal scrolling is on. Use also the scale of barriers and maybe even rotation and skew. Make it valid with seamless mode. ====== Script code ====== <sxh javascript> var NAME="barrier"; var cont = LL.getEvent().getContainer(); var script=LL.getCurrentScript(); //container rect var contrect=[cont.getPositionX(),cont.getPositionY(),cont.getPositionX()+cont.getWidth()/cont.getPositionScale(),cont.getPositionY()+cont.getHeight()/cont.getPositionScale()]; //barriers var barriers=[]; var items=cont.getItems(); for(var t=0;t<items.getLength();++t){ var item=items.getAt(t); if(item.getLabel()==NAME) barriers.push([item.getPositionX(),item.getPositionY(),item.getPositionX()+item.getWidth(),item.getPositionY()+item.getHeight()]); } //check if collide if(collide(contrect,barriers)){ var prev=script.getTag(); if(prev!=null){ prev=prev.split(" "); cont.setPosition(prev[0],prev[1],prev[2],false); cont.cancelFling(); } }else{ script.setTag([cont.getPositionX(),cont.getPositionY(),cont.getPositionScale()].join(" ")); } function collide(a,bList){ for(var t=0;t<bList.length;++t){ var b=bList[t]; if( a[0]>=b[2] || a[1]>=b[3] || b[0]>=a[2] || b[1]>=a[3] ) continue; return true; } return false; } </sxh>

script_visual_stop_points.txt · Last modified: 2016/02/21 18:13 by trianguloy