Developing a Facebook Application for absolute beginners – step 3

In step 1 we created a simple Facebook application, and in step 2 we made our application able to write on the wall

Now it’s time to add images and more text to users’ wall when they run the application.

This is what I am creating:

I know I wrote “appliction”… but it was a typo… don’t make me take another screenshot (lazy geek…)

In order to do this, you will need to know how to include attachments.

You can add a lot of rich information to a post by including an attachment. The attachment gives you the opportunity to expand on the post by describing what the user did in your application.

This is the script: Read more

Rendering joints with Box2D

In most Box2D projects you can see how to render bodies or attach objects to them, but I couldn’t see any tutorial about rendering joints.

If you look at the classic rendering loop it’s something like this one

for (var bb:b2Body = m_world.m_bodyList; bb; bb = bb.m_next) {
     if (bb.m_userData is Sprite) {
          bb.m_userData.x = bb.GetPosition().x;
          bb.m_userData.y = bb.GetPosition().y;
          bb.m_userData.rotation = bb.GetAngle() * (180/Math.PI);
     }
}

but as you can see, it only renders bodies.

The following script is the same you can find at Simulating a hook with Box2D but I will render the joints with lines. Read more

Developing a Facebook Application for absolute beginners – step 2

It’s time to add some features to the application we created in step 1.

This time we’ll add some interaction with Facebook, such as publishing results on your wall.

The new script is this one:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
< ?php
 
require_once 'facebook.php';
 
$appapikey = 'xxxxxxxxxxxxxxxxxxxxxxxxx';
$appsecret = 'xxxxxxxxxxxxxxxxxxxxxxxxx';
 
$facebook = new Facebook($appapikey, $appsecret);
 
$user_id = $facebook->require_login();
 
$friends = $facebook->api_client->friends_get();
 
echo "<p>Hello <fb :name uid=\"$user_id\" useyou=\"false\" linked=\"false\" firstnameonly=\"true\"></fb>, you have ".count($friends)." friends";
 
foreach($friends as $friend){
     $infos.=$friend.",";
}
 
$infos = substr($infos,0,strlen($infos)-1);
 
$gender=$facebook->api_client->users_getInfo($infos,'sex');
 
$gender_array = array(); 
 
foreach($gender as $gendervalue){
     $gender_array[$gendervalue[sex]]++;
}
 
$male = round($gender_array[male]*100/($gender_array[male]+$gender_array[female]),2);
$female = 100-$male;
 
echo "<ul><li>Males: $male%</li><li>Females: $female%</li></ul>";
 
$message = "has ".count($friends)." friends. $male% of them are male. $female% are female";
 
$has_permission = $facebook->api_client->users_hasAppPermission("publish_stream");
 
if(!$has_permission){
     echo "<br /><fb :prompt-permission perms=\"publish_stream\">Publish results on your wall!!</fb>";
}
else{
     $facebook->api_client->stream_publish($message);
}
 
?></p>

That is the same as Developing a Facebook Application for absolute beginners until line 33 Read more

Simulating a hook with Box2D

In a comment to Pumpkin Story prototype, a reader asked for a function to simulate a hook.

This can be quite easily done in some steps.

This first step will set a rule: you can only hook to a static body. Obviously it’s not a mandatory, rule, but just a gameplay one.

In this example, we’ll use the same script we saw at Box2D joints: Distance Joint with some modifications and the concept saw at Creating a sling with Box2D using joints when we must remove the hook.

This first part is simple, and will introduce us into the world of hooks.

Clicking and holding the mouse on a static object (the green one), we’ll create a joint between the centre of the ball and the mouse pointer.

Releasing the mouse will destroy the joint.

This is the script: Read more

Pumpkin Story prototype

This quick Pumpkin Story prototype is made merging and mixing these scripts: Drawing arcs with AS3 and Creation of a Flash artillery game using Box2D.

If you notice, it’s similar to an artillery game (like Bloons) with the “only” difference you are the bullet.

This opens some interesting gameplay options, so interesting I am going to make a similar game, but I’ll start talking about it during next days.

Meanwhile, this is the script: Read more

MySQL to JSON with PHP

Ugly title for a post, really… but I did not find any function to convert the result of a MySQL query directly into JSON notation, so I made my own function.

I really needed it today, so I am sharing it with you. It’s not a everyday use function, but I am sure some of you will find it useful, just like it happened with Sending email with multiple attachments with PHP.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
function mysql2json($mysql_result,$name){
     $json="{\n\"$name\": [\n";
     $field_names = array();
     $fields = mysql_num_fields($mysql_result);
     for($x=0;$x<$fields;$x++){
          $field_name = mysql_fetch_field($mysql_result, $x);
          if($field_name){
               $field_names[$x]=$field_name->name;
          }
     }
     $rows = mysql_num_rows($mysql_result);
     for($x=0;$x<$rows;$x++){
          $row = mysql_fetch_array($mysql_result);
          $json.="{\n";
          for($y=0;$y<count($field_names);$y++) {
               $json.="\"$field_names[$y]\" :	\"$row[$y]\"";
               if($y==count($field_names)-1){
                    $json.="\n";
               }
               else{
                    $json.=",\n";
               }
          }
          if($x==$rows-1){
               $json.="\n}\n";
          }
          else{
               $json.="\n},\n";
          }
     }
     $json.="]\n};";
     return($json);
}

The first parameter is the result of the query, without any parsing, just the output of mysql_query function, the second parameter is the name you want to give to your JSON object.

Returns a string with the JSON notation of the result.

Drawing arcs with AS3

If you have ever tried to draw arcs with AS3 (or AS2), you probably smashed your computer on the floor after spending hours with curveTo().

That’s not what we need when we want to draw simple arcs, without any Bezier curve.

That’s why I made my own function.

It’s not that interesting since it only uses a bit of trigonometry, and obviously I did not write it for the sake of writing a function, but at the moment with this script

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package {
	import flash.display.Sprite;
	public class arc extends Sprite {
		var my_canvas:Sprite = new Sprite();
		var deg_to_rad=0.0174532925;
		public function arc() {
			addChild(my_canvas);
			my_canvas.graphics.lineStyle(20,0xff0000,1);
			draw_arc(my_canvas,250,200,150,14,180,1);
		}
		public function draw_arc(movieclip,center_x,center_y,radius,angle_from,angle_to,precision) {
			var angle_diff=angle_to-angle_from;
			var steps=Math.round(angle_diff*precision);
			var angle=angle_from;
			var px=center_x+radius*Math.cos(angle*deg_to_rad);
			var py=center_y+radius*Math.sin(angle*deg_to_rad);
			movieclip.graphics.moveTo(px,py);
			for (var i:int=1; i< =steps; i++) {
				angle=angle_from+angle_diff/steps*i;
				movieclip.graphics.lineTo(center_x+radius*Math.cos(angle*deg_to_rad),center_y+radius*Math.sin(angle*deg_to_rad));
			}
		}
	}
}

you get this result: Read more

Developing a Facebook Application for absolute beginners

With more than 300 million active users and 50% of them using it every day (source), Facebook can be an interesting way to make some viral marketing.

One of the most effective ways is developing an application users (and users friends – and friends of users friends – and…) will use every day.

This tutorial will guide you through the creation of a simple application that will display how many male and female friends do you have.

Requirements

To develop a Facebook application with this tutorial, you will need:

* An active Facebook account
* An hosting plan supporting php
* Being my fan

ehm, actually being my fan is not strictly required, but it’s strongly recommended :)

Getting started

Go to developers area and click on Set Up New Application

Give a name to your application and agree terms. Read more

AS3 level editor

Almost a year ago I blogged about a basic level editor for a tile based game, and now Philipp Zins from Germany show us his AS3 level editor-

I made the level editor in ActionScript 3. You can scroll through the tiles with the mouse wheel – it isn’t necessary now, but very helpful if you use many, many tiles. You can change the map size and activate the “Generate”-Button by clicking or pressing Return.You can scroll the map, too. The finished array will be traced. The tile graphics are a little different – you will see that. I think I used some german words in the code, sorry.

Prepare yourself for a quite long source code… Read more

The return of “Under Construction” – evolution of a malpractice

In the late 90’s most personal and some commercial websites used to place a big, animated, irritating image like this one:

This picture, placed in a webpage browsed at a 800×600 resolution (the most popular one during those years), fills half of the visible area.

This means the page was shouting “hey, I am incomplete, probably I will never be completed so what are you doing here?”

We know a good site is always under construction. This blog is always under construction. I add new content almost every day.

As co-owner of a web agency, I notice almost all customers ask some minor changes to their sites about every six months… no matter if it’s a new set of photos or an update to the “about” page… they are changing. Read more

Next Page →

flash games company