Resizing a Texture

36 просмотров
Перейти к первому непрочитанному сообщению

JF

не прочитано,
2 июл. 2014 г., 20:52:3702.07.2014
– replica-island-...@googlegroups.com
In the class "GameObjectFactory", the "preloadEffects()" method includes the line:

textureLibrary.allocateTexture(R.drawable.effect_smoke_small01);

Later on, another method uses the texture:

public GameObject spawnEffectSmokeSmall(float positionX, float positionY) {...
....
                SpriteAnimation idle = new SpriteAnimation(0, 1);
                idle.addFrame(new AnimationFrame(
                        textureLibrary.getTextureByResource(R.drawable.effect_smoke_small01),
                Utils.framesToTime(24, 17), null, null));


I've tried numerous times to change the size of this texture, but with no luck.
Why do I want to change the size?  Because the standard PNG file isn't high enough resolution to look sharp in the game. So i made a bigger image and now want to resize it back down. This technique works for bitmaps (I simply make a bigger PNG, and then resize the bitmap back down, but i can't figure it out for a texture (or how to convert to a bitmap and back to texture successfully). 

I can add more details to this question later on, but if anyone has thoughts, let me know.

Thanks!
Joe

Chris Pruett

не прочитано,
3 июл. 2014 г., 01:08:1503.07.2014
– replica-island-...@googlegroups.com
Joe, what size are you trying to change it to?  Remember that whatever size you pick, you’ll need to maintain power-of-two dimensions.

Chris

--
You received this message because you are subscribed to the Google Groups "ReplicaIsland Coding Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to replica-island-coding...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

JF

не прочитано,
3 июл. 2014 г., 18:32:2503.07.2014
– replica-island-...@googlegroups.com
Hey Chris!
I'm trying to reduce it by 50%. (From 64x64, to 32x32). With that said, while I was trying different techniques I totally neglected to keep the power-of-two and actually may have at some point had a solution that would have worked.


Just to recap: the original picture PNG is actually 64x64, and i need the 64x64 to keep my picture detailed.  But 64x64 makes the picture too large relative to the reset of the game (characters, etc), so I'd like to resize it down on screen.


I'm doing so with my drawable bitmap HUD digits by adding the code in red (after making the PNG larger):

        for (int x = 0; x < digits.length && digits[x] != -1; x++) {
            int index = digits[x];
            DrawableBitmap digit = mDigitDrawables[index];
            Texture tex = digit.getTexture();
            digit.setWidth((int)(tex.width * .3));
            digit.setHeight((int)(tex.height * .3)); 



But since R.drawable.effect_smoke_small01 never becomes a DrawableBitmap, the solution isn't as obvious :-\. 

Thanks again!
Joe
To unsubscribe from this group and stop receiving emails from it, send an email to replica-island-coding-community+unsubscribe@googlegroups.com.

vecima

не прочитано,
30 окт. 2014 г., 09:50:1430.10.2014
– replica-island-...@googlegroups.com
Joe,

Did you ever figure this out?
I'll be looking at this same thing tonight, so if I figure something out, I'll post again.

vecima

не прочитано,
5 нояб. 2014 г., 23:18:2005.11.2014
– replica-island-...@googlegroups.com
So I've tried a few things unfortunately with no success.  I'm specifically trying to render a character whose GameObject size is 64 X 64 with a texture that is 128 X 128. What I see is the top left 1/4 of the image (the top left 64X64). I tried playing with the texture size, as well as adding a call to bitmap.setCrop(etc) to the SpriteComponent update method, but that had no effect, even with differing numbers.

I don't yet understand how the textures are mapped onto the drawable area.  I'll keep digging, but in the meantime has anyone had any success on this?

Chris Pruett

не прочитано,
6 нояб. 2014 г., 01:17:4906.11.2014
– replica-island-...@googlegroups.com
Sorry for the slow response here.

I don’t perfectly remember how this works, but I think the bitmap code (which calls into grid.java) expects to map the sprite to the size of the quad unless a different crop is set.  There shouldn’t be any reason that the actual size must match, though.  DrawableBitmap.draw() takes scale factors, which should change the size of the sprite without changing the size of the image it’s coming from.

Chris

On Nov 5, 2014, at 8:18 PM, vecima <veci...@gmail.com> wrote:

So I've tried a few things unfortunately with no success.  I'm specifically trying to render a character whose GameObject size is 64 X 64 with a texture that is 128 X 128. What I see is the top left 1/4 of the image (the top left 64X64). I tried playing with the texture size, as well as adding a call to bitmap.setCrop(etc) to the SpriteComponent update method, but that had no effect, even with differing numbers.

I don't yet understand how the textures are mapped onto the drawable area.  I'll keep digging, but in the meantime has anyone had any success on this?

--
You received this message because you are subscribed to the Google Groups "ReplicaIsland Coding Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to replica-island-coding...@googlegroups.com.

vecima

не прочитано,
12 нояб. 2014 г., 21:46:4212.11.2014
– replica-island-...@googlegroups.com
So, I got this accomplished in the following manner.

In SpriteComponent.update, where the DrawableBitmap is allocated and setup, I moved the line to set the Texture on the DrawableBitmap to before the call to setFlip.
I updated DrawableBitmap.setFlip to look like this:

public final void setFlip(boolean horzFlip, boolean vertFlip)
{
if (this.mTexture != null)
{
setCrop(horzFlip ? this.mTexture.width : 0,
vertFlip ? 0 : this.mTexture.height, 
horzFlip ? -this.mTexture.width : this.mTexture.width,
vertFlip ? -this.mTexture.height : this.mTexture.height);
}
else
{
 setCrop(horzFlip ? mWidth : 0,
vertFlip ? 0 : mHeight,
horzFlip ? -mWidth : mWidth,
vertFlip ? -mHeight : mHeight);
}
}

If the texture is available on the DrawableBitmap, it uses the texture dimensions to do the crop.  This is why I moved the line in SpriteComponent.

To unsubscribe from this group and stop receiving emails from it, send an email to replica-island-coding-community+unsubscribe@googlegroups.com.
Ответить всем
Отправить сообщение автору
Переслать
0 новых сообщений