简体   繁体   English

J2ME游戏画布

[英]J2ME Game Canvas

In J2ME, only a screen or a canvas can be displayed at a time. 在J2ME中,一次只能显示一个屏幕或画布。 The screen can have multiple objects inside it (textfield, form, etc.) while a canvas can only hold a gamecanvas. 屏幕内部可以有多个对象(文本字段,表单等),而画布只能容纳游戏扫描。

The question is: Is it possible to have multiple game canvases in one canvas? 问题是:是否可以在一个画布中放置多个游戏画布? I'm trying to display two at the same time, one at the top and one at the bottom. 我试图同时显示两个,一个在顶部,一个在底部。 I'd like to repaint the bottom canvas without repainting the top. 我想要重新粉刷底部画布而不重新涂抹顶部。

Thank you in advance! 先感谢您! Any form of help will be appreciated! 任何形式的帮助将不胜感激! :) :)

No, you can only display one Canvas or GameCanvas object at a time. 不,您一次只能显示一个Canvas或GameCanvas对象。

But: If you're asking about having 2 Canvas objects, because you need to update 2 parts of the screen independent of each other, you can do that by using 2 Image objects. 但是:如果您要求有两个Canvas对象,因为您需要彼此独立地更新屏幕的两个部分,您可以使用2个Image对象来完成。

Simply get the Graphics object of each Image with Image.getGraphics(); 只需使用Image.getGraphics()获取每个Image的Graphics对象; Then you can draw onto each image. 然后你可以绘制到每个图像上。 And finally draw both images on the canvas (or just one of them, if you only want to update one part of the screen). 最后在画布上绘制两个图像(或者只是其中一个,如果您只想更新屏幕的一部分)。

Example using GameCanvas: 使用GameCanvas的示例:

Image topImage = Image.createImage(width, height);
Image bottomImage = Image.createImage(width, height);
Graphics topG = topImage.getGraphics();
Graphics bottomG = bottomImage.getGraphics();
Graphics g = getGraphics(); // Get graphics of the GameCanvas

drawStuffOn-topG();
drawStuffOn-bottomG();

g.drawImage(topImage, 0, 0, g.TOP|g.LEFT);
g.drawImage(bottomImage, 0, halfScreenHeight, g.TOP|g.LEFT);

flushGraphics();

不,您只使用一个画布,但只重绘已更改的位

Canvas.repaint(int x, int y, int w, int h);

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

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