Home Help Search Login Register


J2meForums  |  General Category  |  Game programming (Moderators: mikkom, shendley)  |  Topic: Sprite3D « previous next »
Pages: [1] Print
Author

Sprite3D

 (Read 234 times)
prasad.madu
New user
*
Posts: 10



View Profile
Sprite3D
« on: July 27, 2010, 04:55:46 pm »

Dear all,

I have an image of a person. when I create it, I simply cut the person and insert it in to a transparent background. Now person is in the image and its surrounding is transparent. I converted it to 3D Sprite object. But when I render it to my 3D world, its transparent background is also rendered with shading color around (kind of deformation).

here is the code sample:

        Image2D texImage = null;
        Appearance myAppearance = new Appearance();
     
         texImage = (Image2D) Loader.load("/GameWorld/Umpire/umpair back .png")[0];
     
        sprite = new Sprite3D(true, texImage, myAppearance);     
        sprite.setCrop(0, 0, 64, 128);
       
        sprite.setTranslation(-0.6f, 0.65f, 0.0f);
        sprite.setScale(0.6f, 1.2f, 0f);
        sprite.setOrientation(90, 0f, 0.1f, 0f);
        sprite.postRotate(-270, 0.1f, 0f, 0f);
        groundWorld.addChild(sprite);

I render the world  in my game loop. But when I draw it as a sprite on top of a another image, transparency is there. What should I do? Pls help.
Logged
halfsfot
Full Member
***
Posts: 115



View Profile
Re: Sprite3D
« Reply #1 on: July 27, 2010, 05:33:08 pm »

upload a screenshot to see the problem
Logged

explanations - free
code example - paid
prasad.madu
New user
*
Posts: 10



View Profile
Re: Sprite3D
« Reply #2 on: July 28, 2010, 06:59:39 am »

Here is the screen shot. Surrounding of the umpire should be transparent to see the environment clearly. But see the deformation. Can i fix this through the code or what should i do? 

* err.jpg (21.4 KB - downloaded 27 times.)
Logged
halfsfot
Full Member
***
Posts: 115



View Profile
Re: Sprite3D
« Reply #3 on: July 28, 2010, 08:30:38 am »

I'm not sure why does this happen but try these:
Code:
                Appearance app = new Appearance();
                Texture2D tex = new Texture2D((Image2D)Loader.load(textureFilename)[0]);
                tex.setBlending(Texture2D.FUNC_REPLACE);//replace for faster drawing
                CompositingMode compMode = new CompositingMode();
                compMode.setBlending(CompositingMode.ALPHA);// set the texture to use the alpha component
                compMode.setAlphaThreshold(0.1f);
                app.setLayer(63);//draw the 2D billboards last so the transparency is not fucked up
                app.setCompositingMode(compMode);
Logged

explanations - free
code example - paid
prasad.madu
New user
*
Posts: 10



View Profile
Re: Sprite3D
« Reply #4 on: July 28, 2010, 09:04:31 am »

Yep,
But I changed code to this way

Appearance app = new Appearance();
            Image2D img = (Image2D) Loader.load("/GameWorld/Umpire/four.png")[0];
//            Texture2D tex = new Texture2D(img);
//            tex.setBlending(Texture2D.FUNC_MODULATE); //replace for faster drawing
            CompositingMode compMode = new CompositingMode();
            compMode.setBlending(CompositingMode.ALPHA); // set the texture to use the alpha component
            compMode.setAlphaThreshold(0.1f);
            app.setLayer(63); //draw the 2D billboards last so the transparency is not fucked up
            app.setCompositingMode(compMode);
//            app.setTexture(0, tex);
            sprite = new Sprite3D(true, img, app);
            sprite.setCrop(cropX, 0, img.getWidth(), img.getHeight());
            sprite.setTranslation(-0.4f, 0.65f, 0.0f);
            sprite.setScale(1.4f, 2.0f, 0f);
            groundWorld.addChild(sprite);

After commenting tex, it works fine with transparency. To get transparecy only needs compMode.setBlending(CompositingMode.ALPHA); When i used  tex.setBlending(Texture2D.FUNC_MODULATE); or another func, game world is not loading. But wht is dat setLayer(63) thing means. Anyhow my problem was solved. Now as no polygons there will not huge affect on performance. Thank You very much again Smiley. You are the best
Logged
halfsfot
Full Member
***
Posts: 115



View Profile
Re: Sprite3D
« Reply #5 on: July 28, 2010, 09:07:08 am »

the layer shows the order in which the objects are drawn in the scene - higher order objects are drawn last (this way the transparency will be correct)
Logged

explanations - free
code example - paid
prasad.madu
New user
*
Posts: 10



View Profile
Re: Sprite3D
« Reply #6 on: July 28, 2010, 02:50:44 pm »

3D sprites can't be rotated inverse like by inverting values of setScale method (to convert same image from right hand to left hand batsman) as I did in mesh objects and ball tends to less visible when it goes far from camera. how can i avoid that getting small thing when going far from camera and achieve first issue?
Logged
halfsfot
Full Member
***
Posts: 115



View Profile
Re: Sprite3D
« Reply #7 on: July 28, 2010, 03:19:31 pm »

you can mirror the image in code :
sprite3d.setCrop(int cropX, int cropY, int width, int height) but use negative width (width*=-1)

the sprite can be scaled or unscaled depending on how do you create it:
Sprite3D(true, texImage, myAppearance);      - scaled
Sprite3D(false, texImage, myAppearance);      - not scaled - will not become smaller when far
Logged

explanations - free
code example - paid
prasad.madu
New user
*
Posts: 10



View Profile
Re: Sprite3D
« Reply #8 on: July 28, 2010, 04:10:16 pm »

yep, You are correct. but when ball is thrown by the bowler it gets smaller and when it is moving towards to a fielder in phone ball is not shown. But in emulator it works fine. This happens when scaling is on. When it is off ball becomes large when it is moving out from the camera and in the view of fielding scene. I can't think the reason. Do you have any suggestions?
Logged
halfsfot
Full Member
***
Posts: 115



View Profile
Re: Sprite3D
« Reply #9 on: July 28, 2010, 04:17:53 pm »

if there is a difference between emulator and phone i can't help you, maybe it's a bug in the phone implementation
Logged

explanations - free
code example - paid
prasad.madu
New user
*
Posts: 10



View Profile
Re: Sprite3D
« Reply #10 on: July 28, 2010, 04:28:01 pm »

If so I have to use ball mesh for that coz it is ok in both emulator and phone. Thanks for your help so far. really admire it. Smiley
Logged
Pages: [1] Print 
J2meForums  |  General Category  |  Game programming (Moderators: mikkom, shendley)  |  Topic: Sprite3D « previous next »
Jump to:  


Login with username, password and session length

Powered by MySQL Powered by PHP J2meForums | Powered by SMF 1.0.8.
© 2001-2005, Lewis Media. All Rights Reserved.
Valid XHTML 1.0! Valid CSS!