Hello Guest

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - theremin

Pages: [1]
1
Support / Dynamically set tk2dCamera resolutionOverride in code
« on: November 24, 2012, 06:16:28 pm »
I haven't updated 2D Toolkit in a while, and I recently decided to update to 1.80 patch 3. I noticed that camera scaling (resolution override) seems to work quite differently now.

I used to handle camera scaling dynamically in code, and that worked really well for me, but my old script doesn't work anymore. This is the script that I used to put on my tk2dCamera object, in the Start() method:

Code: [Select]
tk2dCamera.inst.resolutionOverride = new tk2dCameraResolutionOverride[1];
tk2dCamera.inst.resolutionOverride[0] = new tk2dCameraResolutionOverride();
tk2dCamera.inst.resolutionOverride[0].width = Screen.width;
tk2dCamera.inst.resolutionOverride[0].height = Screen.height;

if (Screen.height >= 1280)
    tk2dCamera.inst.resolutionOverride[0].scale = 4f;
else if (Screen.height >= 640)
    tk2dCamera.inst.resolutionOverride[0].scale = 2f;
else
    tk2dCamera.inst.resolutionOverride[0].scale = 1f;

tk2dCamera.inst.UpdateCameraMatrix();

I'm not interested in using 2D Toolkit's new automatic scaling ? it doesn't allow me to fine tune my scaling enough, and I want pixel perfect scaling that's always a factor of 2 ? but, again, my old script isn't working anymore.

How can I manually set the resolutionOverride scale value with this new version of 2D Toolkit?

2
Support / Unity 4.0 and 2D Toolkit
« on: August 22, 2012, 05:08:52 pm »
I just got an e-mail from Unity Technologies today saying that the Unity 4.0 pre-order beta is officially available for download today. I'm not going to download it yet; I'm in no particular rush. But it did remind me that I've been curious about Unity 4.0 and 2D Toolkit. Will 2D Toolkit likely support Unity 4.0 at some point? And will Unity 3.x support continue?

3
I would like to be able to make a copy of my animated sprite's atlas texture and dynamically change the pixels in-memory at runtime, but I'm having trouble figuring out which of the sprite instance's texture(s) I have to change in code.

For example, take the following code:

Code: [Select]
var texture = (Texture2D)Instantiate(renderer.material.mainTexture);
renderer.material.mainTexture = texture;

var cols = texture.GetPixels();
for (var x = 0; x < cols.Length; x++)
{
if (cols[x].a > 0f)
{
cols[x] = Color.red;
}
}

texture.SetPixels(cols);
texture.Apply();

This code takes the texture and changes every visible pixel (alpha>0) to red. I put this code into a new MonoBehaviour script and attached it to my animated sprite GameObject.

If I put the code in the Start() method, it seems to do absolutely nothing (the sprite animates normally with its original texture, as defined in the editor). But if I put that code in the Update() method, I can see that the code partially works -- the sprite frames turn red, and flash quickly between red and their original colors. It seems as the code is "battling" against the 2D Toolkit code, which is constantly swapping back to the original texture.

How can I completely swap out the sprite atlas texture for a specific animated sprite without fighting against the 2D Toolkit code?

I've tried changing the texture as seen in the code above, and I've also tried changing the tk2dAnimatedSprite anim.collection.textures. Is there any way to tell a tk2dAnimatedSprite to use a completely different material/texture at runtime?

4
I was asking an unrelated question on the Unity Answers site, and I posted a snippet of the 2D Toolkit "BlendVertexColor" shader, and one of the commenters said the following:

Quote
You should tell whoever made 2D Toolkit that fixed function shaders aren't appropriate for mobile devices anymore! Fixed function emulation is a poor choice for mobile devices; it eats performance and battery.

http://gamedev.stackexchange.com/questions/16423/why-is-programmable-pipeline-glsl-faster-than-fixed-pipeline

I'm a shader novice, so I'm not sure exactly what he means by this. Can anyone explain what this means? What would be a better alternative for a shader?

5
Support / Get clip name in CompleteDelegate?
« on: June 02, 2012, 07:57:04 pm »
Is it possible to get the clip name (for the clip that's ending) in animationCompleteDelegate? Or, to ask it a different way: Is there an easy way to get a clip name from a clipId?

The method signature for the complete delegate is:

Code: [Select]
void CompleteDelegate(tk2dAnimatedSprite sprite, int clipId)
It would be cool if it was more powerful, like the event delegate:

Code: [Select]
void EventDelegate(tk2dAnimatedSprite sprite, tk2dSpriteAnimationClip clip, tk2dSpriteAnimationFrame frame, int frameNum)
i.e., I would love to have the tk2dSpriteAnimationClip clip instead of int clipId.

6
Support / Change tk2dCamera scale dynamically with code?
« on: May 31, 2012, 01:46:24 am »
How can I change the Scale for the tk2dCamera dynamically with code? I don't want to have to create dozens of different Resolution Overrides for all sorts of different devices and monitors; I'd prefer to just set the scale dynamically with code according to a handful of resolution ranges. Is this possible?

Basically, I'm looking for something like this:

Code: [Select]
td2kCamera.inst.currentScale = 2f;

7
FAQs / Pixel perfect scaling for sharp retro-style pixel graphics?
« on: March 17, 2012, 01:39:13 am »
I'm investigating 2D Toolkit for possible purchase, but I want to make sure it accomplishes what I'm looking to do first before I buy.

If I design a game with retro-style sharp pixel graphics (with hard edges and no anti-aliasing) at 480x320 for the iPhone 3GS, can I use Resolution Override with scale=2 to size the game up for iPhone Retina and iPad (and scale=4 for the iPad 3) and maintain the sharpness of the graphics, just at double the size? Or will 2D Toolkit soften the edges? What I'm looking for is for 1:1 pixel ratio on the 480x320 iPhone, and 2:1 pixel ratio on iPhone Retina -- essentially "pixel perfect" in both cases, just double the size in the latter case.

To illustrate, take a look at this page: http://en.wikipedia.org/wiki/Image_scaling

I would want my sprites to be sized up like the TV on the left (nearest-neighbor scaling) as opposed to smoothed anti-aliased scaling. Can I accomplish this with 2D Toolkit?

Pages: [1]