Diddy - An Open Source Framework - Part 6

Monkey Programming Forums/User Modules/Diddy - An Open Source Framework - Part 6

therevills(Posted 2012) [#1]
Thread continued from here...

An Open Source Framework that includes a set of extra functions and APIs for the Monkey language.


Diddy includes the following modules:

* Easy to use Screen based framework
* Sprite class
* Resource managers for sounds and images
* A* Path finding
* XML parser
* Asserts
* Serialization
* Particles
* Collections
* Tweening
* GUI (Buttons, Sliders, Windows)
* Base64 encoding/decoding
* Tile Engine (Using the Tiled Map Editor)

Also includes extra functions:
http://code.google.com/p/diddy/wiki/NewCommands

Heaps of the examples are also included.


therevills(Posted 2012) [#2]
Diddy is currently being used as the main framework in the Community Project: Monkey Touch.


Origaming(Posted 2012) [#3]
framework.monkey
Sprite class
line
1580
1600

format_code('Method Draw:Void(offsetx:Float = 0, offsety:Float = 0, rounded:Bool = False)
if Not visible Then Return
...
Method DrawHitBox:Void(offsetx:Float = 0, offsety:Float = 0)
if Not visible Then Return
...')


therevills(Posted 2012) [#4]
Cheers Origaming, just added it. I must have forgotten to actually use it ;)


Origaming(Posted 2012) [#5]
framework.monkey
896
933
r490
format_codebox('Method LoadLibGdxAtlas:Void(fileName:String, midHandle:Bool=True, readPixels:Bool = False, maskRed:Int = 0, maskGreen:Int = 0, maskBlue:Int = 0)
...
gi.SetMask(maskRed, maskGreen, maskBlue)
...
Method LoadSparrowAtlas:Void(fileName:String, midHandle:Bool=True, readPixels:Bool = False, maskRed:Int = 0, maskGreen:Int = 0, maskBlue:Int = 0)
gi.SetMask(maskRed, maskGreen, maskBlue)
...')

gi.SetMaskColor


therevills(Posted 2012) [#6]
D'oh! Thanks Origaming!


Origaming(Posted 2012) [#7]
Request :
gamesounds, Pause and Resume


therevills(Posted 2012) [#8]
gamesounds, Pause and Resume

These arent in Monkey by default and it would mean altering Mojo, so you are best talking to Mark ;)


Origaming(Posted 2012) [#9]
audio.monkey already have
format_code('Function PauseChannel( channel )
device.PauseChannel channel
End

Function ResumeChannel( channel )
device.ResumeChannel channel
End')

because gamesounds record used channel, i add this to gamesound class
format_code('Method Pause:Void()
If IsPlaying() Then
PauseChannel(channel)
End
End

Method Resume:Void()
If IsPlaying() Then
ResumeChannel(channel)
End
End')


therevills(Posted 2012) [#10]
Ahhh channels... why did'nt you say :P

Shame the IsPlaying() doesnt work with Flash :(


Origaming(Posted 2012) [#11]
:( android to, already doing some test,
if Pause and resume while channel already finish playing music, android ok but flash will freeze.


jondecker76(Posted 2012) [#12]
I have a question on using the framework, as I'm starting to lay out the skeleton of my first app. I wanted to create a separate .monkey file for each screen to keep my code neat. My problem comes when wanting to switch from one screen to the next - my defined global is apparently out of scope. For example,. right now I'm simply trying to make an intro screen (for display of logo) that displays for 5 seconds, then goes on to the main menu screen.

Here is an example:

game.monkey:
format_code('
'Strict

Import diddy
Import screenTitle
Import screenMenu
Import screenGame


Global menuScreen:MenuScreen
Global titleScreen:TitleScreen
Global gameScreen:GameScreen
Global VIRTUAL_W = 1080
Global VIRTUAL_H = 1920

Function Main:Int()
New MyGame()
Return 0
End

Class MyGame Extends DiddyApp
Method OnCreate:Int()
Super.OnCreate()

#If TARGET="android"
SetGraphics(DeviceHeight(),DeviceWidth())
#Else
SetGraphics(480,853)
#end


SetScreenSize(VIRTUAL_W,VIRTUAL_H, True) ' Virtual resolution! Respect aspect ratio last parameter
LoadImages()
titleScreen = New TitleScreen
menuScreen = new MenuScreen
gameScreen = new GameScreen
defaultFadeTime = 300
game.Start(titleScreen)
Return 0
End

Method LoadImages:Void()
' Load in our screen images
images.Load("title.png","", False)

' Load in our dice images
images.Load("1.png", "", False)
images.Load("2.png", "", False)
images.Load("3.png", "", False)
images.Load("4.png", "", False)
images.Load("5.png", "", False)
images.Load("6.png", "", False)
End
End
')


screenTitle.monkey: (error is in here!)
format_code('
Import diddy



Class TitleScreen Extends Screen
Field title:GameImage
Field ts:Int

Method New()
name = "Title"
End

Method Start:Void()
title=game.images.Find("title")
game.screenFade.Start(300, False)
ts=Millisecs()
End

Method Update:Void()
If ts<Millisecs()-3000
game.screenFade.Start(300, True, True, True)
game.nextScreen = menuScreen ' <-------- menuScreen is out of scope!
End If
End

Method Render:Void()
' Both rendering and fading are affected by virtual resolution
DrawImage(title,0,0)

End
Method ExtraRender:Void()
' Render isn't affected by virtual resolution, but fading is
End
Method DebugRender:Void()
' Neither render nor fading are affected by virtual resolution

end


End
')


screenMenu:
format_code('
Import diddy



Class MenuScreen Extends Screen
Method New()
name = "Menu"
End

Method Start:Void()

End

Method Update:Void()

End

Method Render:Void()
' Both rendering and fading are affected by virtual resolution
End
Method ExtraRender:Void()
' Render isn't affected by virtual resolution, but fading is
End
Method DebugRender:Void()
' Neither render nor fading are affected by virtual resolution

End


End
')

... etc

Is there a way to cleanly do this in diddy using screens? I guess I could put all of the screen classes in one master screen.monkey file and define the global handles there, but I'd really prefer a cleaner layout like I'm trying here. Is there something built-in, or do I need to add something custom in my class?


therevills(Posted 2012) [#13]
You need to import game in your screen monkey files :)

Also I noticed that you are moving between screens the "old" way:

game.monkey:
[monkeycode]Strict

Import diddy
Import gamescreen
Import titlescreen

Global gameScreen:GameScreen
Global titleScreen:TitleScreen

Function Main:Int()
New MyGame()
Return 0
End

Class MyGame Extends DiddyApp
Method OnCreate:Int()
Super.OnCreate()
gameScreen = New GameScreen
titleScreen = New TitleScreen
Start(titleScreen)
Return 0
End
End[/monkeycode]

titlescreen.monkey:
[monkeycode]Import diddy
Import game

Class TitleScreen Extends Screen
Method New()
name = "Title"
End

Method Start:Void()
End

Method Update:Void()
If KeyHit(KEY_SPACE)
FadeToScreen(gameScreen)
End
End

Method Render:Void()
Cls
DrawText ("TITLE SCREEN", 100, 100)
End
End[/monkeycode]

gamescreen.monkey:
[monkeycode]Import diddy
Import game

Class GameScreen Extends Screen
Method New()
name = "Game"
End

Method Start:Void()
End

Method Update:Void()
If KeyHit(KEY_SPACE)
FadeToScreen(titleScreen)
End
End

Method Render:Void()
Cls
DrawText ("GAME SCREEN", 100, 100)
End
End[/monkeycode]


Volker(Posted 2012) [#14]
Is there a way to cleanly do this in diddy using screens?

You need to import game in your screen monkey files :)

This could be called a cleanly way, indeed.


jondecker76(Posted 2012) [#15]
Thank you both, very helpful!


jondecker76(Posted 2012) [#16]
Hmm.. I just got home and installed monkey-ext_64, added diddy and the mojo module from Monkeyv63b.

For some reason, monkey_ext + mojo on linux doesn't work - I get an error

format_code('Syntax error - unexpected token ':'')
in framework.monkey, line 194 (Catch e:DiddyException)

All the standard linux examples are working fine on this setup. Any ideas what the problem may be?

Looks like I might have to set up a Windows VM :(


therevills(Posted 2012) [#17]
Can you try removing the Try Catch statements? I'm pretty sure its a Monkey bug with Linux...


jondecker76(Posted 2012) [#18]
You seem to be correct.

I had to comment out all the Try/Catch logic in framework.monkey. For example:
format_code('
Method OnResume:Int()
'Try
dt.currentticks = Millisecs()
dt.lastticks = dt.currentticks
currentScreen.Resume()
'Catch e:DiddyException
' Print(e.ToString(True))
' Error(e.ToString(False))
'End
Return 0
End
')

I also had to comment out the Throw line in assert.monkey:
format_code('
'summary: Assert Error, outputs the error of the assertion
Function AssertError:Void(msg:String)
'Throw New AssertException(msg)
End
')


After that, everything works like a champ, thanks!

Any idea where the bug may be for a permanent fix?


jondecker76(Posted 2012) [#19]
One other thing:

I tried to Import game at the top of my screen includes (per the recommendation a few posts up), but I get an error
format_code('
Module 'game' not found
')


therevills(Posted 2012) [#20]
Any idea where the bug may be for a permanent fix?

No idea I dont mess with Linux, ask on the Monkey-ext thread hopefully Samah or fsoft can help.

but I get an error

Strange... wonder if this is an issue with Monkey-ext, are you using the MODULE_PATH stuff?


jondecker76(Posted 2012) [#21]
No module path stuff, simply installed monkey-ext, copied in diddy & threading module, and copied in the mojo module.

Should I set up monkey v63, install diddy there, then use the middle path stuff from monkey-ext ? If so, where do I put the module path statement?


therevills(Posted 2012) [#22]
I would try to get your error fixed before trying the MODULE_PATH stuff (you would add it to the config.winnt.txt).

Again this sounds like a Linux bug.


therevills(Posted 2012) [#23]
Small Change in the set up of Diddy!

We have added the method Create to the Diddy app, please use this in future instead of overwriting OnCreate:

[monkeycode]Class MyGame Extends DiddyApp
Method Create:Void()
titleScreen = New TitleScreen
Start(titleScreen)
End
End[/monkeycode]

This change allows exceptions to be caught correctly and it saves you a few lines of typing ;)

Your current code should still work as normal, but the exceptions might not be caught correctly and it will give you a Monkey Uncaught Exception instead of a Diddy Exception.

All examples have been updated to reflect this change. (Hopefully)


jondecker76(Posted 2012) [#24]
I just tried to "Import game" on a windows box with a fresh monkey install and fresh Diddy install. I still get the error that Module 'game' not found. There is no 'game' module in the modules directory either.

WHere am I supposed to get this 'game' module?


EDIT
Oh jeez - never mind, its not a game module, but the game source file (mine is named differently, which is of course why it didn't work).

The cyclic include thing is a little odd for me, but I'll just go with it!


therevills(Posted 2012) [#25]
LOL! I said Import game as that what your example had :P

Yeah the cyclic imports are a bit different. Least you've sorted it :)


jondecker76(Posted 2012) [#26]
Sorry for all the questions, but I'm finally getting somewhere with this.

I'm using a virtual resolution. How can I get appropriately scaled MouseX/MouseY,TouchX/TouchY values?


therevills(Posted 2012) [#27]
Use: game.mouseX and game.mouseY

Basically all these do is the following:
[monkeycode]mouseX = MouseX() / SCREENX_RATIO
mouseY = MouseY() / SCREENY_RATIO[/monkeycode]


Midimaster(Posted 2012) [#28]
hi Therevilles,

sorry for the delay, but I hadn't the time to answer to #99 and #100 of the past diddy thread (part 5) ....

2 weeks ago I thought I did found a bug with CONST VERTICAL%, but now I see, you are right: I cannot simultate this error again. Maybe it was a mistake of mine.


therevills(Posted 2012) [#29]
sorry for the delay

No worries Midi :)

-----------

Introducing DiddyData

Samah and I have been coding for quite a few years now and we are pretty tired of all the boiler plate code you sometimes (always!) have to write. This is one of the main reason I love BlitzMax and Monkey since it removes so much of it in the first place.

But no matter what the language you use, you still seem to have to write some, this is where DiddyData comes in.

DiddyData uses a simple command (LoadDiddyData) to load an xml file (diddydata.xml), which sets up your screen size, loads your resources (images and sounds) into the banks and instantiates screens for you.

This is very much work-in-progress!

Here is an example:
format_codebox('Strict

Import reflection
Import diddy

Function Main:Int()
New MyGame()
Return 0
End

Class MyGame Extends DiddyApp
Method Create:Void()
debugOn = True
LoadDiddyData()
Start(screens.Find("Title"))
End
End

Class TitleScreen Extends Screen
Method Start:Void()
End

Method Render:Void()
Cls
DrawText("Press SPACE to Play", SCREEN_WIDTH2, SCREEN_HEIGHT2, 0.5, 0.5)
End

Method Update:Void()
If KeyHit(KEY_SPACE)
FadeToScreen(game.screens.Find("Game"))
End
End
End

Class GameScreen Extends Screen
Field sprite:Sprite
Field background:GameImage
Field sound:GameSound

Method Start:Void()
sprite = New Sprite(game.images.Find("Ship"), SCREEN_WIDTH2, SCREEN_HEIGHT2)
background = game.images.Find("bg_1_1")
sound = game.sounds.Find("fire")
End

Method Render:Void()
Cls
background.Draw(0, 0)
sprite.Draw()
End

Method Update:Void()
If KeyDown(KEY_SPACE)
sound.Play()
End
If KeyHit(KEY_ESCAPE)
FadeToScreen(game.screens.Find("Title"))
End
End
End')

Using the following XML:
format_codebox('<diddy screenWidth="800" screenHeight="600" useAspectRatio="true">
<resources>
<images>
<image path="sprites/Ship1.png" name="Ship" width="64" height="64" frames="7" />
<image path="backgrounds/bg_1_1.png" midhandle="false" />
</images>
<sounds>
<sound path="Firelaser" name="fire" soundDelay="100" ignoreCache="false" />
</sounds>
</resources>
<screens>
<screen class="TitleScreen" name="Title" />
<screen class="GameScreen" name="Game" />
</screens>
</diddy>')


Compared to the "old" way:
format_codebox('Strict

Import diddy

Global titleScreen:TitleScreen
Global gameScreen:GameScreen

Function Main:Int()
New MyGame()
Return 0
End

Class MyGame Extends DiddyApp
Method Create:Void()
debugOn = True
SetScreenSize(800, 600, True)
titleScreen = New TitleScreen
gameScreen = New GameScreen
LoadImages()
LoadSounds()
Start(titleScreen)
End

Method LoadImages:Void()
Local tmpImage:Image
images.LoadAnim("sprites/Ship1.png", 64, 64, 7, tmpImage, True, False, "Ship")
images.Load("backgrounds/bg_1_1.png", "", False)
End

Method LoadSounds:Void()
sounds.Load("Firelaser", "fire", False, 100)
End
End

Class TitleScreen Extends Screen
Method New()
name = "Title"
End

Method Start:Void()
End

Method Render:Void()
Cls
DrawText("Press SPACE to Play", SCREEN_WIDTH2, SCREEN_HEIGHT2, 0.5, 0.5)
End

Method Update:Void()
If KeyHit(KEY_SPACE)
FadeToScreen(gameScreen)
End
End
End

Class GameScreen Extends Screen
Field sprite:Sprite
Field background:GameImage
Field sound:GameSound

Method New()
name = "Game"
End

Method Start:Void()
sprite = New Sprite(game.images.Find("Ship"), SCREEN_WIDTH2, SCREEN_HEIGHT2)
background = game.images.Find("bg_1_1")
sound = game.sounds.Find("fire")
End

Method Render:Void()
Cls
background.Draw(0, 0)
sprite.Draw()
End

Method Update:Void()
If KeyDown(KEY_SPACE)
sound.Play()
End
If KeyHit(KEY_ESCAPE)
FadeToScreen(titleScreen)
End
End
End')

We plan on adding menus to the xml and various other goodies to save time writing boiler plate code :)

And in the future another bonus when using DiddyData is that you can change the xml file after compiling your code (in the build folder) and if you set up a key hit to reload the diddydata you should see your new changes straight away without recompiling.


jondecker76(Posted 2012) [#30]
Very very cool, I'll give this a try in my current project


jondecker76(Posted 2012) [#31]
What is your current recommendation for installing Diddy? I simply downloaded the zip file (which hasn't been updated since Aug 30)

Is it generally safe to just SVN CO the trunk and run an svn update every now and then?


therevills(Posted 2012) [#32]
If you want the latest and greatest go for the SVN, if you want "stable" go for the zip ;)


Samah(Posted 2012) [#33]
So, I've been thinking about migrating Diddy to Mercurial. What's people's opinions on this? It's fairly trivial to convert the entire repository and retain revision history.

I'm curious as to how many people it would affect, since I'm sure only a small percentage of our user base actually uses the repository; most of you probably just download the latest zip.

I don't want a Subversion vs Git vs Mercurial flame war, I'd just like to know how many of you will care.


c.k.(Posted 2012) [#34]
+1 hg


Halfdan(Posted 2012) [#35]
First of diddy is really great!
But it lacks some documentation so I will just ask here:
What format fonts does the Font class use? (I dont recognize the xml data).


therevills(Posted 2012) [#36]
What format fonts does the Font class use? (I dont recognize the xml data).

Samah designed his own format, to generate the xml you can use the FontBuilder util:
http://code.google.com/p/diddy/source/browse/trunk/utils/fontbuilder/FontBuilder.java


Halfdan(Posted 2012) [#37]
Wo that is cool , diddy is very complete.. the time it would take to write all this myself :)


TheRedFox(Posted 2012) [#38]
Nice update. Suffering through getting music working back as I had a method with the same signature (SetMusic) and fades where handled the old way + PreStart... Damn, can't we get refactoring over here ? ;-)


Rushino(Posted 2012) [#39]
Nice ! Seeing an A* pathfinding ! :)


dragon(Posted 2012) [#40]
Request: are you interested to add this functions to diddy?

GetDPIFactor()
GetDPIX()
GetDPIY()

http://developer.android.com/reference/android/util/DisplayMetrics.html#density

http://stackoverflow.com/questions/3860305/get-ppi-of-iphone-ipad-ipod-touch-at-runtime


Origaming(Posted 2012) [#41]
IOS build
http://www.monkeycoder.co.nz/Community/posts.php?topic=3635

double mouseZ
function.monkey
40,41
86,88


therevills(Posted 2012) [#42]
@dragon,

Looks good I'll add them on the weekend.

@Origaming and RedFox... what the hell was I thinking!? I guess I wasnt going to add the empty stubs in the native code... I've just removed that wrapped iOS block.


byo(Posted 2012) [#43]
Hi.

First of all, what an amazing module, full of features. Thank you.

The 'Animation' example doesn't work with Monkey v65.
Also the 'pathfinding' example shows the error below once the ball reaches the end of the path: "Monkey Runtime Error: Array out of range".
Using Chrome BTW.

Best regards,

Andre Guerreiro Neto


therevills(Posted 2012) [#44]
Hi Andre, both those examples work fine here on v65 and Chrome.


Origaming(Posted 2012) [#45]
animation works well,,
yup pathfind error if the ball reached the end.
line 142
format_code('If PathFinder.route.Length() > 0 And currentPath >0 Then')
I also add a Reset
line 114
format_code('If KeyHit(KEY_R)
'reset
x = 0
y = 0
For fy = 0 Until MAP_HEIGHT
For fx = 0 Until MAP_WIDTH
grid[fx + fy * MAP_WIDTH] = 0
Next
Next
PathFinder.route = PathFinder.route.Resize(0)
PathFinder.paths = 0
EndIf')


therevills(Posted 2012) [#46]
Strange, it doesnt crash/error on mine. It displayes the following when the ball reaches the end:

format_code('currentPath = undefined, undefined')

I'll add the check though...


Origaming(Posted 2012) [#47]
while reached the end:
currentPath = -2
format_code('DrawText "currentPath = " + PathFinder.route[currentPath] + "," + PathFinder.route[currentPath + 1], SCREEN_WIDTH, 30, 1')
error caused by PathFinder.route[-2] and PathFinder.route[-1]


therevills(Posted 2012) [#48]
Yeah I understand why you guys are getting the crash, but I find it strange it doesnt crash here.


Midimaster(Posted 2012) [#49]
@therevills:

I see in the diddy.android.java source, that you have also a function to show the android virtual keyboard. But for a proper use in germany, we would need to aproach the german umlauts ÄÖÜ, which I normaly get with long pressing at the "U" then android opens a second small blue window with special characters. Do you see a way to call the keyboard and get this second window?


Origaming(Posted 2012) [#50]
release mode, undefined,
normally when test an example we using debug mode,


byo(Posted 2012) [#51]
@therevills: I'm not sure it's a mistake on my part but the "animation" example shows mw the error below as soon as it starts:

Monkey Runtime Error: ReferenceError:
CFG_OPENGL_GLES20_ENABLED is not defined


Best regards,

Andre Guerreiro Neto


therevills(Posted 2012) [#52]
@Midimaster - I really should remove the function to show the keyboard since Monkey/Mojo can do that for you now. My guess is that the keyboard Diddy is displaying doesnt have that option to display the second window.

@Origaming - Yeah I thought it might be an issue between debug and release, but I did test both... nevermind eh :)

@byo - Diddy doesnt use the OpenGL module, so I dont know whats happening there...


Origaming(Posted 2012) [#53]
@therevills yup, debug and release
@byo delete build folder


byo(Posted 2012) [#54]
@Origaming: it worked like a charm. Thank you. ;-)
@threvills: see above. Thank you for your reply.

Best regards,

Andre Guerreiro Neto


Rushino(Posted 2012) [#55]
Getting some problems when trying to include 'diddy'. Ive added the diddy folder in G:/Programmes/MonkeyPro64b/modules and it cannot see it.

Any one have an idea why ?

G:/Programmes/MonkeyPro64b/modules/diddy/examples/GUI/testGUI.monkey<3> : Error : Module 'diddy' not found.
Done.

Thanks!

EDIT: Nevermind... got it fixed. :)


Samah(Posted 2012) [#56]
So I've added a simple storyboarding module. It currently handles position, scale, alpha, rotation, colour, and looping (although I need to test looping).

Storyboards are defined in an xml format, and use GameImages as the sprite image. You can have multiple sprites using the same image. Check out the example. You can hit spacebar to toggle pause/play, and click+drag to move the time position.

Get the tip from the Hg repo (either branch) or the latest SVN checkin.


TheRedFox(Posted 2012) [#57]
Got it! Very nice as I used to do all that timeline thing with code. One chore less.

Maybe double-touch drag would be great for iOS. I'll look into that :-)


Samah(Posted 2012) [#58]
If I make an editor it'll most likely be an external program.

Some more changes pushed, when you're ready. :)


TheRedFox(Posted 2012) [#59]
Hey, threading is cool too, just discovered it :-) Any doc around that?


Samah(Posted 2012) [#60]
Any doc around that?

Not yet, sorry, but it's just standard pthread-style threading. It's very similar to threading in BlitzMax.


TheRedFox(Posted 2012) [#61]
Fine, I'll get some education then :-) I do not have BlitzMax, got stuck with B3D :-)


TheRedFox(Posted 2012) [#62]
Fine, I'll get some education then :-) I do not have BlitzMax, got stuck with B3D :-)


Samah(Posted 2012) [#63]
By the way, I just tried out the storyboard example on retina iPad. It's soooooooooo nice. :D
Just need higher quality images and it'll be perfect. ;)

Edit: It looks pretty awesome having an iPad and an Android tablet running it side by side. <3 Monkey.


Samah(Posted 2012) [#64]
I just added sound support to the storyboard, updated SVN with the latest Hg commit, and uploaded a new zip file.

Edit: Added support for special effects like fullscreen flashes (no more white sprites with scripted alpha values).

Edit 2: Refactored to use keyframes rather than transformations.


TheRedFox(Posted 2012) [#65]
Storyboard looks sweet :-)

Something crossed my mind and it may even be "easy" (well, kind of) to add: particles.

As the pSystem is already in Diddy, this would definitely add pizzaz to the storyboard and allow to tell fairytales pretty easily...


Samah(Posted 2012) [#66]
I might look at particles later. This is my current TODO list:

* More scripted effects (fullscreen fading, etc.)
* Music (no seeking, unfortunately)
* Editor! (Yes, I will actually make one...)

Now that it uses keyframes, an editor should be way easier to develop. I'm kinda going with a layout similar to the osu! storyboard editor.

Any more feature suggestions?

Anyway, here's how the keyframe system currently works:
The <sprite> tag contains the default values for the sprite, as if you had a keyframe for each type at time=0. Each child tag defines a new keyframe for that type, at a given time, with a given tween/ease setting. When deciding what values to give a sprite, it does this:

1) Loop through all the keyframes in a sprite until it finds (for each keyframe type) the keyframe both before and after the current time.

2) If we couldn't find a "previous" keyframe, it must be the first keyframe (or there are no keyframes for this type). In this case we just use the default values in the <sprite> tag.

3) If we found a "previous" keyframe, but no "next" keyframe, we must have gone past the final keyframe. In this case we use the values for the final keyframe.

4) If we found both a "previous" and "next" keyframe, we check the tween setting for the "next" keyframe. If tweening is disabled, we use the value from the previous keyframe. If it's enabled, we interpolate from the previous to the next, using the ease setting from the next keyframe.

5) Regardless of keyframes, sprites are rendered whenever their alpha is > 0. When you no longer want to display a sprite, just set its alpha to 0 and it will be skipped. If you ALWAYS want to display a sprite (like for a background) set its alpha to > 0 in the <sprite> tag and define no keyframes.

This is all subject to change, but I'm much happier with the keyframe system over the start/end transition system.


Samah(Posted 2012) [#67]
Just added a SeekMusic command to jump to any point in a music file if it's playing. Call PlayMusic first, then SeekMusic with a time in milliseconds.

Due to platform limitations, SeekMusic won't work on XNA or PSM, but all other targets are implemented and tested.


TheRedFox(Posted 2012) [#68]
I find that the storyboard is also perfect for crafting help screens that hold water (one of my use cases)


Samah(Posted 2012) [#69]
Glad to see someone's finding it useful :)
I'm working SeekMusic into it so that you can theoretically jump to any part of the storyboard and the music will be at the right position.

Edit: I've integrated SeekMusic into the storyboard, so you should be able to jump to any spot in your storyboard and the music will be at the correct time.

Note that I had to do a nasty try/catch hack in HTML5 since the audio object is not immediately added to the DOM when you call PlayMusic.


TheRedFox(Posted 2012) [#70]
Cool, this allows to provide explanations that are in sync with the text.

Would it be possible to have some kind of multilingual support? How would you see such an implementation?

There are often cases where the length of an explanation in one language is not the same as another.

Maybe the best is to use several storyboards (possibly refrerring to a master one for the resources list).

Your take?


Samah(Posted 2012) [#71]
Well there's an internationalization module in Diddy that you could use. I might be able to integrate that into the storyboard somehow, but it's going to require one or more new features:

1) Add drawtext/fontmachine support, and specify the language to use (fairly easy, I should think), or
2) Add logic (if/else) to storyboards... ARGH!

I was planning on creating a new tag like <sprite> but for <text>, so you can include text within your layers, and apply transformations to it. The XML format should be considered very volatile at the moment. For the most part, any changes I make should be fairly trivial to edit by hand.

Note that you can't seek sounds played with PlaySound, only music.


therevills(Posted 2012) [#72]
BTW I've updated my Platformer application here on MonkeyCoder to be the platformer example from Diddy:

http://www.monkeycoder.co.nz/Community/topics.php?forum=1047&app_id=47


Also I am in the process of tidying up the functions.monkey by removing the externs commands into externfunctions.monkey.


TheRedFox(Posted 2012) [#73]
Well, I do use I18N() for all of my texts already. Works very well. Thanks for making it available.

It was more about having several music files and transition timings for multiple languages.

All resources can stay the same (sprites, background music, ...) but no the transition timings.

A bit like having a parent POM in Maven (as you are a Java guy as well), we'd have a parent storyboard XML imported into the actual language-related storyboard.

Nothing I can't handle with a template or two at the moment, but it is always better if it is out of the box.


andrew_r(Posted 2012) [#74]
As of last night, the latest SVN update drop was missing the base64 file. I worked around this by pulling the zip from the google code page, but that complained about Interpolate being defined in two places; StoryBoard and the main code file (Functions?).
Anyway, I did a search and replace of Interpolate with Interpolate2 in Storyboard to "fix" it.

I'm not sure if the svn repository is missing the base64 file *and* the zip file is screwed, but it seems unlikely... More likely I've screwed something up. I thought I'd let you know just in case it's something on your end :)


therevills(Posted 2012) [#75]
@Andrew, you didnt do anything wrong it looks like we were out of sync between Hg and SVN. I've just done a bulk commit to SVN so it is now up to date. Thanks for letting us know :)


andrew_r(Posted 2012) [#76]
I'm still getting this:

C:/Tools/MonkeyPro/modules/diddy/psystem.monkey<2062> : Error : Duplicate identifier 'Interpolate' found in module 'storyboard' and module 'functions'.


smilertoo(Posted 2012) [#77]
diddy framework doesn't appear to work on windows phone7, every example i tried failed with namespace name 'WebBrowserTask' could not be found errors.


Samah(Posted 2012) [#78]
@andrew_r: Duplicate identifier 'Interpolate' found in module 'storyboard' and module 'functions'.

Looks like there's a clash in storyboard. I'll move that into functions when I get a chance.

Edit: Done. Just update to the latest SVN or Hg version.

Edit 2: I cleaned up the Base64 module too.


rickomax(Posted 2012) [#79]
Hey, I found a bug reading XML files with Diddy.

If I have a tag like this:
format_code('<Animation />')

The parser return the tag name as:
format_code(''Animation '')

See the whitespace at the end of the string?


andrew_r(Posted 2012) [#80]
It looks like the ReadPixels function doesn't work properly if a translation has been applied followed by a push matrix.

This modification fixes it for my use, but it doesn't take into account anything other that translation.
I thought I'd let you know so you can take it into account for future releases.
format_code('
Method ReadPixelsArray:Void()
Cls 0, 0, 0
Local posX:Int = SCREEN_WIDTH2
Local posY:Int = SCREEN_HEIGHT2
'MODIFICATION START (single translation only, followed by pushmatrix)
Local m:= GetMatrix()
Local offX:Int = m[4]
Local offY:Int = m[5]

DrawImage Self.image, posX - offX, posY - offY
' MODIFICATION END

If readPixels
ReadPixels(pixels, posX - image.HandleX(), posY - image.HandleY(), image.Width(), image.Height())
readPixelsComplete = True
PixelArrayMask(pixels, maskRed, maskGreen, maskBlue)
End
End
')

Andrew


smilertoo(Posted 2012) [#81]
Are there any plans to fix diddy to work on windows phone 7?


CopperCircle(Posted 2012) [#82]
It does work on WP7 just remove the WebTask code in VS. It is to do with the LaunchBrowser function.


Samah(Posted 2012) [#83]
Thanks, rickomax. I've not encountered this before because I've never used a self-closing tag with no attributes.


therevills(Posted 2012) [#84]
@andrew_r - yeah I hate matrix maths and it was only really quickly done to see how well the new Read/Write pixels stuff worked ;)

@smilertoo & CopperCircle, what happens with WP7? Is there anything we can remove/fix/wrap to make it work without you altering the "WebTask" code? (Whats is the WebTask code?)

@Samah - I'm still breathing, but its hard work :P


andrew_r(Posted 2012) [#85]
@therevills

Well, I don't particularly need scaling in this instance, but If I happen to come up with a patch that includes scaling and takes into account *all* of the matrix operations I'll post it.

Depending on how matrix stacks are implemented, it'll either be a pain in the ass, or completely trivial.

Andrew


smilertoo(Posted 2012) [#86]
every example i tried failed with namespace name 'WebBrowserTask' could not be found errors. The errors are always the same few lines that can remarked out, but it would be nice not to have to do that each time.

The WINDOWS_PHONE sections fail.


public static void launchBrowser(String address, String windowName)

{
#if WINDOWS
System.Diagnostics.Process.Start(address);
#elif WINDOWS_PHONE
WebBrowserTask webBrowserTask = new WebBrowserTask();
webBrowserTask.Uri = new Uri(address, UriKind.Absolute);
webBrowserTask.Show();
#endif

}


public static void launchEmail(String email, String subject, String text)
{
#if WINDOWS
string message = string.Format("mailto:{0}?subject={1}&body={2}",email, subject, text);
System.Diagnostics.Process.Start(message);
#elif WINDOWS_PHONE
EmailComposeTask emailComposeTask = new EmailComposeTask();

emailComposeTask.Subject = subject;
emailComposeTask.Body = text;
emailComposeTask.To = email;

emailComposeTask.Show();
#endif
}


therevills(Posted 2012) [#87]
@andrew_r - Please do :)

@Smilertoo - I added that code when Volker told me here that the LaunchBrowser and LaunchEmail didnt work in the WP:

http://www.monkeycoder.co.nz/Community/post.php?topic=2995&post=35032

http://www.monkeycoder.co.nz/Community/post.php?topic=2995&post=35045

I did state I had not tested the code though ;)


Samah(Posted 2012) [#88]
@rickomax: I've fixed the XML parser. Get the latest version from Bitbucket.


CopperCircle(Posted 2012) [#89]
I will post some working WP7 LaunchBrowser code as soon as I create the WP7 version of my current project. (couple of days)


Belimoth(Posted 2012) [#90]
Samah and I have been coding for quite a few years now and we are pretty tired of all the boiler plate code you sometimes (always!) have to write. This is one of the main reason I love BlitzMax and Monkey since it removes so much of it in the first place.


That's a great idea, will there be a tool to generate these xml files? In my framework I have a monster of an abstraction to handle loading resources, but if you supply the xml tool I will just abandon it and extend Diddy classes instead.

Also I had a question about your image bank system in general. How well does it get along with images that have the same filename but are in different folders?


therevills(Posted 2012) [#91]
will there be a tool to generate these xml files?

Maybe... Samah loves writing these type of tools ;)

How well does it get along with images that have the same filename but are in different folders?

Not very well. The bank stores the image via the filename as the key, so if you have the same filename it will overwrite the existing image.


Belimoth(Posted 2012) [#92]
Okay, good to know.


Amon(Posted 2012) [#93]
Downloaded the latest version from bitbucket and when testing on Android ( Samsung Galaxy S3 ) I can no longer get diddy working with it.

All I get is a blank screen and a few seconds later an error pops up stating Monkey Game has Stopped Working.

I am using the basic framework code from the examples folder for testing purposes and it refuses to work.

Any ideas to help diagnose where it borking or where I'm making it bork?

[edit]
running 4.1.1 android version. Samsung Galaxy S3 Unlocked, rooted but fully updated.


therevills(Posted 2012) [#94]
Do any of the Monkey examples work? I know that there is an issue with Monkey and Android 4.2 (and Mark has suggested a fix in the downloads section)...


Amon(Posted 2012) [#95]
Just gone through most of the examples and all the ones I've tried work. I tried a few of my other projects that don't use Diddy but use other frameworks i.e. Playniax Framework, fantomEngine etc and they all work.

Something in Diddy is definitely causing the problem.

I'm already using the fix from the downloads area.

[edit]if by examples you mean Monkey Examples not diddy examples then yes those work. I'll go through some of the diddy examples now to see if they work and will report back.


Amon(Posted 2012) [#96]
Ok! Going through the few Diddy examples I went through they all work except the framework one. That one causes the error. Stumped!!!


therevills(Posted 2012) [#97]
I'll have a look tonight.

I have recently done a change to Pirate Tripeaks which uses the Diddy Framework and that works fine on my Nexus 7 (4.2), could you try it on your device?

https://play.google.com/store/apps/details?id=com.therevillsgames.piratesolitairetriPeaks&hl=en


Amon(Posted 2012) [#98]
Opps! Sorry I took so long to report back. Was engrossed in the game. :)

Pretty cool game there dude!

Yep, can confirm it works.


Amon(Posted 2012) [#99]
I managed to get an error code and other which points to DEVICE_WIDTH in framework.monkey.

format_code('
Monkey Runtime Error : Error: Error #1023

C:/Apps/Coding/MonkeyPro66/modules/diddy/framework.monkey<176>
D:/Coding/Monkey/test.monkey<16>
')


therevills(Posted 2012) [#100]
Thanks Amon... how did you get that message?

Could you try this:
framework.monkey - Line 176: Replace this
format_code('DEVICE_WIDTH = DeviceWidth()') with this:
format_code('Local dw:Float = DeviceWidth()
DEVICE_WIDTH = dw')


Amon(Posted 2012) [#101]
Hi! I got the message by compiling to flash then mouse clicking and tapping the keyboard like a LunaticNinja. Only reason is because I could see something show up so when I started randomly clicking etc it displayed a bluescreen in the chrome browser with the error message.

Tried to implement what you asked but it still displays the error but points to :
format_code('
Local dw:Float = DeviceWidth()
')

on line 176. There is an extra line it shows now pointing to line 204 which is:
format_code('
Create()
')


therevills(Posted 2012) [#102]
Very strange... DeviceWidth is a Mojo command. I'll check it out tonight... can you try bananas\mak\bouncyaliens as I know that example uses DeviceWidth...


Amon(Posted 2012) [#103]
I noticed DeviceWidth in bouncyaliens, which works on all targets, doesn't have the '()'!

???


therevills(Posted 2012) [#104]
The "()" is because we use Strict mode... if you add () it shouldnt make a difference...


therevills(Posted 2012) [#105]
Samah spotted the error straight away with that example... it had an infinite loop in there. I've pushed the fix to Hg.


Amon(Posted 2012) [#106]
Lovely! Was it the ScreenFading?


therevills(Posted 2012) [#107]
Nope, we had a Super.OnCreate in the Create method for that example... and DiddyApp calls Create in OnCreate, so it keeps calling each other and finally the targets gives up... D'oh!


Volker(Posted 2012) [#108]
Whats the best free texture packer tool to use with diddy atlas?


therevills(Posted 2012) [#109]
Whats the best free texture packer tool to use with diddy atlas?

Try this one:
http://www.codeandweb.com/texturepacker


Volker(Posted 2012) [#110]
I know about this one, but it applies watermarks in the demo version.
No free one out there?


therevills(Posted 2012) [#111]
Opps, sorry I bought it ages ago and forgot I had to pay for it...

And I'm having a hard time finding a "free" one, this one looks okay http://spritesheetpacker.codeplex.com/ but Diddy isn't written to handle its output... its a pretty simple output so we could add it if its any value.


Kauffy(Posted 2013) [#112]
Would it be possible to add overloads for the Date/Time functions to not just report the current dateparts, but also to report the datepart of a given date serial?

Or is there a way to do this now that I'm not already aware of?

Thanks!


therevills(Posted 2013) [#113]
Would it be possible to add overloads for the Date/Time functions to not just report the current dateparts, but also to report the datepart of a given date serial?

Sorry, I'm not quite sure what you are asking... could you give me an example?


Kauffy(Posted 2013) [#114]
Sure, @therevills.

So, the date functions currently report the date part (months/days/years/minutes, etc.) of the current date/time.

But what if you wanted to:
1) Store a given date, and then recall it later?
2) Use an alternate date/time because your game takes place in 1945?

I'm thinking of this like in Excel or any other place, where there is a date serial-- I think the number of seconds since January 1, 1900-- or maybe it's days. Whatever it is.

I would think these are already available on the native platforms-- maybe I gotta figure out how native code and externs work. :)


Samah(Posted 2013) [#115]
I was going to make a Date class at one point to mimic some of the Java functionality. If you think it's useful I'll add it to Diddy.


Rushino(Posted 2013) [#116]
@therevills Is this have been updated for V67 ?


therevills(Posted 2013) [#117]
updated for V67 ?

Nope not yet, we are waiting for the official release.


Rushino(Posted 2013) [#118]
Alright thanks! I think i will stick with v66 for now.


Auburn(Posted 2013) [#119]
Hi, I am having a problem with the tiling engine in diddy; if i change a tile using any of the set methods it will update that information for collision detection, but it will not render the map with any changes, it just renders the original map that was loaded. When i check the tile data with get method it returns the tile it set previously.

Is this something I am doing wrong or is it a bug?

This is my code:
format_code('SetTile ( mouseX, mouseY, 2, layerName )')
This is inside a method in my tilemap class.

Edit: I know it is updating the correct tile as collisions work on the updated tile.


Samah(Posted 2013) [#120]
Given that tile collision and image are on different layers, you need to update both of them. This is a side-effect of the fact that collision detection in the tile engine is a bit of a hack given that (last time I used it) Tiled does not initially support the concept of "collisions". They must be handled manually by the engine that reads the Tiled map files.


Auburn(Posted 2013) [#121]
Ok, but how do I update the image for the map then?

I have spent a while looking through the tile module but could find nothing on updating the image from the map data.


rIKmAN(Posted 2013) [#122]
Hi,

First great job on the Framework! :)

Everything seems to work fine for me in v65 and v66b, however in v67c I get a compile error:

Error : Duplicate identifier 'game' found in module 'monkeytarget' and module 'framework'.


I know that v67c is the experimental version and it will be something Mark has changed that you need to accomodate, but thought I'd let you know.

Looking forward to having a play with diddy this week. :)


rIKmAN(Posted 2013) [#123]
A few more errors when going through the examples that come with diddy (diddy_r522.zip) and using Monkey v66b.

DiddyData - Compiles but gives error
Monkey Runtime Error: Type Error: Cannot call method 'm_NewInstance' of null


Particle
Error : Duplicate identifier 'Interpolate' found in module 'storyboard' and module 'functions'.


Serialisation - needs a Return 0 added at the end of Main()
Error : Missing return statement.


Sounds
Compiles but gives me "Audio Error1!" whenever I press a key

Threading
Error : Module 'threading' not found.



therevills(Posted 2013) [#124]
however in v67c I get a compile error:

As stated above we wont be supporting v67 until its official.

With your errors, try getting the latest source from bitbucket: https://bitbucket.org/swoolcock/diddy/src

Also with the Audio error, that is a Mojo error message, the browser you are using might not support the audio format... and we did remove some of the duplicate sounds (same sound different format) to save on the download size.


rIKmAN(Posted 2013) [#125]
Ah yeah, I grabbed the latest from the SVN with Tortoise and everything seems to work again now, thanks.

The browser I am using is Chrome.


Tibit(Posted 2013) [#126]
I get the same errors, but with your https://bitbucket.org/swoolcock/diddy/src

Do I need to get the SVN version?


Zwer99(Posted 2013) [#127]
Hey guys,

I have a problem with the tile engine together with aspact ratio. The following happens because of the scaling:


It's surely because of the pixels getting float numbers. Does anybody know how to solve that?


Samah(Posted 2013) [#128]
Disable image filtering.


Zwer99(Posted 2013) [#129]
:( The Problem still occures.
My config-file for Flash and HTML5 Looks like this:

format_code('#MOJO_AUTO_SUSPEND_ENABLED=false
#MOJO_IMAGE_FILTERING_ENABLED=false

#TEXT_FILES="*.txt|*.xml|*.json"
#IMAGE_FILES="*.png|*.jpg"
#SOUND_FILES="*.mp3"
#MUSIC_FILES="*.mp3"
#BINARY_FILES="*.bin|*.dat"')
Did I do something wrong? I edited both files: the one in the build-dir and the one in monkey/Targets. I also tried to delete the whole build-dir and recompile everything. But there's still the same problem.


Tazzy(Posted 2013) [#130]
Hi there,

Just downloaded the latest version version of Diddy and tried the examples. I'm new to Monkey, but not to programming.
For some reason I run into a few compiler errors in the diddy modules:

- No overload found for GetMatrix(Float) -> storyboard.monkey
- Function Interpolation is found in both functions.monkey and storyboard.monkey -> psystem.monkey

I managed to fix them both so that it compiles, but I'm not sure it's now functionally correct, since the Vector sample just shows an empty screen.

Can anyone tell me if I'm using the correct version. I've downloaded version 5.22 from http://code.google.com/p/diddy/downloads/list

Seems to me there should be topics or fixes about that already, since it's from october 8 last year.
Other than that it seems like a good extension to me and looks promissing.


rIKmAN(Posted 2013) [#131]
Hey Tazzy, I had a few of the same errors as you when using the latest version from the .zip file.

To fix them I grabbed the version from the SVN therevills pointed me too a few posts up.

Download TortoiseSVN and point it to: https://bitbucket.org/swoolcock/diddy/src

Once I had that all the examples ran fine for me.

Also what version of Monkey are you using?


Tazzy(Posted 2013) [#132]
Hi rIKmAN,

Thank you for your help. Unfortunately I get the same errors when I grab them from bitbucket :(

C:/Blitz/Monkey/modules/diddy/storyboard.monkey<242> : Error : Unable to find overload for GetMatrix(Float[]).
Abnormal program termination. Exit code: -1


rIKmAN(Posted 2013) [#133]
What version of Monkey are you using?
I think I was testing with v66b though I would have to check when I get home.

v67 builds aren't supported in Diddy yet until Mark releases it as "official"


Tazzy(Posted 2013) [#134]
Hi,

I was looking that up and also tried to update when I noticed there are newer versions. I was using version 64b at that time.

When I tried to update to 66b I got nothing to work in Monkey anymore.
CFG_OPENGL_GLES20_ENABLED is not defined :(
So back at 64b.

But did mojo really change it's signature from
mtx = GetMatrix to GetMatix(mtx) in later versions?

If not, I would guess it's a real compiler error and it has nothing to do with versions of Monkey. Somebody checked in without compiling... I've even checked the sourcecode on bitbucket. Same error

What I don't understand I why nobody noticed it before and so it's still unfixed since october 2012. Is there still active development on Diddy?


Samah(Posted 2013) [#135]
What I don't understand I why nobody noticed it before and so it's still unfixed since october 2012.

format_code('TRANS monkey compiler V1.42
Semanting...
Translating...
Building...
Done.
Process ended with return code 0 at 2/20/2013 8:28:03 AM')
From modules\mojo\graphics.monkey (contents removed):
[monkeycode]Function GetMatrix( matrix#[] )
' *snip*
End[/monkeycode]
Works fine for me with v66b. Do you have your own version of GetMatrix somewhere?

Somebody checked in without compiling... I've even checked the sourcecode on bitbucket. Same error

I never push unless it compiles and runs.


therevills(Posted 2013) [#136]
When I tried to update to 66b I got nothing to work in Monkey anymore.
CFG_OPENGL_GLES20_ENABLED is not defined :(

Sounds like your Monkey set up is messed up.

mtx = GetMatrix to GetMatix(mtx)

GetMatrix has two signatures:
format_code('Function GetMatrix : Float[] ()
Function GetMatrix : Int ( matrix:Float[] )')


Tazzy(Posted 2013) [#137]
Yeah, now I get it.
The second overload was added _after_ v64b

So switching to 66b now added this overload and this explains why I'm the only one having this problem. Got the new version of Monkey to work too.
Seems you have to delete the temporary .build folders for all projects you compiled before.

What I don't really get is what this overload adds to the table, but I'm sure there are some good reasons for this. But it's not important.

So will try diddy again. Probably those issues are fixed now too


Thank you for your help :)


Samah(Posted 2013) [#138]
The point of the overload is to allow the developer to use a cached array. It saves creating a new array on every call to GetMatrix, which can end up being a performance overhead.


Redbeer(Posted 2013) [#139]
Documentation seems to be missing for this.

I was very happy to work with Diddy, even though the documentation was somewhat sparse and not updated, there was "enough" to make use of most of the information without having to read through the source code.

However, it seems that all the documents that were in the wiki at the google code address have disappeared. In fact the very link presented in this thread is missing.

Is there any way we can get this information back and/or has it moved somewhere else?


Paul - Taiphoz(Posted 2013) [#140]
unfortunately poor documentation is a common problem here, good programmers do not always make for good document writers, its often the thing sitting at the bottom of a todo list.

It's that thing, if samah and therv.. take the time to write full documentation then its time their not spending on diddy or their own games, I will suggest this as I have done for the main monkey docs.

@sam/ther you guys should think about sorting out a proper wiki and then letting the community help you out with the docs, not only would they grow and be more up to date but it would require a lot less time on your part to manage, I wish Mark would do the same with the monkey docs.


Redbeer(Posted 2013) [#141]
Well I'm less concerned about writing new documentation, but I would like it if what was already there hadn't disappeared....


c.k.(Posted 2013) [#142]
Documentation should always be open source and community-editable.

Always.

Takes the load off the developers, and with many people contributing small bits, it becomes a very comprehensive resource in a relatively short time.


Paul - Taiphoz(Posted 2013) [#143]
yeah I hold the php docs up as a shining example of how it could be done.


therevills(Posted 2013) [#144]
@Redbeer - when we moved over to Hg the wiki switched to the Hg one, I've been meaning to copy over the SVN wiki - not enough time these days.

@Taiphoz - yeah a proper wiki would be good... but where to host it/secure it/spam protect it? Google Code has a wiki system, but we have to add people to the project, we could do that if we get a list of people who wish to add stuff.

@Mods - Please close this thread.

Thread continues here (Part 7):
http://www.monkeycoder.co.nz/Community/posts.php?topic=4589