鸿蒙系统开发游戏,鸿蒙原生开发游戏----给鸿蒙引入一些游戏思想

鸿蒙有很多布局组件,但我们不需要他们的自适应布局,因为这只适合软件不适合游戏,所以布局最好只使用DependentLayout(相对布局),组件只使用Image当我们的精灵。

层级:

鸿蒙没有层级思想,只有先后加载,后加载的层级大于前面的层级。但有父子的思想。所以我们可以提前设置层级。比如下图这个意思

ohos:id="$+id:game_root"

ohos:width="match_parent"

ohos:height="match_parent">

ohos:id="$+id:layout1"

ohos:width="match_parent"

ohos:height="match_parent"/>

ohos:id="$+id:layout2"

ohos:width="match_parent"

ohos:height="match_parent"/>

这样通过不同的id层,加载不同层的Image(精灵),达到设置层级的目的

裁切:

裁切可以通过该不同的手段等,颜色混合也可以,但目前我还没在鸿蒙上使用颜色混合,所以通过“马赛克原理”,直接从图片本身下手,,直接从图片本身动手,我们对获取到的图片的像素码(图片保存在计算的真正的值)直接进行修改,直接获取到裁切过后的图片public static PixelMap getPixelMap(Context context, int picId, int minX, int minY, int width, int height) throws Exception {

String drawingPath = context.getResourceManager().getMediaPath(picId);

Resource a***t = context.getResourceManager().getRawFileEntry(drawingPath).openRawFile();

ImageSource source = ImageSource.create(a***t, getSrcOpts());

getDecodingOptions().desiredRegion = new Rect(minX, minY, width, height);

//        getDecodingOptions().desiredSize = new Size(width, height);

return source.createPixelmap(getDecodingOptions());

}

帧动画:

很简单,就是根据定时去换图,当然这个游戏必要的一部分,也是为了延伸下面的移动@Override

protected void onUpdate(double dt) {

apertureTime += dt;

if (apertureTime >= 50) { // 切到下一帧

apertureTime -= 50;

imageAperturep.setPixelMap(listAperturep.get(apertureIndex));

}

}

移动之贝塞尔:

通过起始点,终点,和控制点,,,计算出贝塞尔的轨迹集合,然后在通过帧动画一样的形式设置左边距和上边距,达到运动出贝塞尔的轨迹,,,(同理可以运动花里胡哨的轨迹,只不过要通过运算)// 贝尔曲线点集合

public static List> getBezier(int x1, int y1, int x2, int y2, int x3, int y3, float t){

List> positionList = new ArrayList<>();

int[][] keyPointP = new int[][]{

{x1,y1},

{x2,y2},

{x3,y3}

};

int x, y;

for (double k = t; k <= 1 + t; k += t) {

double r = 1 - k;

x = (int) (Math.pow(r, 2) * keyPointP[0][0]+ 2 * k * r * keyPointP[1][0] + Math.pow(k, 2) * keyPointP[2][0]);

y = (int) (Math.pow(r, 2) * keyPointP[0][1] + 2 * k * r * keyPointP[1][1] + Math.pow(k, 2) * keyPointP[2][1]);

Map position = new HashMap<>();

position.put("x",x);

position.put("y",y);

positionList.add(position);

}

return positionList;

}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值