看博客学学Android(八)

原为地址:

http://bigosaur.com/blog/7-first-aliens-screen-orientation-android

Day 6: First aliens and screen orientation

OK, I got some really retro aliens, and they are flying around. Sorry for no demo, it's an Android game, all I got is .apk and you probably wouldn't want to install .apk from a complete stranger. Basically, the background loads, and stars load, and stars slowly move. To scroll the stars I'm using setV() and setV2() on the stars texture, slowly increasing the timer. Like this:

    scrollTimer -= delta*0.014;
    if (scrollTimer < 0.0f)
        scrollTimer = 1.0f;
    sStars.setV(scrollTimer);
    sStars.setV2(scrollTimer+1);

And then some aliens show up and they move to the right. That's about all that works now. I'm still learning libGDX, so a lot of time goes into googling and reading tutorials or watching videos.

Helpful tip: I noticed that some games built with libGDX have fixed screen orientation. If you flip the device, the game shows upside-down. I found a very simple solution to this in some obscure comment in some SO thread. Just replace landscape with sensorLandscape in AndroidManifest.xml and device flips the screen automatically.

Setting up Eclipse for libGDX and Android

 

第六天:第一个外星人和屏幕方向

现在,我有了一个写真正古典的外星人,而且他们正在四周飞行。很遗憾没有一个Demo,这是一个安卓的游戏,所以呢,整体上是一个.apk文件,同时,你大概也不想去安装一个完全陌生的安卓软件。

总的来说,加载了背景,加载了星星,并且星星还在缓慢的移动着。为了让星星滚动,我在星星的构造上我使用了setV() 和setV2(),随着时间慢慢的增长。就想这样:

    scrollTimer -= delta*0.014;
    if (scrollTimer < 0.0f)
        scrollTimer = 1.0f;
    sStars.setV(scrollTimer);
    sStars.setV2(scrollTimer+1);

然后,一些外星人到来了,并且移动到了右边。这是就目前所有的工作了,我依旧还在学习libGDX,所以,会有大量的时间在谷歌和阅读资料或者看一些视频。

小贴士:我注意到一些使用libGDX创建的游戏固定了屏幕的方向。如果你将设备翻转,游戏将会变成颠倒的。在一些非常容易被忽视的线索以及同样容易被忽视的评论中,我找到一个非常简单的解决方案。只要在AndroidManifest.xml中将 landscape替换为 sensorLandscape,这样在翻转设备的时候屏幕也会自动的跟着翻转。

ps:在搜索setV这个方法的时候,居然无意中找到了http://www.importnew.com/author/importnewguest~ 另外一个在做同样事情的博客,开始日期居然也差不多~ 嘿嘿,莫非是同样看到了叔的推荐么~

转载于:https://www.cnblogs.com/NorthDrift/p/3405461.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值