In my game a player flys through space and has to avoid asteroids. Asteroids are just simple polygons which I draw using a Mesh class. For all the polygons I use just one Mesh class object and it works fine. To add a little variety to their looks I would like to use say 4 textures.
My question is, do I have to create different Mesh object for each texture or maybe there is a way to use just one Mesh class object? I read that it is best to use as little Mesh objects as possible to improve performance and since it is an Android game I certainly could use performance boost.
Inside draw method to bind one texture to a mesh I use this code:
mShaderProgram.begin();
mShaderProgram.setUniformMatrix("u_projTrans", mCamera.getCamera().combined);
Gdx.graphics.getGL20().glEnable(GL20.GL_TEXTURE_2D);
mTexture.bind();
mMesh.render(mShaderProgram, GL20.GL_TRIANGLES);
mShaderProgram.end();
Related
In my game I have some gold that the player can collect. My problem is I want to individually refernce textures of gold so i can take that particular instance of gold off the screen (player picked it up). How would I go about doing this as i am pretty sure you cannot do this with regular textures. Would i have to create a shape and fill it with the gold texture so I can delete that particualr gold piece? Thanks
I think you confuse Texture (which is basically a loaded image that you can draw) with game entities. Depending on how you implement your game, you can spawn multiple bodies (Box2D), actors (Scene2D) or your simple data containers (width, height, x, y) representing each coin and draw each one on the screen using the same texture. Actually, that's the preferred way to handle assets: you load images once and then simply reuse them for each sprite.
I suggest looking into the following classes:
Sprite (makes it easier to draw textures).
Image (allows to display simple images on Scene2D stage).
Box2DSprite (third party utility class that makes it easier to draw Box2D worlds).
This visualization is created using Away3D (Flash):
www.guardian.co.uk/world/interactive/2011/mar/22/middle-east-protest-interactive-timeline
Would it be possible to create something of the same quality (re. interaction, animation, performance, pixel-perfection etc.) using WebGL?
Bonus: How would one set up the basic scene? (without interaction and animation)
Yes, it would be. The scene is not complex at all, so it would have good performance. Interaction, yes, depends how you implement it, but if you are doing project with, for example, Three.js it wouldn't be a problem. Pixel perfection, obviously, yes.
In the scene, you could have curved plane, with texture that is changing UVs of vertices when you use 'navigate'. Pins could be done with particle, or better, simple quads with transparent textures. To have pixel-precise pin picking, you could depth-test pins on ray trace, or use pin-shaped geometry with shader, which probably the best solution.
So, basic scene - curved plane with per-vertex-changing-UV, pin-shaped and texture pins.
Alternatively, you could do exactly the same thing with 2D canvas. All elements are just drawn and scaled, text would be much simpler, and picking would be with 2d calculations.
Hope this helps.
let's say I have two shapes wrapped in Movieclip container. How can I detect if one shape is OVER another one? more precisely, whether one shape is covering a part/all of the other shape?
So far I've managed to do it by comparing coordinates of both shapes, but I'm wondering if there is some built-in function or an easier way to do it. Thanks
DisplayObject.hitTestObject(obj:DisplayObject):Boolean
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObject.html#hitTestObject()
If you need finer grain hit testing and are willing to work with BitmapData objects (you can draw a DisplayObject to BitmapData using BitmapData.draw(dispObj));
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html#hitTest()
Here are a couple ways you could do this:
flash.display.DisplayObject.hitTest()
or
flash.display.DisplayObject.getRect()
ex: sprite1.getRect(stage).intersects(sprite2.getRect(stage));
You can use hitTestObject http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObject.html#hitTestObject%28%29
trace(shape1.hitTestObject(shape2));
But keep in mind that this is a simplistic test if just the bounds of the objects overlap. If you want pixel-perfect collision testing you'll have to use some 3rd-party library such as http://www.freeactionscript.com/2011/08/as3-pixel-perfect-collision-detection/
Are there any libraries for animation groups of objects in as3?
I need something like this: for example, I specify an array of images and creates the animation of all objects in the array - fireworks, the spiral vortex, 3D rotation, undulating, etc. Tweenlite and other libraries not fit, because there is no pattern complex motion.
I need to quickly apply complex animation paths to the set of objects.
Particle systems, such as Flint Particles may be inline with what you are citing:
Flint Particle System
http://flintparticles.org/
Examples
http://flintparticles.org/examples/logo-firework
http://flintparticles.org/examples/firework
http://flintparticles.org/examples/firework-display-3d
http://flintparticles.org/examples/catherine-wheel
what would be your recommendation for drawing shapes (rects, circles...) onto BitmapData, and how to effectively switch between colors.
Is there any way to get graphics context from BitmapData so I could easily paint shapes using graphics.draw...()?
Why do you want to use a BitmapData? Not sure what you're after, but after reading a couple of your questions it seems you're a kind of fighting against how flash works. I think you'll make things much easier for yourself if you use what's available already. BitmapData objects are meant mainly to manipulate pixels and don't expose methods for drawing shapes. A Graphics object (available through Sprite, Shape, etc) on the other hand, allows you to draw vector shapes easily.
So, the best approach for this, I guess, would be using the drawing API to do what you want and then, if needed, convert the graphic to a BitmapData.