NGUI Unity3d : Getting Screen size

I have been doing some Unity recently and so far it has been going very well. Hum, I bang my head on the wall sometimes but overall it’s fun. Except for when you search for something trivial and you can’t find anything. You see, they can say what they want but Unity isn’t a mature tech yet.

I am mostly doing UI, so I am using NGUI. It’s pretty neat, does pretty much what I want, but sometimes it doesn’t expose what I need, like the size of the screen. Well Unity has the Screen class where you can get the width and height of the screen and that is what I was using until I ran into some problems. I started by testing on my Nexus 4, then on the Nexus 7 and everything was fine until I tested on the Nexus 10. You see the Nexus 10 has a huge resolution and it was bigger than a little value that I hadn’t figured out what it was doing yet. The maximum height value on the UIRoot Script. This is actually a pretty nifty little thing. You see NGUI does some magic in the back when the resolution of the device exceed this value. It will scale the size of a pixel to be bigger that 1×1, scaling your content at the same time. When this happens the values of Screen.width and Screen.height are not measured in the same pixel unit has the NGUI one. So if you scale some background according to the number of pixels of your screen, it will be scaled way too big.

DisplaySize.instance.width

So I made this little static class to get myself the screen size in NGUI’s unit. I basically get the activeHeight from the UIRoot and I derive the NGUI Screen height and width from it. Here is the code:

public class DisplaySize{
	protected static DisplaySize _instance;
	public static DisplaySize instance{
		get {
			if (_instance == null){
				_instance = new DisplaySize();
			}
			return _instance;
		}
	}
 
	public GameObject gameObject;
 
	public float width;
	public float height;
 
	public void CalculateSize(){
		UIRoot mRoot = NGUITools.FindInParents<UIRoot>(gameObject);
 
		float ratio = (float)mRoot.activeHeight / Screen.height;
 
		width = Mathf.Ceil(Screen.width * ratio);
		height = Mathf.Ceil(Screen.height * ratio);
	}
}

So somewhere in your initializing code you need to pass it a gameObject that is a children of UIRoot and call CalculateSize. After that you can call DisplaySize.instance.width from anywhere in the code.

I am pretty new to Unity, so if you got a better way to do this, leave it in the comments.

, ,

No Comments


ActionScript Graphing Cookbook

I wrote a f**** book! I really did write a book. I wasn’t that excited about it until I got it in my hands. It’s usually like that for everything I work on, I spend so much time doing it that, in the end, I can’t stand it anymore. Looking back, it wasn’t easy to write this book. The writing was easy enough, it mostly was finishing and personal discipline that was hard. Anyway I’m pretty happy now that it is done. Other funny fact, if you look me up on Google, you’ll find an old bio stating that I wasn’t co-author of any books, well we can scratch that now!

ActionScript Graphing Cookbook

That’s the title of the book, it is mostly about taking data and showing it in a visual way, be it with a chart, a graph, a map or any sort of data visualization. I wrote chapter 3-4-6-7-8. The first thing I did when I got the physical book, is check out Chapter 6 : Mapping geographical and spatial data. I didn’t know so much about maps and how to draw on them, but I can say that learning and writing about them was very fun.  It basically became my favorite chapter of the book. Be sure to check the heat map recipe; it’s the best one in the book.

Code samples

Another great thing about this book is that every recipe comes with code sample. I would say that I spent almost as much time making the code samples than writing the book. They are meant as starting points to be easily modified to fit your need.

So if you need a book to get you started on data-visualization and making graphs in ActionScript, the ActionScript Graphing Cookbook is for you! Go and buy it!

 

No Comments


Glitch is over

I was shocked to learn today that Tiny Speck will be terminating Glitch in December.

But what was Glitch?

Glitch was a virtual world for kids that was awesome. The storytelling was awesome and the design was impeccable . It was fun and beautiful. I would have liked my kids to play it (I don’t have any by the way) . Here are some screens to show you, but you won’t get how well it ran.

So what is the fuss?

Well why I write about this is because of what they say is the reason of their failure. Their text about it is kinda weird. First they say that movement towards mobile was a problem. Ok, I understand that there is a huge increase in mobile traffic, but I don’t think there is a decrease in desktop traffic right? So people going mobile shouldn’t be such a problem. Secondly they blame the decline of the Flash platform, which I don’t really understand, because I never heard anyone uninstalling the Flash Player, so it is still installed on 96% of all computers. Also Adobe is now focusing on games. I really don’t see the decline there except in people’s mind. No other tech would have allowed them to do what they did. This game wouldn’t even have been doable on mobile. The screen size would have been a major issue.

Something else is fishy

Next, they say they won’t sell to another company, because they say there is no worth in their product. This is kind of a weird statement. If you do not see value in your product, maybe someone else will; maybe someone else will be able to turn it around. I say this because Glitch was an amazing product, for sure someone was going to see value in it.

So wtf happened?

My guess is that their business side went wrong. They weren’t able to monetize it. I don’t know what they tried because it has been at least 6 months since I went, but surely they failed on that. They say they are going to reimburse every one for stuff bought more than one year ago. Doesn’t that sound crazy to you? That or they really made no money at all and it is nothing for them to give the money back. Or it could indicate that they are idealists and that could have prevented them from making choices in order to monetize the game (like adding ads, not everyone like ads). I don’t know it all sounds really weird to me.

Someone there clearly think he knows what he is doing, but he doesn’t.

No Comments


Robotlegs 2 coming from Robotlegs

I did an article when I switched from PureMVC to Robotlegs so I am going to do something similar here. Yesterday I was able to do everything I wanted with Robotlegs 2, enough to do a full project with, but it wasn’t straight forward. Hopefully this will save you some time.

OMG they removed the org

First thing you will notice in the git repository is that they removed the org package; it starts right at robotlegs. No more org.robolegs.somethingelse. I was kinda confused at first. I thought I was at the wrong place. I kept looking for the src. But after reading this discussion about it, I figured I was at the right place. It did make much sense at first and it was pretty confusing, but in the end it doesn’t change much. Doesn’t help much either, but we will get use to it I guess. Goodbye org package!

Bender full of women

They next package inside the robotlegs source folder is bender. Funny thing, English not being my first languages I was thinking of binders and I didn’t get it… Silly me, well it refers to Bender, the robot character from Futurama. It is meant as a version name (version number) so version 2 is named Bender, version 3 will be some other robot I guess. This is a like what Google is doing with Android and naming every version of its operating system as a dessert (Ice cream sandwich, Jelly Bean, Gingerbread, etc). Again a bit confusing; I would have gotten it right away if I had seen v2, but bender is great once you know about it ;) (first emoticon I put in a post)

Putting it into context

Next little problem I had was when I created the context. The code on the git page is great but it only gives you half of what you should write. So here is what they have on their page:

_context = new Context().install(MVCSBundle).configure(MyAppConfig, SomeOtherConfig).configure(new ContextView(this));

Now this is all good and nice, so I paste this in my project, and than I put my variable statement for _context at the top of my Class and I naturally type it to Context. Error, here is the silly error it returned : “Error: Implicit coercion of a value with static type robotlegs.bender.framework.api:IContext to a possibly unrelated type robotlegs.bender.framework.impl:Context.”. Now I’m like OMG, WTF, I think I should be right about everything. Well not this time. You need to type your _context as IContext; took me a little while to figure it out (hopefully having the error pasted in this post will save you some time). So:

private var _context:IContext;

MVCS but where is my command map?

This one was easy, I was looking to map some commands, but couldn’t find the right class. I am in FlashDevelop and I start typing CommandM and two classes pop up CommandMapper and CommandMapping. Sounds somewhat good, but doesn’t seem to be the right thing. After some looking around in the examples, the class I was looking for was IEventCommandMap, once you inject that, you are golden.

[Inject]
public var commandMap:IEventCommandMap;
commandMap.map(TestEvent.SQUARE_CLICKED, TestEvent).toCommand(StartApplicationCommand);

And finally the ContextView

So yeah, last thing I needed to do was to add some views on the stage, but where to start? Answer: pretty much everywhere! Inject the ContextView where you need it, after that you can add views to its view. Hum sounds confusing here is some code:

[Inject]
public var contextView:ContextView;
contextView.view.addChild(new SquareView());

Conclusion

So I got all my building blocs that I am used too in Robotlegs v1 so I could technically build a project using it. V2 feels good, I like the new syntax to create the Context and to map mediators and commands. It seems to be doing way more than what I am used too, there are a lot of extensions that I didn’t investigate. But hey, time will tell if it can hold its own.

, , , , ,

1 Comment


Wtf I hate Flex

Ok when I say WTF I mean why the fuck, and this post will explain why I think Flex is shit. Wow, those are harsh words. But I truly hate Flex. I must explain first that I don’t think Flex has been built for me. I mostly make nice looking stuff; games and rich experience websites. Flex is made to be functional, but making it looking good, and by that I don’t mean half-ass good looking, I mean flawless, is pretty hard. Harder than it would have been using just ActionScript in the first place.

I came to Flash because I didn’t want to do HTML. Why would you try to emulate HTML (MXML) with Flash? It makes no sense to me… HTML will always better at HTML, duh! Flash is better at being awesomely good looking easily. Anyway I digress, but I mean if you are building a game or a microsite (everything other than a web app, and a corporate one at that), please stop using Flex.

I rant here because I have been forced lately to use Flex where I work and I don’t really like it ( and I can’t say much because I just started). I feel like it is creating so much friction for what I want to do that it ain’t worth it. Believe me I am trying to stick to ActionScript as much as I can, but in order to use the fonts that are already embedded in the game, I need to build on the Flex display list. It means using UIComponents wherever I would use Sprites and using UITextfields wherever I would use a simple TextField. It adds a lot of overhead and for a game, I don’t think that is a good thing…

Flex is not smooth and it is not made for smooth people. Flex as been engineered for hardcore programmers that don’t really care about design. Plus now Adobe isn’t even supporting it anymore, it makes its future so hazardous… Anyway, what I want to say with all this, please stop using Flex, please…

17 Comments


Warming up on writing, this blog needs some love!

This was actually hard to do. Sit down and do like I have done so many times in the past; write a blog post. I shouldn’t be writing this post, there is one that comes before, but I’ll keep it for a rainy day. There are two reasons why I didn’t write a lot this year. First, I didn’t work much. Most of my inspiration came from having technical problems at work; no problems, no writing. Second is the fact that I was writing a book (well half a book). When you write as your main occupation, you don’t want to write as your side occupation. Makes sense.

Now the book is almost done (3 chapters to revise and it’s in the bag!) and I got a new job so I will probably give more love to this blog. Not sure if will be on the same topic, but I know for sure that I will write about whatever I want. No more directed writing for a while (at least ten years). Anyway, I got a job at WoozWorld, a social-media platform / virtual world website. It is pretty different than the agency world and right now it feels very awkward. I will let it grow on me a bit and see on it turns out. Also my official title is Flex / Java developer which is also bizarre but I am mostly pluging ActionScript into a Flex application so it’s not so bad.

While in New York I was working with FDT. I didn’t like it at first, but I came to like it, after they fixed a lot of issues. Now I have to work with FlashBuilder and I don’t like it at all, haha! Feels even worse than FDT at first, but I tried to use FlashDevelop on the project to know success. The project is really big and probably grew in a weird way over time, so it has weird dependency that makes it hard to just change editor (I know this must be weird that a project is so tied to an editor, but trust me I tried to use another). Well, it will probably just do like FDT and I will come to like FlashBuilder.

So that’s all for now folks, this was just a warm up post to get back in the game! Next post I will go more in details on what I did during the last year.

1 Comment


Got a sponsorship from Mathnook.com

Finally got an offer that made sense for a sponsorship and it is the good people behind mathnook.com and gamenook.com that made it. The previous sponsor wanted the ad revenue which I knew wouldn’t be too high (made 7$ as of yet), but they didn’t offer much too, plus I wanted to know how much money it meant so I refused. After I posted about my game here, I got contacted and accepted the sponsorship from mathnook.com because it didn’t come with any strings attached.

Anyway, I reuploaded the game on Kongregate, go play it!

, , , , , ,

1 Comment


Tricks when starting using the Starling framework

I am working on my next game, well trying to. I am a bit lazy but I am fighting that. Anyway I came to a point where performance was an issue in the prototype, so I decided it was time to jump into the Starling Framework.

I have been wanting to try it for some time and I must say it was quite easy to port my existing code to it since it uses the same API than the Flash display list. But there are a lot of little things that are different. I’m am going to list a few gotchas, but first I think every one new to Starling should read Thibault Imbert book (which is free) about it. It is only 122 pages long and it took me about 20 mins to go through it. Also the wiki on the starling framework website is quite useful.

Starling; the walled garden

Here is the code you need to start Startling:

_starling = new Starling(Game, stage);
_starling.start();

Game being a class where you will control what will happen inside of Starling (also called the Root Class). Now you see my next game interface will use the normal Flash display list, but from it the user will be able to change stuff that happens on the graphics inside Starling. So I need a way to communicate with it, but there is no easy way to access the Game class… Here is the way I found:

_starling.addEventListener(Event.ROOT_CREATED, _onRootCreated);
private function _onRootCreated(event:Event):void {
	_starling.removeEventListener(Event.ROOT_CREATED, _onRootCreated);
	_game = Starling.current.stage.getChildAt(0) as Game;
	_game.init(_whateverData);
}

If you ask me this is a bit hackish, mostly the stage.getChildAt(0) but it works. I think you should just be able to access it using Starling.rootClass but that is just me I guess. I read somewhere that you could listen to the Event.CONTEXT3D_CREATE but that didn’t work in the latest version.

Little differences

So they wanted Starling to be similar to the display list but some little differences remained. The first one I noticed was that the rotation property on a DisplayObject is in radians instead of degrees. A bit annoying but not really a huge thing. Starling comes with a utility function to convert angles that you can find here: starling.utils.deg2rad. They did this in order to be consistent with the Sparrow framework; not sure why Flash people should care but hey, what can you do…

Also if you are looking for filters on display objects, stop looking it’s not there.

Finally the is 2 great new properties on display object pivotX and pivotY which allow you to change the origin point which is really useful in rotations and scaling.

Well that is it for now, as I play more with it I should find more stuff and I will edit this post. Also, I will be working on a book soon, so I might not feel like writing on this blog too ( you know, like writing too much in one day).

, , ,

3 Comments


Doodle Complete on Kongregate

After a six weeks waiting for sponsors on Flash Game License and a ridiculous bid of 75$, I decided to finally release my game Doodle Complete on the web. The 75$ bid was even more ridiculous than that, the bidder also wanted to collect the money from advertisement and release the game under their name on Kongregate and Newgrounds (well new grounds require the game to be only 700px height so my game won’t fit there…). So I decided to release it without sponsors and to at least get some information about advertisements revenues. I spent all day yesterday trying to get Admob working for the Blackberry Playbook (yes you can get it on your PlayBook now!), but I couldn’t really do it. I also made it available with MochiAds and to their distribution network which already gave me 2000 views, so that is good.

Now, it seems like people on Kongregate don’t really like the game because the controls are hard… Well I could do something there, but I don’t think it would make people go crazy about the game anyway. So I kinda decided to let it go. I’m going to fix the minor bugs, but I won’t put anymore time on this game and start working on the next one which will be more classical, little risks that people will complain about the controls.

Last thing I will do is try the iAd extension for iOs from Milkman games to see if those revenues are worth the trouble. I will have to pay 20$, but I guess I will have it for other games too.

Anyway go play the game on Kongregate and if you can give it 5 stars :)

, , , , , , , , ,

3 Comments


Little games for Lassonde based on Madagascar 3

Didn’t have much to show since I came back from the States, but here is a little project that was pretty fun to do. Fruite Madagascar 3. My part in it was to do the games: Burst-A-Balloon, Pin the zebra and Memory game.

Felt really good to have a project that didn’t become extremely complicated after a while :) . I used Robotlegs for all of them, and I reused a lot of code in each game. Seems like Robotlegs ain’t the preferred framework when building games, but in this case performance wasn’t really an issue so I liked it a lot.

, , , ,

No Comments