Complex background images for Java2D applications - java-2d

I am developing a (card) game and for the background I need something fancy. On my research I found Microsoft's Solitaire game with this really nice green background, which tries to imitate a card table. Actually it does this really well.
So my question is, how to replicate this in Java2D with minimum resources.

You can use a background image to accomplish this effect. You can draw it just like a shape using:
Graphics.drawImage(Image img, int x, int y, ImageObserver observer)
If you dont have the resources for this, concider using a texture that you can tile.

Related

Animating OpenGL content within a Cocoa OSX Application

I am currently attempting to create an interactive, informative poster, with regards to Anti-Aliasing techniques and effects. The application is written in Obj-C within Xcode, and makes use of OpenGL and Cocoa functionalities.
I am attempting to create a small animation to display the difficulties of drawing a diagonal line on a pixel grid, however am having real trouble getting my head around the animation aspect.
I am aiming for something with a similar look and feel to this:
I have currently drawn a grid using OpenGL primitives:
,
and would like the effect above to be replicated within my grid, however without the shading yet (that is the next part), so just plain black pixels coloured step by step along the line.
I am new to both OpenGL and Obj-C, so am unsure whether best to implement the animation within OpenGL, or using OSx Core Animation - neither of which I have used before.
The OpenGL drawing takes place within my MyOpenGLView class, with the drawing done in a drawAnObject method, which is then called within the drawRect method.
Any help would be much appreciated, thanks in advance!

UI on Android Game - What are my options?

First of all let me give a bit of context to make the question more precise:
I am developing an Android game (using SurfaceView, Canvas, etc), and it is working perfectly for the gameplay part. I initially tried to use View-derived elements on top of it for menus and other UI elements, and rapidly realized by experimentation and looking at some questions here on Stackoverflow that this was a really bad idea, since they dont mix well (say a LinearLayout on top of a SurfaceView).
I see 3 possible paths:
A) Continue using View elements on top of SurfaceView (and deal with the problems with it, such as horrendous lag)
B) Draw UI elements manually on SurfaceView/Canvas. Something like: canvas.drawBitmap(menuBitmap, posX, posY, ...); and then handle the touches manually, and suffer with screen fragmentation
C) Use a library/framework designed specifically for this that handles all the drawing of UI, touch on buttons, drag to scroll, etc. Something like the View and its derived elements, but designed for games and apps that draw using SurfaceView.
Are there more options that Im not seeing? And "C" seems the best to me, but is there a library for that? Which one?
Edit: forgot to ask the most obvious question, also: How does other professional/commercial games deal with this?
Thanks
I really don't like these game engines (AndEngine, Corona, Unity3D, cocos2d, etc). I want to learn Android, which will be more useful for my professional life than engine X or Y.
All my games were created without game engines. I use option (A) for almost everything and I don't see any lag or sluggishness.
Examples:
The game screen for Minesweeper 3D is a set of layouts and views plus a SurfaceView to hold the OpenGL 3D field.
The game screen for Box Topple is also a set of layouts and views together with a custom view created to handle and display the box2d physics engine.
See my other games as well...
I had these same exact issues.
Then I found a free game engine called AndEngine.
This engine handles just about everything you need.
For example:
OpenGL wrapper classes for simple, efficient drawing
Sprite classes (animated or not)
Particle effects
Cameras to view different parts of the scene you draw on
Scrolling backgrounds
Online multiplayer and Box2D physics engine extensions
etc.
And for your case:
It has a HUD that you attach to a camera, which stays static as the camera moves.
You can then attach buttons (already built-in, with click events) to this.
Here is some example code to create a button:
moveRightButton = new ButtonSprite(10, 10, moveRightButtonTexture, getVertexBufferObjectManager()) {
#Override
public boolean onAreaTouched(TouchEvent event, float x, float y) {
if (event.isActionDown()) {
player.moveRight();
// Set to 'clicked' image
this.setCurrentTileIndex(1);
}
else if (event.isActionUp()) {
// Set to 'unclicked' image
this.setCurrentTileIndex(0);
}
return super.onAreaTouched(event, x, y);
};
};
You can find the engine and its extensions at https://github.com/nicolasgramlich?tab=repositories.
The main problem with the engine is that there is no documentation.
However, there is a forum dedicated to the engine at http://www.andengine.org/forums/.
Also, you can download AndEngine Examples (via the same repository I mentioned above), created by the developer to give examples of usages of various aspects of the engine.
It takes a bit to get used to, but it has been very rewarding.

Cocos2d on iOS: 2d billiard zooming

I want to make a pool game where the user can pinch the pool table to zoom so he can
precisely shoot the pocket.
So, this means I need a large pool table graphic.
What is the best way to handle such a situation in cocos2d?
How do I load the graphic? What is the limitation on graphic size?
I have a lot of doubts because Im not sure which path to take.
Regards
Mirza
For something as simple as a pool table it might be better to render it all using vector graphics. This means you will need less graphics (perhaps only a few for textures) and you get infinite zooming without all the graphic image overhead.

Objective-C, Methods for animating gui

I've created many types of interfaces using the Cocoa API — some of them using documented basic animation techniques and others simply by experimenting (such as placing an animated .gif inside an NSImage class) — which had somewhat catastrophic consequences. The question I have is what is the correct or the most effective way to create an animated and dynamic GUI so that it runs optimally and properly?
The closest example I can think of that would use a similar type of animation would be something one might see done in flash on any number of interactive websites or interfaces. I'm sure flash can be used in a Cocoa app, although if there is a way to achieve a similar result without re-inventing the wheel, or having to use 3rd party SDKs, I would love to get some input. Keep in mind I'm not just thinking of animation for games, iOS, etc. — I'm most interested in an animated GUI for Mac OS X, and making it 'flow' as one might interact in it.
If u wish to add many graphics animations, then go for OpenGLES based xcode project for iOS. That helps u to reduce performance problem. You can render each of the frames in gif as 2D texture.
I would recommend that you take a look at Core Animation. It is Apples framework for hardware accelerated animations for both OS X and iOS. It's built for making animated GUIs.
You can animate the property changes for things like position, opacity, color, transforms etc and also animate gradients with CAGradientLayer and animate non-rectagunal shapes using CAShapeLayer and a lot of other things.
A good resource to get you started is the Core Animation Programming Guide.

how to create a bubbles game UI in android

I want to create a bubbles like game in android and I'm not sure how to draw the graphics.
Should I use canvas ? Every bubble should be a bitmap or maybe an image view ?
Another thing, I want to be able to rotate / scale the bubbles.
I've tried with bitmaps and canvas but wasn't able to rotate the bubbles.
Image view for every bubble looks like a mess to me.
Your help is appreciated.
Thanks
If you want to make a game, I would suggest using a Canvas, and put the Canvas over most, or all, of your layout. Creating anything but the most basic game using the regular UI structures would be a nightmare.
It sounds like you've gotten to the point where you can load the bubble images and draw them to the canvas, which is good. As for rotating the bubbles, use this:
Matrix rotator = new Matrix();
rotator.postRotate(90);
canvas.drawBitmap(bitmap, rotator, paint);
That was from an answer to this SO question, which was more specifically about rotating bitmaps on a Canvas.
For more information on making games in Android, this book was pretty helpful for me.
Hope that helps!