使用Paper.js检测当前旋转 [英] Detecting current rotation with Paper.js
问题描述
我正在使用 Paper.js 制作小型游戏,
但我是无法找到Paperscript提供任何方式来获取我的项目组的当前轮换
。
I'm making a small shoot 'em up game with Paper.js, but I'm unable to find that Paperscript provides any way to get the current rotation of my group of items.
在下面的代码中,用Q和'旋转'circlegroup' E键应该影响WASD导航,沿着对象的鼻子当前指向的方向移动项目。我想我需要得到我的物品的当前旋转,以便
影响导航。 Paper.js是否提供了这样做的方法?
In the code beneath, rotating 'circlegroup' with Q and E keys, should affect the WASD navigation, moving the item in the direction that the 'nose' of the object is currently pointing at. I figure that I need to get the current rotation of my items in order to affect the navigation. Does Paper.js provide any way to do this?
bigcircle = new Path.Circle({
radius:10,
fillColor: 'grey',
position: (10, 20),
selected: true
});
smallcircle = new Path.Circle({
radius:5,
fillColor: 'black'
});
var circlecontainer = new Group({
children:[smallcircle, bigcircle],
position: view.center
});
var circlegroup = new Group({
children: [circlecontainer]
});
function onKeyDown(event) {
if(event.key == 'w') {
circlegroup.position.y -= 10;
}
if(event.key == 'a') {
circlegroup.position.x -= 10;
}
if(event.key == 's') {
circlegroup.position.y += 10;
}
if(event.key == 'd') {
circlegroup.position.x += 10;
}
if(event.key == 'q') {
// hold down
circlegroup.rotate(1);
}
if(event.key == 'e') {
// hold downw
circlegroup.rotate(-1);
}
}
推荐答案
否,每个对象没有存储旋转属性。您需要自己为每个对象或类定义它。看一下 Github存储库中包含的Paperoids游戏一个更详细的例子。
No, there's no rotation property stored per object. You'll need to define it per object or class yourself. Take a look at the Paperoids game included in the Github Repository for a more detailed example.
这篇关于使用Paper.js检测当前旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!