简体   繁体   English

如何使用 OCaml 中的图形库移动图像?

[英]How to move an image using the Graphics lib in OCaml?

I'm programming in OCaml, and I use the Graphics library for the visualisation and Camlimages.我在 OCaml 中编程,我使用图形库进行可视化和 Camlimages。

I have a moving element in the game, I would like to attach an image to it, the element have an x and y coordinates.我在游戏中有一个移动元素,我想给它附上一张图片,该元素有一个xy坐标。

In the game loop, I have a function called display which displays on the screen the different elements of the game.在游戏循环中,我有一个名为display的函数,它在屏幕上显示游戏的不同元素。

What I've done so far is including this in the display function of the element:到目前为止我所做的是将其包含在元素的display功能中:

Graphic_image.draw_image image (t_x (x_ pos -. 20.)) (t_y (y_ pos -. 7.))

However my problem here is that the image is being duplicated at each frame.但是我的问题是图像在每一帧都被复制了。

My goal is to be able to avoid the duplication of the image at each frame or be able to move it.我的目标是能够避免在每一帧复制图像或能够移动它。

How could I do that?我怎么能那样做?

Thanks.谢谢。

Putting clear_graph at the beginning of your main render function should be sufficient.clear_graph放在主渲染函数的开头就足够了。 Can you provide a more complete outline of what's going on in that?您能否更完整地概述其中发生的事情?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM