Smart Mobile Studio
  • News
  • Forums
  • Download
  • Store
  • Showcases
    • Featured demos
    • The Smart Contest 2013, Round 1 – Graphics
  • Documentation
    • Get the book
    • System requirements
    • Prerequisites
    • Getting started
      • Introduction
      • Application architecture
      • The application object
      • Forms and navigation
      • Message dialogs
      • Themes and styles
    • Project types
      • Visual project
      • Game project
      • Console project
    • Layout manager
    • Networking
      • TW3HttpRequest
      • TW3JSONP
      • Loading files
  • About

Monthly Archives: March 2012

Pascal game developer’s compo!

Posted on 31.03.2012 by Jon Lennart Posted in Developers log
Waste of time? Think again!

Waste of time? Think again!

Many programmers don’t get the demo scene. What could be the point of spending hours, days and weeks on creating effects? Well for me the demo scene has been one of the best things in my life. I grew up with Commodore 64, MSX, Atari and Amiga machines. And while we all loved to play games only the few asked the magical question “how”. Some were happy to just play the games, but the rest of us, those that became programmers as adults, were always the people who just had to ask the question “how the hell did they do that”?

I have been extremely privileged growing up in Norway during the 1980’s and 90’s, nowhere in the world (with exception of Germany, Sweden and Finland) was the demo scene stronger than in Norway. Even to this day we fill the viking ship annually with thousands of young programmers full of creativity (check out this site for tickets to The Gathering). So there can be little doubt that the “demo scene” is primarily a European phenomenon.

PS: if you are looking for talent then The Gathering should be the proverbial shangri-la !

But why? What is it good for?

Demo coding is one of the best ways of growing as a programmer and as a thinking individual. The problems you face (like tweening objects, calculating sprite paths, how one object stands in context to another, proportion, animation cycles – the works!) will help you in every avenue of life, including your personal life since it involved organization and thinking in terms of context. It will benefit you in the most unlikely of scenarios: Take an example from my life, I always wanted to code games, but I spent many years coding invoice systems, win32 services and all the “boring stuff”. But one day my employers wanted a 3d look and feel to their report, so i ended up using the skills i learned as a demo coder to complete tasks. Without it those reports would have been very dry, very dull and not very productive. So it turned out to be my creative side that made the difference, not my education (!) You dont learn stuff like this at the university.

No matter what your interests might be, from games programming to spreadsheets – you are bound to face the same mathematics and the same train of thought. But those that really succeed in these things are the programmers who took the time to really experiment with demo and games coding. Anyone can code a spreadsheet, but it’s the hacker that makes the numbers bounce 😉

The Pascal Game Developer’s compo

Smart Mobile @ 98% complete

Smart Mobile @ 98% complete

When you think “pascal”, you think database driven business applications right? Well that’s just wrong. Delphi (which is the universal name for object pascal) earned that label because it made database programming simple in the early 90’s. But object pascal as a language is capable of so much more. So much so that databases become almost trivial in comparison. Remember all those high-speed dos games? (if you don’t, then get an emulator) A lot of those games were coded in turbo pascal. This was before we had full OOP and the might of the VCL at our fingertips.

It thus stands to reason that with all the power of the Delphi XE2 and the latest free-pascal compiler, that object pascal could knock out some serious games right? I mean — when compared to a commodore 64, Atari ST or Amiga?

Remember that the commodore 64 contained the same cpu-chip that powers most modern dishwasher’s today. Yet that little machine running at 1Mz with an 8bit bandwidth knocked out some pretty cool games! Now imagine what you could do with a computer 10.000 times faster, with 32 bit graphics, 24 bit sound and an IDE unlike anything we had back in the 80’s!

Well, unless you are reading this on a Pentium PC, that computer is what you have right now.

The gathering, Vikingship, Norway

The gathering, Vikingship, Norway

So… If they can do this on a 1mhz dishwasher, then surely we can do better right? With our dual-core processors, fifth generation 3d graphics chip-sets and latest operative systems?

Here are a couple of examples of what people can do with a commodore 64 (second video is from a modern PC, coded in machine code):

Instinct & Horizon C-64 Demo, 2008

And just how much brilliance can you pack into 64k of machine code?

Razor 1911 – my #1 demo group

And just to make it retro – here is the first Amiga demo i ever saw. This demo made me forget all about commodore 64 gaming, and ask the question “how”. This demo changed me from a gamer for a coder:

Doc – Demons are forever

Our mission is to follow javascript at every step. From it’s birth as HTML5 and onto it’s full evolution as a fully fledged multimedia system. We want to push the limits of what can be done under javascript to the full extent of it’s capabilities. And last but not least – to provide the infrastructure required for modern object pascal programmers to continue their hard earned experience and knowledge under a new platform. Javascript is quite alien to the average Delphi or FPC programmer, but with Smart you will be able to knock out apps with little effort.

Getting inspired

Today, the Pascal Game Developer competition started. And Smart was included in the list of allowed pascal compilers (jeey!). If you would like to use our product to push some limits then send us an email and we will return a preview version of smart (32bit) that you can use. You can use Smart as much as you want for the duration of the competition for free. While we are still in beta (with all the bells and whistles that pertains) there really is no compiler and IDE out there like Smart for webkit development!

Let’s push that border a couple of more inches, like pascal has always done 🙂

Click here for the pascal game developer’s website

About the author


Jon Lennart Aasenden is a software architect at Optimale Systemer AS. He is currently the lead developer of Smart Mobile Studio and have been a strong supporter of Delphi and object pascal since the beginning. He is also involved in the evangelizing of object pascal in Norway and is by many called “a Delphi fundamentalist” due to his somewhat radical teaching methods. The views of the author is his own and does not reflect the policy of Optimale Systemer AS.

delphi demo fpc freepascal game gamedev games javascript Object Pascal OP4JS Pascal scene

Retro demo coded in Smart

Posted on 30.03.2012 by Jon Lennart Posted in Developers log 2 Comments
Parallax scrolling galore

Parallax scrolling galore

This is a small retro demo I put together last weekend. Believe it or not but it doesn’t use the HTML5 canvas display at all. Everything you see moving on the screen are actually controls (which in this case inherits from the lightweight TW3MovableControl, which is the base-class TW3CustomControl builds on).

You can test-drive the demo yourself here: Parallax demo

qrcode

Features

  • parallax scrolling
  • alpha blending
  • scroll-text with bitmap fonts
  • 3d rotated logo
  • hardware accelerated transformations

Note: This is a webkit only demo, so it will only run under Chrome or Safari (also iPad and iPhone is supported, but lacks sound).

The source

352 lines of uber-messy code, just like the good old days on the Amiga 🙂

[sourcecode language=”delphi”]
unit Form1;

interface

uses w3system, w3graphics, w3ctrls, w3components, w3time,
w3forms, w3application, w3sprite3d, w3bmpfont;

const
CHAR_SIZE = 16;
CHARSET_FONT = ‘ !"#¤%&/{}=_-\[]0123456789:;(|)?*abcdefghijklmnopqrstuvwxyz’;

type

TMenuLogo = Class(TW3Sprite)
Private
mDown: Boolean;
protected
Procedure InitializeObject;override;
public
Procedure UpdateBehavior(Const TimeId:Integer);override;
End;

TMenuBackground01 = Class(TW3Sprite)
protected
Procedure InitializeObject;override;
public
Procedure UpdateBehavior(Const TimeId:Integer);override;
End;

TFront = Class(TW3Sprite)
protected
Procedure InitializeObject;override;
public
Procedure UpdateBehavior(Const TimeId:Integer);override;
End;

TForm1=class(TW3form)
private
{ Private methods }
{$I ‘Form1:intf’}
FLogo: TMenuLogo;
FBack01: TMenuBackground01;
FTimer: TW3Timer;
FCounter: Integer;
FMyFont: TKromaskyBitmapFont;
FCredits: TW3Image;
FFontDone:Boolean;
FChars: Array of TW3Sprite;
FReady: Array of TW3Sprite;
FScrolled:Float;
FText: String;
FCharIndex:Integer;
FAudio: Variant;
FFront: TFront;
Procedure HandleUpdate(Sender:TObject);
procedure setupChars;
protected
{ Protected methods }
Procedure InitializeObject;override;
Procedure FinalizeObject;override;
Procedure StyleTagObject;reintroduce;virtual;
Procedure Resize;Override;
Procedure FormActivated;override;
Procedure FormDeActivated;override;
end;

Implementation

//############################################################################
// TFront
//############################################################################

Procedure TFront.InitializeObject;
Begin
inherited;
setTransformFlags(CNT_USE_POS);
Background.fromURL(‘res/tile_ground.png’);
Width:=96 * 32;
height:=96;
Transparent:=True;
end;

Procedure TFront.UpdateBehavior(Const TimeId:Integer);
var
mRange: Integer;
Begin
mRange:=application.Display.View.Width;
mRange:=(mRange div 96) * 96;
if X<=-(mRange) then
X:=0.0;
MoveX(-1.5);
Update3d;
end;

//############################################################################
// TMenuBackground01
//############################################################################

Procedure TMenuBackground01.InitializeObject;
Begin
inherited;
setTransformFlags(CNT_USE_POS);
Background.fromURL(‘res/gamebg02.png’);
Width:=960 * 2;
height:=480;
end;

Procedure TMenuBackground01.UpdateBehavior(Const TimeId:Integer);
Begin
if X<=-960 then
X:=0;
MoveX(-0.80);
Update3d;
end;

//############################################################################
// TMenuLogo
//############################################################################

Procedure TMenuLogo.InitializeObject;
Begin
inherited;
setTransformFlags(CNT_USE_POS or CNT_USE_SCALE or CNT_USE_ROTY);
Width:=422;
Height:=57;
mDown:=True;
Update3d;

Transparent:=True;
background.fromURL(‘res/parallax.png’);
end;

Procedure TMenuLogo.UpdateBehavior(Const TimeId:Integer);
Begin
if (TimeId mod 3)=0 then
Begin
case mDown of
True:
Begin
if Y<20 then
Begin
MoveY(0.50);
end else
mDown:=False;
end;
false:
Begin
if Y>10 then
Begin
MoveY(-0.50);
end else
mDown:=True;
end;
end;
update3d;
end else
Begin
RotateY(-1);
update3d;
end;
end;

//############################################################################
// TForm1
//############################################################################

function getXforChar(aChar:String):Integer;
var
xpos: Integer;
begin
if length(aChar)>1 then
xpos:=pos(aChar[1],CHARSET_FONT) else
if length(aChar)=1 then
xpos:=pos(aChar,CHARSET_FONT) else
exit;
result:=CHAR_SIZE * (xpos -1);
end;

Procedure TForm1.InitializeObject;
Begin
inherited;
{$I ‘Form1:impl’}
StyleClass:=”;

FTimer:=TW3Timer.Create;
FTimer.Delay:=1;
FTimer.onTime:=HandleUpdate;

asm
@FAudio = new Audio();
(@FAudio).autoplay=true;
(@FAudio).src = "res/Last Ninja wastelands.mp3";
end;

FBack01:=TMenuBackground01.Create(self);
FLogo:=TMenuLogo.Create(self);
FFront:=TFront.Create(self);
FMyFont:=TKromaskyBitmapFont.Create;

FText:=’Welcome to 1990* This is a nice retro demo coded in ‘
+ ‘¤Smart Mobile Studio¤ Brought to you by Optimale Systemer AS ‘
+ ‘&&&&&&&& ‘;
FText:=lowercase(FText);
FCharIndex:=0;

Background.fromURL(‘res/ancientbg.png’);
w3_setStyle(tagRef,’background-repeat’,’repeat-x’);
w3_setStyle(tagRef,’background-size’,’auto 100%’);
End;

Procedure TForm1.FinalizeObject;
Begin
FLogo.free;
FBack01.free;
FFront.free;
inherited;
End;

Procedure TForm1.HandleUpdate(Sender:TObject);
var
x: Integer;
mSprite: TW3Sprite;
Begin
inc(FCounter);

FLogo.UpdateBehavior(FCounter);
FBack01.UpdateBehavior(FCounter);
FFront.UpdateBehavior(FCounter);

If FMyFont.Ready
and not FFontDone then
Begin
FFontDone:=True;
FCredits:=FMyFont.DrawAndMake(‘coded by quartex’);
FCredits.InsertInto(self.tagRef);
FCredits.Visible:=True;

FCredits.top:=Height – (FCredits.height + 10);
FCredits.left:=(Width div 2) – (FCredits.width div 2);
w3system.w3_Callback(self.resize,10);
end;

if length(FChars)>0 then
Begin
x:=-1;
repeat
inc(x);

mSprite:=FChars[x];
mSprite.moveX(-0.5);

if mSprite.x<=(-CHAR_SIZE) then
begin
FChars.Delete(x,1);
FReady.add(mSprite);
dec(x);
end else
mSprite.update3d;

until x>=high(FCHars);

end;

FScrolled+=0.5;
if FScrolled>=CHAR_SIZE then
begin
FScrolled:=0.0;
inc(FCharIndex);
if FCharIndex>Length(FText) then
FCharIndex:=1;

if FReady.length>0 then
begin
mSprite:=FReady[0];
FReady.Delete(0,1);
w3_setStyle(mSprite.tagRef,’backgroundPosition’,
‘-‘ + IntToStr(getXforChar(FText[FCharIndex])) +’px 0px’);
mSprite.x:=Width;
mSprite.y:=(Height div 2) – (CHAR_SIZE div 2);
mSprite.Update3d;
FChars.add(mSprite);
end;
end;
end;

procedure TForm1.setupChars;
var
cnt: Integer;
x: Integer;
mChar: TW3Sprite;
begin
if FChars.length<1 then
Begin
cnt:=width div CHAR_SIZE;
if (cnt * CHAR_SIZE) < width then
inc(cnt);
inc(cnt);

for x:=0 to cnt-1 do
Begin
mChar:=TW3Sprite.Create(self);
mChar.setTransformFlags(CNT_USE_POS);
mChar.background.fromUrl(‘res/fnt16x16.png’);

w3_setStyle(mChar.tagRef,’backgroundPosition’,’0px 0px’);
mChar.x:=-CHAR_SIZE * 2;
mChar.width:=CHAR_SIZE;
mChar.height:=CHAR_SIZE;
//mChar.color:=clRed;
mChar.Transparent:=True;
mChar.visible:=true;
mChar.update3d;
FReady.add(mChar);
end;
end;
end;

Procedure TForm1.FormActivated;
Begin
inherited;
setupChars;
FTimer.Enabled:=True;
end;

Procedure TForm1.FormDeActivated;
Begin
FTimer.enabled:=False;
inherited;
end;

Procedure TForm1.Resize;
var
dx: Integer;
Begin
inherited;
dx:=(width div 2) – (FLogo.width div 2);
FLogo.setBounds(dx,10,FLogo.Width,FLogo.Height);
FFront.setBounds(0,Height-FFront.height,FFront.width,FFront.height);
FBack01.top:=FFront.top – FBack01.height;
if FCredits<>NIl then
begin
FCredits.top:=Height – (FCredits.height + 10);
FCredits.left:=(Width div 2) – (FCredits.width div 2);
end;
end;

Procedure TForm1.StyleTagObject;
Begin
// Custom styling
End;

end.
[/sourcecode]

demo parallax

Sprite3d converted to Smart

Posted on 23.03.2012 by Jon Lennart Posted in Developers log 2 Comments

I am happy to report that the award winning HTML5 3d system Sprite3d has been converted to Object Pascal and will ship with Smart Mobile Studio. Sprite3d is a fantastic javascript library which allows you to perform advanced 3d transformations on ordinary HTML elements. Since CSS 3d is hardware accelerated both on mobile and desktop browsers -the results often outperform drawing graphics using the canvas object.

As an example of what you can do with Sprite3d have a look at the following demo (written by the Sprite3d author). Keep in mind that this is not webGL It uses nothing but CSS and javascript and all the objects are ordinary DIV tags.

Under Smart Mobile Studio, using Sprite3d to rotate a button in 3d-space is as simple as:

FSprite:=TW3Sprite3d.Create(button1);
try
  FSprite.SetTransformOrigin(button1.Width div 2, button1.height div 2);
  FSprite.RotateY(1.5);
  FSprite.RotateZ(-0.5);
  FSprite.Update3d;
finally
  FSprite.free;
end;

The exciting part is that you can apply these transformations to any Smart control. While it is highly doubtful that a spinning edit-box will be of much use in serious business applications, the effects could be leveraged as a means to add life to otherwise static interfaces (options that scale in/out, drop down lists that rotate on close, buttons that move as a response to touch) – and last but not least, it opens up for some interesting multimedia possibilities.

About the author


Jon Lennart Aasenden is a software architect at Optimale Systemer AS. He is currently the lead developer of Smart Mobile Studio and have been a strong supporter of Delphi and object pascal since the beginning. He is also involved in the evangelizing of object pascal in Norway and is by many called “a Delphi fundamentalist” due to his somewhat radical teaching methods. The views of the author is his own and does not reflect the policy of Optimale Systemer AS.

feature sprite3d sprites

Getting ready to rumble

Posted on 22.03.2012 by Jon Lennart Posted in Developers log 1 Comment

We are getting seriously close to a beta here now. Just a couple of more tweaks and some visual goodies and then it’s party time 🙂

Smart Mobile @ 98% complete

Smart Mobile @ 98% complete

I am of-course working overtime in the hope that we can ship the beta before next Friday, just in time for the Pascal game development competition. If you haven’t checked it out yet, visit PGD and have a look!

Debugging smart apps on your mac

Posted on 20.03.2012 by Jon Lennart Posted in Developers log, Documentation

If you happen to own a Mac computer, there is a cool trick i can teach you to make better Smart Mobile applications. It’s also a trick which can benefit native development. In short: the iPhone emulator that ships with Apple’s SDK have many hidden aspects and parameters. One of the most useful is an option to highlight GUI elements that iOS have marked for the GPU. This is a really cool feature and very helpful for both Firemonkey, C#, C++, FreePascal and (drumroll) Javascript apps.

Detecting hardware acceleration

First, make sure the Smart IDE is set to use the built-in server. Now simply load in a project (one of the demos for instance) and execute the application. The server window appears and displays the full URL of your app.

Smart running inside VMWare on a Mac

Smart running inside VMWare on a Mac

Second, go to your Mac and open up a new terminal window. The terminal is more or less what we call a command-line prompt under Windows. On the Mac the terminal is located at “/Applications/Utilities/Terminal”.

In the terminal window punch in the following to start the iPhone emulator with the “magic” setting:

[sourcecode language=”bash”]
CA_COLOR_OPAQUE=1 /Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app/Contents/MacOS/iPhone\ Simulator
[/sourcecode]

Note: The above should be a single line of text. Remove any formatting before pasting it into the terminal.

Punch in the commands and hit enter

Punch in the commands and hit enter

The iPhone emulator should now start up and you will notice that there is a red-tint covering different GUI elements. The elements which have a red tint are those marked for hardware acceleration.

Watching Smart go

Next, click on the safari icon to start Safari Mobile, and when loaded – punch in the URL to your running Smart application. Hit enter and wait for the application to load.

Once your app is safely running inside the iOS emulator, click the shortcut button and select “Add to home screen”. All Smart apps can run in full-screen directly from the iPhone screen – we don’t want to waste 30% of the screen on Safari.

Add the app to the home screen

Everything is HW accelerated here

Now you can start the app directly from the iPhone screen – and you can clearly see which components in your Smart app that uses hardware acceleration. It is also worth noting that elements turn red when they are cached and handled by the GPU. In our case the Buddha below does not turn red until you click the “spin the Buddha” button.

Click the button and hardware rotation takes over

Click the button and hardware rotation takes over

Marking your own controls

If you want to ensure that a custom control (or indeed, any TW3CustomControl descendant) makes use of hardware acceleration, there are two ways of achieving it. Both do the same thing and simply hints to the browser that it needs to cache the element in video memory rather than casual memory:

You can add the following to the control’s CSS:

[sourcecode language=”css”]
-webkit-transform: translateZ(0);
[/sourcecode]

Or, you can set the property directly in your code. Preferably by overriding the StyleTagObject method:

[sourcecode language=”delphi”]
Procedure TMyControl.StyleTagObject;
Begin
inherited;
w3_setStyle(tagRef,’webkitTransform’,’translateZ(0)’);
end;
[/sourcecode]

debugging how-to tips & tricks

Beta1, components and layout

Posted on 18.03.2012 by Smart Mobile Studio Team Posted in News 11 Comments

It’s a been a while since we published anything about Smart Mobile Studio, but that doesn’t mean we have been resting on our laurels. Quite the opposite. We have been busy with the final step of the project – namely the visual designer. We know that people have been waiting for our first beta release – and you will not be disappointed! So while we are tinkering on the final bits, here is a status report of what we have been up to.
Continue reading→

Pages

  • About
  • Feature Matrix
  • Forums
  • News
  • Release History
  • Download
  • Showcases
    • The Smart Contest 2013, Round 1 – Graphics
  • Store
  • Documentation
    • Creating your own controls
    • Debugging, exceptions and error handling
    • Differences between Delphi and Smart
    • Get the book
    • Getting started
      • Introduction
      • Local storage, session storage and global storage
      • Application architecture
      • The application object
      • Forms and navigation
      • Message dialogs
      • pmSmart Box Model
      • Themes and styles
    • Layout manager
    • Networking
      • Loading files
      • TW3HttpRequest
      • TW3JSONP
    • Prerequisites
    • Real data, talking to sqLite
    • System requirements
    • Project types
      • Visual project
      • Game project
      • Console project

Archives

  • December 2019
  • December 2018
  • November 2018
  • July 2018
  • June 2018
  • February 2018
  • September 2017
  • April 2017
  • November 2016
  • October 2016
  • September 2016
  • April 2016
  • March 2016
  • January 2016
  • October 2015
  • September 2015
  • July 2015
  • April 2015
  • January 2015
  • December 2014
  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • June 2014
  • March 2014
  • February 2014
  • January 2014
  • December 2013
  • November 2013
  • October 2013
  • August 2013
  • July 2013
  • June 2013
  • May 2013
  • April 2013
  • March 2013
  • February 2013
  • January 2013
  • December 2012
  • November 2012
  • August 2012
  • July 2012
  • June 2012
  • May 2012
  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • November 2011
  • October 2011
  • September 2011

Categories

  • Announcements (25)
  • Developers log (119)
  • Documentation (26)
  • News (104)
  • News and articles (16)

WordPress

  • Register
  • Log in
  • WordPress

Subscribe

  • Entries (RSS)
  • Comments (RSS)
© Optimale Systemer AS