Text 9 Apr Animated Sprite on 3D Space!!!

I have been working in a few things in the last few days on putting an animated sprite on 3D space. Well, I did it! That was one of the things I have always wanted to do. Like I said before, most tutorials out there are useless. To do a simple “hello world”, they end up putting other undesired functionality, and the reader is left to dig and until he/she finds where the correct functionality is located. I was able to do the task by experimenting, researching, and consulting a few of my friends. This is the function that I came up with to display an animated sprite on a transparent polygon:

        //draw the model

        public void Draw(AnimatedSprite animatedSprite)

        {

            foreach (ModelMesh mesh in model.Meshes)

            {

                foreach (BasicEffect effect in mesh.Effects)

                {

                    effect.Texture = Image.Crop(animatedSprite.texture, animatedSprite.sourcerect);

                    effect.Projection = projectionMatrix;

                    effect.View = view;

                    effect.World = transforms[mesh.ParentBone.Index] * modelWorldMatrix;

                }

                mesh.Draw();

            }

        }

So here we are drawing a model. What I do here is, that I send the animated sprite, and I crop the current frame from the sprite sheet. I use the cropped texture and apply it to the model mesh. Considering the the animated sprite is being updated (It is updated somewhere else, and not visible in this code sample), the program will always crop the correct frame of the sheet.

Why am I so excited about this? Like I said, I have always wanted to do this. One of the style mixes that I have admired is that of Final Fantasy Tactics. They have 3d environments with 2d Sprites for characters. Now I have achieved a similar look.

Apart from this, I have been helping out a friend with his game idea. I have to say that it has progressed faster than I had expected. Its going well. In that project, just yesterday, I was creating a Level class for a “side scroller”. One of my philosophies is to make my classes as reusable as possible. Thats why I implemented some xml while doing it. You list the assets needed on the xml, and the class reads it and assigns it to the correct objects. I did that before with my menu class, and it worked just as well when I tried it with the Level class.

Another friend is also trying to start a typing game. Right now he is writing the concept document and class diagrams. Hopefully we will get to start on it soon. I have to say that I do enjoy programming, and I like to keep busy as well.

Text 4 Apr More XNA Programming

I have been programming on XNA. Something that I have been struggling for a long time is on how to display a sprite in 3D space. My first obstacle was putting a texture on a polygon. I did it without the help of tutorials. All the tutorials for XNA 4.0 are badly done. To demonstrate a concept, the make an HUGE project with extra functionality. The reader is left to dig through the pile of code. Thats not the way to approach it. A tutorial should only teach one concept, and be as bare bones as it can. When you understand a concept, you can build the bigger projects on your own. Speaking of which, maybe I should start my own XNA tutorials… Anyway, I was able to put a texture on a polygon. The next task was to translate the texture’s alpha transparency to the polygon. I did that, but then came up with another problem. The alpha transparency painted the polygon’s blank areas cornflower blue. After hours of research, I learned on a forum, alpha transparent texture should be drawn last. 

So far, so good. Now comes the real challenge. I want to put an animated sprite on the polygon. That is gonna be the next step for me.

I have also been helping a friend with his game idea. Lots of stories to tell on that front. I will surely update on them as well.

Text 18 Mar Visual Basic, Android Phone, and Eclipse

Most of my time today(Thursday) was spent programming. I successfully wrote an XML file with Visual Basic (I learned to both read and write xml files in Visual Basic!!!). Here is the code:

‘imports

Imports System.Xml

Public Class Form1

    ’variables

    Dim m_name As String

    Dim m_birth As String

    Dim m_social As String

    ’xml objects

    Dim xmlDocument As New XmlDocument()

    Dim xmlElement As XmlElement

    ’

    Private Sub btn_save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_save.Click

        Dim Document As New XmlDocument()

        Dim newAttribute As XmlAttribute

        ’declare type

        Dim declaration As XmlDeclaration = Document.CreateXmlDeclaration(“1.0”, Nothing, Nothing)

        Document.AppendChild(declaration)

        ’do root element

        Dim DocumentRoot As XmlElement = Document.CreateElement(“Info”)

        Document.AppendChild(DocumentRoot)

        ’create element ‘Patient’

        Dim Patient As XmlNode = Document.CreateElement(“Patient”)

        ’set name

        newAttribute = Document.CreateAttribute(“Name”)

        newAttribute.Value = tb_name.Text

        Patient.Attributes.Append(newAttribute)

        ’set date of birth

        newAttribute = Document.CreateAttribute(“Birth_Date”)

        newAttribute.Value = tb_birth.Text()

        Patient.Attributes.Append(newAttribute)

        ’set social security

        newAttribute = Document.CreateAttribute(“Social_Sucurity”)

        newAttribute.Value = tb_social.Text()

        Patient.Attributes.Append(newAttribute)

        ’close the element

        DocumentRoot.AppendChild(Patient)

        ’save the xml file

        Document.Save(“Patient_File ” + tb_name.Text + “.xml”)

        ’close application

        Me.Close()

    End Sub

End Class

Even so the majority was spent on setting Eclipse to run and Android Phone application. The process was long and exhausting. After 3 long hours, along with the help of a friend, I was able to run a “Hello World” application (“hello world” being the simplest tutorial that programmers encounter when learning new things). It was time well spent. I learned how to link libraries in Eclipse, and how to set a virtual Android Emulator. This of course is the beginning. Now the challenge is to make something meaningful on the Android.

Text 16 Mar The Last Few Days

The last couple of days, I have spent my time mostly writing Video Game Concepts and doing research. It is important for a programmer to be familiar with the documentation of an idea. The reasons programmers need a physical document to read is to ease development. That way they know exactly what they are programming and how it relates to other aspects of the program. I do not want to repeat my past mistakes. In the past, eager to start programming, I have skipped the documentation process. That has caused many problems. By not having a clear outline of the program, I ended up rewriting code multiple times. As a programmer, I like to think that I can do everything from the top of my head, but programming is not an improvisation game, it requires careful planning. With that in mind I spent the last few days writing concepts down. Not many hours ago, I was helping a fellow graduate and friend document his ideas for a game. 

In terms of research, I read a bit on C#. I was worried about the future. An important aspect of game development is memory management. If you are not careful your game could have memory leaks and run completely out. C++ offers the programmer the ability to deallocate memory at will. C# does not. C# has what is called trash collection. When an element is not being used or has no pointers to it, trash collection may deallocate the unused memory. This presents a challenge in game programming. You want to have control over memory. To deal with it in C#, you need to be able to learn of ways of how to get around it. One of the suggestions I saw was to create a method call that sets all the objects and pointers in a class to “null”. I have yet to try this, for I am still reading on the matter. By researching, one can avoid problems in the future.

So why use C# for a game instead of C++? Most game developers use C++ because of the memory management issue. The reason I am reading on C# and game development is because I want to make a game for the XBOX 360. I am using XNA, and XNA works on C#. XNA allows for the development of PC, Windows Phone, and XBOX 360 games. My reason for using C# is because of how easy it is to go cross platform. XNA has become mainstream within independent game developers, so it is easier to contact and learn from other developers who may have good suggestions or ideas when it comes to programming games.

Text 28 Feb Learning with Java

Today I spent most of my day reading on programming. I read a bit on C# to better understand some issues that came up during my XNA test game. But the core of my efforts went to reading and doing Java. I had done some console applications in the past with Java, but today I started on creating an application with a window frame and “clickable” buttons.

Programming in any language is the same. Logic is always the same. A loop is always a loop, a variable is always a variable, and a function is always a function. The only thing that changes is syntax and perhaps capabilities or limitations of a programming language (terminology also varies from one language to the next).

With that mindset, I got started on my application window. I will admit that it took me by surprise. It was a bit more challenging than I had expected. Recently I jumped from C++ and C# into Visual Basic. That transition was smooth. Before I knew it I was working on a Window Application that read XML files. Java was a bit rougher. I see that Java is more similar to C++ and C# than Visual Basic ever was, so why was I struggling? I asked myself. I strongly believe that it was due to the IDE. I am using Eclipse for Java, but I am far more used to Visual Studio. In Visual Studio making a window application is quite the breeze depending on the project type you choose. In Eclipse I was doing everything from scratch (which is a good thing from a learning perspective). In the end I was successful, and I did the test application that I had set out to do. Here is the code:

//imports

import java.awt.*;

import java.awt.event.*;

import java.awt.geom.*;

public class GUI extends Frame

{

private Closer Handler;

GUI()

{

Handler= new Closer();

setTitle(“My Test Window”);

setSize(640, 480);

setLayout(new FlowLayout());

addWindowListener(Handler);

show();

}

public static void main(String args[])

{

GUI MyGUI= new GUI();

Button m= new Button(“button”);

m.setBackground(new Color(20, 59, 100));

MyGUI.add(m);

}

}

class Closer extends WindowAdapter

{

public void windowClosing(WindowEvent event)

{

System.exit(0);

}

}

So, what did I learn in this learning round with Java? In addition to learning the syntax, I also learned something about myself and my view of programming. Programming Logic is always the same, but an IDE is not. Now I understand that I have to set the goal of better understanding Eclipse. This is all part of expanding one’s knowledge. 

Text 27 Feb More games & XNA 4.0… with notepad

Today I spent most of my time trying to create a tile builder to facilitate the creation of game levels on XNA. So previously, I had worked on reading XML files and extracting data from them. Today I made  layout of a game level in notepad. 0’s were empty space and 1’s stood for tiles and obstacles. I made the program read the extracted string and load the tiles and obstacles accordingly. Using XML is indeed making things better, and using notepad to create level layouts its going to make the making games so much easier! 

Text 26 Feb Making Games on XNA 4.0

Lately I have been programming on XNA, making classes for a possible game in the future. It is interesting how programming can be so flexible. There are so many ways and paths one could take to accomplish a goal. In reality, there is no right or wrong when it comes to programming, only efficient or deficient. A programmer evolves with every tasks he/she tackles and I have certainly lived it. I am going through that evolution constantly. Since tackling XNA 4.0, I decided to try some new things that I had not done before. Instead of hard-coding data (such as menus, level layouts), I had the program read from XML files containing such data. Since I accomplished that, I have seen the future, and it seems as if it will make coding so much easier. 

On the side, I have also been learning new programming languages. Recently, I started on Visual Basic. One has to be willing to expand their knowledge to become a better programmer.

Text 26 Feb Replies

Replies must be enabled manually. Coustumize->Community then check the boxes.


Design crafted by Prashanth Kamalakanthan. Powered by Tumblr.