render what's goes outside of the screen in 2d - java

how can I render whats right outside of the screen on the left side? Like in Super Mario Bros for example? I want to move clouds endless over the screen.
Here's an example of what I mean:
http://image-upload.de/file/nSzNhe/612a71bf0d.png

You simply create the entity with coordinates that are offscreen, and have a draw function that draws the entities, and when they move onscreen, they will be drawn. Might also want to make sure they get deleted once the go offscreen again though.

Related

Stage is bigger than the screen in LibGDX, how to fit it in the screen?

I'm developing a game in libGDX, and the levels in my grid contains a grid actor which contains mirrors inside (see my game). The problem is that the grid is too big and I want to be able to see all the stage.
I'm using an OrthographicCamera and an ExtendViewport.
I tried using frustrum (I don't really know what it is): I create four BoundingBox (left, right, top and down) which are placed out of the grid. I set the camera position to the middle of the grid actor and i make a loop zooming the camera until the boxes are in the frustrum, but I don't know if it is the best solution...
I think you want to use a FitViewport, which will make sure you don't 'spill' off the screen.
FYI, the frustum is used to determine depth of your camera- how far it can see. I agree that that won't help you in this situation.

Rotating Asteroids

I'm trying to make asteroids that spin in my 2D game.
Using the graphics class I am drawing an image I created onto the screen (the asteroid) and moving it across the screen.
My next step was to make it rotate however I am lost at to how to do this.
I was able to make it rotate when I was simply drawing a polygon by changing the vertices of the asteroid however there are no vertices when drawing images, only (x,y) and (length,width).
How can I rotate an image? Is there any inbuilt functionality that does it?
I'm not asking for someone to tell me exactly how to do this, I'm just looking for a push in the right direction as I am a bit lost.
Either use a AffineTransform or use Graphics#rotate. In either case, you should make a copy of the Graphics context first (Graphics#create) first, which will preserve the state of the original context. Just make sure you dispose of the copy when you're done (Graphics#dispose)
Something like this perhaps

How do I change/edit a drawn sprite?

I am working on a project that draws an ellipse centred at where the user clicks.
I need to make two buttons, + and -, which make the last ellipse drawn by the user rotate by 15 degrees.
I also need to make an undo button that removes the last ellipse the user drew.
Both of these tasks require reference to the last sprite drawn, so how would you refer to it? In other words, how would you change a drawn sprite?
The Momento Pattern is something you can use for this.

Calling a 3D cube drawing method more than once in JAVA?

I've drawn a 3D cube on an applet, it appeared fine, then I translated it to another coordinates and painted in again. So now I have both cubes on the applet.
But the second cube appeared distorted, How can I fix it???
I tried using a Buffered Image, it appeared fine, but in my project I'm not supposed to use it. Because at the end it's supposed to be animated all with translations and rotations. so using a Buffered Image would be useless here.
Any ideas?
for every frame, you have to draw the background, so the previously drawed gets deleted, and then draw the cube again.
However, If you wanna do more complicated 3d things, jME is a good, easy to understand 3d engine.

Understanding Android's Canvas.saveLayer(...)

I am hoping the saveLayer methods will allow me to do draw onto different "layers" and then once the drawing has finished, merge the layers with the canvas in whichever order i choose.
The obvious question is "why dont you just rearrange your drawing operations instead?" The answer is I can't:
I have a Path that I need to draw onto a Canvas. In the background/lowest z-index I want to draw the path closed and with a few additional points using a fill style. Then on top of that, I want to draw an outline of only the points that were originally in the Path.
Since I cannot undo the adding of points to the Path, my only choices are to clone the path, or to draw to a second layer which can later be placed on top of everything else.
saveLayer() seems to offer that functionality but it doesnt behave the way I was expecting. The basic flow of my operations is like this:
int overlay = canvas.saveLayer(...);
// drawing operations for my uppermost layer
...
int background = canvas.saveLayer(...);
// drawing operations for my background layer
...
// merge the offscreen background bitmap with the canvas:
canvas.restoreToCount(background);
// merge the offscreen overlay bitmap with the canvas:
canvas.restoreToCount(overlay);
When the code runs, the ordering of background and overlay have not changed at all; what gets drawn first is at the bottom and what gets drawn last is on top. Even stranger to me is that I can completely comment out both calls to restoreToCount() and nothing changes. According to the javadoc, nothing should be drawn to the canvas until a balancing restore() is invoked.
Obviously I am completely misunderstanding the function of this method. Can anybody help me to understand saveLayer's usage, or perhaps suggest an alternate way to layer my drawing operations?
Thx!
Nick
saveLayer() does not let you rearrange the layers in a random order. The only way to do it is to draw in offscreen bitmaps yourself. Note also that your view's parent will call save()/restore() around your onDraw() call, which will cause your layers to be composited.

Categories

Resources