Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

需求:相机摇晃 #4

Open
dingjibang opened this issue Jan 15, 2016 · 2 comments
Open

需求:相机摇晃 #4

dingjibang opened this issue Jan 15, 2016 · 2 comments

Comments

@dingjibang
Copy link
Owner

需求要求完成时间:
image

需求简述:
在脚本添加一个命令,来让画面变得像是地震了一样的晃动

script命令
shaking (int time, int strong, ShakeType type)
time 摇晃帧数,如果为 -1 则无限
strong 摇晃强度,0最小,最大随便233
type 见附录

tip:
com.rpsg.rpg.system.controller.MoveController 下面的代码是管相机的,里面有两个actor(buffer和offset),buffer是管“平滑移动”的,offset是“移动相机”的,他俩是不冲突的,也就是你移动相机时候顺便行走也不会有问题image,也就是说现在要再来个actor来做这个摇晃效果,三个actor代码变得略鹅心了23333

附:
ShakeType : enum {
leftRight,//左右摇晃
topBottom,//上下摇晃
random,//瞎激霸摇
}

@Lchaos @HUIZHANGSAMA

@ttwings
Copy link

ttwings commented Oct 4, 2017

最后是怎么实现的? 大神,贴段代码学习一下。

@dingjibang
Copy link
Owner Author

@ttwings 最后没有(人)实现呢,这只是个简单的课题一样的需求,实现还是很好实现的,用打字介绍下吧

假设相机的坐标一直对着玩家,对着屏幕中心。这时玩家走路就会产生玩家不动,地图在卷动的效果,也就是典型的RPG效果,假设这里已经实现了。

我们把这个相机的当前坐标设为x, y,在GDX-RPG里,用了一个投机取巧的办法来实现了画面晃动,就是创建一个空白的Actor,当我们给这个Actor创建一个Action,比如
actor.addAction(Actions.forever(Actions.sequence(Actions.moveTo(-100, 0, 1), Actions.moveTo(100, 0, 1)))

上边的actions就是创建一个无限循环,让这个actor每隔1秒左右移动。

最后,我们在渲染函数里,将相机的坐标设置为 (x + actor.getX(), y),就可以让相机来产生晃动效果了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants