As I wrote last I've gotten the sprite animation somewhat working and I've even found a good way of making the sprite sheet. But I still haven't found the trick to getting the quality of the images right :(
So to start with the quality seems fine almost anyway as you can see here:
But after a while of running the application the graphics get blurred as you can see in this second screenshot. I have no idea why.
If anyone out there has an idea as to what I'm doing wrong then please comment.
Showing posts with label problem. Show all posts
Showing posts with label problem. Show all posts
Wednesday, October 6, 2010
Wednesday, September 29, 2010
Damn, Smooth Sliding
Rewriting the code the sprite sheet animation from java script to C# has given me some problems I didn't anticipate. The code simply appears to work differently in C# than in java script. I have two videos that illustrate the difference.
This video shows the right animation but the code is in java script:
Here the similar code is rewritten in C# as you will see the sprite sheet just slides at an angle instead of jumping picture by picture:
Here's the original java script code:
//vars for the whole sheet
var colCount : int = 4;
var rowCount : int = 1;
//vars for animation
var rowNumber : int = 0; //Zero Indexed
var colNumber : int = 0; //Zero Indexed
var totalCells : int = 4;
var fps : int = 10;
var offset : Vector2; //Maybe this should be a private var
//Update
function Update () { SetSpriteAnimation(colCount,rowCount,rowNumber,colNumber,totalCells,fps); }
//SetSpriteAnimation
function SetSpriteAnimation(colCount : int,rowCount : int,rowNumber : int,colNumber : int,totalCells : int,fps : int){
// Calculate index
var index : int = Time.time * fps;
// Repeat when exhausting all cells
index = index % totalCells;
// Size of every cell
var size = Vector2 (1.0 / colCount, 1.0 / rowCount);
// split into horizontal and vertical index
var uIndex = index % colCount;
var vIndex = index / colCount;
// build offset
// v coordinate is the bottom of the image in opengl so we need to invert.
offset = Vector2 ((uIndex+colNumber) * size.x, (1.0 - size.y) - (vIndex+rowNumber) * size.y);
renderer.material.SetTextureOffset ("_MainTex", offset);
renderer.material.SetTextureScale ("_MainTex", size);
}
And the code in my C# version:
using UnityEngine;
using System.Collections;
public class Animation_sprite_sheet : MonoBehaviour {
//vars for the whole sheet
public int colCount = 4;
public int rowCount = 1;
//vars for animation
public int rowNumber = 0; //Zero Indexed
public int colNumber = 0; //Zero Indexed
public int totalCells = 4;
public int fps = 10;
Vector2 offset; //Maybe this should be a private var
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
SetSpriteAnimation(colCount,rowCount,rowNumber,colNumber,totalCells,fps);
}
//SetSpriteAnimation
public void SetSpriteAnimation( int colCount, int rowCount, int rowNumber, int colNumber, int totalCells, int fps){
// Calculate index
float index = Time.time * fps;
// Repeat when exhausting all cells
index = index % totalCells;
// Size of every cell
Vector2 size = new Vector2 ((1.0f / colCount), (1.0f / rowCount));
// split into horizontal and vertical index
float uIndex = index % colCount;
float vIndex = index / colCount;
// build offset
// v coordinate is the bottom of the image in opengl so we need to invert.
Vector2 offset = new Vector2 ((uIndex+colNumber) * size.x, ((1.0f - size.y) - (vIndex+rowNumber) * size.y));
renderer.material.SetTextureOffset ("_MainTex", offset);
renderer.material.SetTextureScale ("_MainTex", size);
}
}
As all the examples I can find in unity's documentation and around the internet on unity are mostly in java script I often find myself being lost when it comes to using C# in unity.
This video shows the right animation but the code is in java script:
Here the similar code is rewritten in C# as you will see the sprite sheet just slides at an angle instead of jumping picture by picture:
Here's the original java script code:
//vars for the whole sheet
var colCount : int = 4;
var rowCount : int = 1;
//vars for animation
var rowNumber : int = 0; //Zero Indexed
var colNumber : int = 0; //Zero Indexed
var totalCells : int = 4;
var fps : int = 10;
var offset : Vector2; //Maybe this should be a private var
//Update
function Update () { SetSpriteAnimation(colCount,rowCount,rowNumber,colNumber,totalCells,fps); }
//SetSpriteAnimation
function SetSpriteAnimation(colCount : int,rowCount : int,rowNumber : int,colNumber : int,totalCells : int,fps : int){
// Calculate index
var index : int = Time.time * fps;
// Repeat when exhausting all cells
index = index % totalCells;
// Size of every cell
var size = Vector2 (1.0 / colCount, 1.0 / rowCount);
// split into horizontal and vertical index
var uIndex = index % colCount;
var vIndex = index / colCount;
// build offset
// v coordinate is the bottom of the image in opengl so we need to invert.
offset = Vector2 ((uIndex+colNumber) * size.x, (1.0 - size.y) - (vIndex+rowNumber) * size.y);
renderer.material.SetTextureOffset ("_MainTex", offset);
renderer.material.SetTextureScale ("_MainTex", size);
}
And the code in my C# version:
using UnityEngine;
using System.Collections;
public class Animation_sprite_sheet : MonoBehaviour {
//vars for the whole sheet
public int colCount = 4;
public int rowCount = 1;
//vars for animation
public int rowNumber = 0; //Zero Indexed
public int colNumber = 0; //Zero Indexed
public int totalCells = 4;
public int fps = 10;
Vector2 offset; //Maybe this should be a private var
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
SetSpriteAnimation(colCount,rowCount,rowNumber,colNumber,totalCells,fps);
}
//SetSpriteAnimation
public void SetSpriteAnimation( int colCount, int rowCount, int rowNumber, int colNumber, int totalCells, int fps){
// Calculate index
float index = Time.time * fps;
// Repeat when exhausting all cells
index = index % totalCells;
// Size of every cell
Vector2 size = new Vector2 ((1.0f / colCount), (1.0f / rowCount));
// split into horizontal and vertical index
float uIndex = index % colCount;
float vIndex = index / colCount;
// build offset
// v coordinate is the bottom of the image in opengl so we need to invert.
Vector2 offset = new Vector2 ((uIndex+colNumber) * size.x, ((1.0f - size.y) - (vIndex+rowNumber) * size.y));
renderer.material.SetTextureOffset ("_MainTex", offset);
renderer.material.SetTextureScale ("_MainTex", size);
}
}
As all the examples I can find in unity's documentation and around the internet on unity are mostly in java script I often find myself being lost when it comes to using C# in unity.
Monday, September 20, 2010
Out of Order
I've run into a problem. When I build and run the application it just shuts down right after showing the Unity icon. The console gives me this information:
The internet tells me I should reinstall everything - Unity, XCode and my mobile provisioning files :( 3-4GB download. Yay.
Subscribe to:
Posts (Atom)