[英]Selecting rectangle / making it move
Relevant code: 相关代码:
if (pic2 == true) {
image(imgs[1],50,375);
} else {
image(imgs[1],50,375);
fill(255);
rect(tboxPos,375,picWidth,picHeight);
fill(0);
textAlign(LEFT);
text("text box 2...",420,395);
}
I'm using processing 2.2 and just added following library: http://benedikt-gross.de/libraries/Ani/ 我使用的是2.2处理程序,只是添加了以下库: http : //benedikt-gross.de/libraries/Ani/
I want to use this for some kind of animation(my "rect" should slide from one side to the other. Ani seems to provide an easy solution to this, however I need to specify the "rect", so it doesn't select the image or text. Can this be done, by using Ani.to(this, ......), or do I have to specify it in another way? 我想将其用于某种动画(我的“ rect”应该从一侧滑到另一侧。Ani似乎为此提供了一种简单的解决方案,但是我需要指定“ rect”,因此它没有选择图片或文字。可以通过使用Ani.to(this,......)来完成此操作,还是必须以其他方式指定它?
I have to do this with several rectangles as well. 我也必须用几个矩形来做。
Thank you in advance. 先感谢您。
Step one : Store whatever you want to move in variables. 第一步 :将要移动的任何内容存储在变量中。 For a rectangle, that's probably just the x
and y
values, and maybe the width
and height
: 对于矩形,可能只是x
和y
值,以及width
和height
:
float rectX = 25;
float rectY = 50;
float rectWidth = 10;
float rectHeight = 20;
Step two : Use those variables to draw your rect: 第二步 :使用这些变量绘制矩形:
void draw(){
background(0);
rect(rectX, rectY, rectWidth, rectHeight);
}
Step three: Modify those variables to move your rect. 第三步:修改这些变量以移动矩形。 You could use the Ani library to do that: 您可以使用Ani库执行此操作:
void setup(){
Ani.init(this);
}
void mouseReleased(){
Ani.to(this, 1.5, "rectX", mouseX);
Ani.to(this, 1.5, "rectY", mouseY);
}
Note that there are many other ways to animate stuff, and you should probably get a better grasp of the basics before you try using a library like Ani. 请注意,还有许多其他方法可以对内容进行动画处理,并且在尝试使用诸如Ani之类的库之前,您可能应该更好地掌握基础知识。 Here is a tutorial that I wrote on basic animation in Processing. 这是我在《处理》中有关基本动画的教程。
Step four : Repeat those steps for whatever other objects you want to animate. 第四步 :对要设置动画的其他对象重复这些步骤。 An image will be similar to a rectangle. 图像将类似于矩形。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.