fantomEngine - A 2D game framework - part 3

Monkey Programming Forums/User Modules/fantomEngine - A 2D game framework - part 3

MikeHart(Posted 2013) [#1]
Hi folks,

I have uploaded version 1.51 of fantomEngine. Get it here:

http://www.fantomgl.com

Lots of new features:

- Keymapping
- Localization
- Huge performance boost for tilemap rendering
- Parsing and storing of Tiled map objects
- Sound handling greatly improved
- Drawing primitives
- etc.

Thanks for all the guys that have contributed to this release! I hope I have mentioned everyone. If not, let me know.

Cheers
Michael


ordigdug(Posted 2013) [#2]
:) Awesome!

I'm glad you expanded the primitives code from what I provided.

Also since you added the collision type "ctLine",
Should the collision type in the CreateLine method within cftEngine.monkey be changed to "obj.collType = ctLine"?

Douglas


ordigdug(Posted 2013) [#3]
Updated "Create Primitives" Example

format_codebox('

Strict

#rem
Script: CreatePrimitives.monkey
Description: This fantomEngine sample script shows how to create the following:
box, circle, polygon, oval, point, stickman (with visable bound box), line
Author: Douglas Williams
Version: 1.01
#End

' Set the AutoSuspend functionality to TRUE so OnResume/OnSuspend are called
#MOJO_AUTO_SUSPEND_ENABLED=True

' Import the fantomEngine framework which imports mojo itself
Import fantomEngine

' The _g variable holds an instance to the cGame class
Global _g:cGame

'***************************************
' The cGame class controls the app
Class cGame Extends App
' Create a field to store the instance of the cEngine class, which is an instance
' of the ftEngine class itself
Field fE:cEngine

'Store canvas width/height
Field cw:Float = 0.0
Field ch:Float = 0.0

'Store stickMan
Field stickMan:ftObject 'For storing STICKMAN
Field stickManY:Float = 0.0 'For storing STICKMAN Y position

'------------------------------------------
Method OnCreate:Int()
' Set the update rate of Mojo's OnUpdate events to 60 FPS
SetUpdateRate(60)

' Create an instance of the fantomEngine, which was created via the cEngine class
fE = New cEngine

'Set canvas Width/Height field variables
cw = fE.canvasWidth
ch = fE.canvasHeight

'Print directions in debug window
Print("Press LEFT and RIGHT to move and UP to jump.~n")

'Print canvas X & Y in debug window
Print("Canvas Width (X) = "+cw)
Print("Canvas Height (Y) = "+ch)

'Print info in debug window
Print("~nOBJECTS ARE DRAWN IN THE FOLLOWING ORDER:")
Print(" Box = Canvas Width x Height at middle of canvas")
Print(" Circle = 1/2 Canvas Height at middle of canvas")
Print(" Oval = Width:100, Height:50, at middle of canvas")
Print(" Polygons = Vertices pairs in relation to X/Y")
Print(" Point = At middle of canvas")
Print(" Stickman = Top Left Corner starts at middle of canvas, Width:8, Height:29")
Print(" Line = Below Stickman")
Print(" X = Two spinning lines at middle of canvas")

'Create Box
Local box := fE.CreateBox(cw, ch, cw/2, ch/2) '(width, height, x, y)
box.SetColor(192,192,192) 'Silver
'box.SetSpin(-1)

'Create Circle
Local circle := fE.CreateCircle(ch/2, cw/2, ch/2) '(radius, x, y)
circle.SetColor(70,130,180) 'Steel blue

'Create Oval
Local oval := fE.CreateOval(100, 50, cw/2, ch/2) '(width, height, x, y)
oval.SetColor(218,165,32) 'Golden rod
oval.SetSpin(1)

'Create Polygons **** A minimum of 3 x/y vertices pairs are required ****
Local polyTriangle := fE.CreatePoly( [-50.0,0.0, 50.0,0.0, 0.0,50.0 ], cw/2-100, ch/2+100 ) '([verts], x, y)
polyTriangle.SetColor(152,251,152) 'Pale green
Local polyTrianglePoint := fE.CreatePoint(cw/2-100, ch/2+100) '(x, y)
polyTrianglePoint.SetColor(0,0,0) 'Black

Local poly := fE.CreatePoly( [-50.0,-50.0, 0.0,-75.0, 50.0,-50.0, 50.0,50.0, -50.0,50.0 ], cw/2+100, ch/2+100 ) '([verts], x, y)
poly.SetColor(255,255,224) 'Light yellow
poly.SetAlpha(0.8) 'Set alpha to 80%
poly.SetSpin(-3)

'Create point
Local point := fE.CreatePoint(cw/2, ch/2) '(x, y)
point.SetColor(0,0,0) 'Black

'Create stickman (Top left corner is at x/y with size of width:8 / height:29)
stickMan = fE.CreateStickMan(cw/2, ch/2) '(x, y) = Upper left of stickman
stickMan.SetColor(0,0,0) 'Black
stickMan.SetID(1)
stickManY = stickMan.GetPosY()
stickMan.SetWrapScreenX(True)

Local boundBox := fE.CreateBox(8, 29, cw/2, ch/2)
boundBox.SetColor(255,255,255) 'White
boundBox.SetAlpha(0.3) 'Set alpha to 30%
boundBox.SetHandle(0.0, 0.0) 'Set handle to top left corner
boundBox.SetParent(stickMan)

'Create Line (line is left (x/y) to right (x2, y2))
Local line := fE.CreateLine(0,ch/2+30, cw,ch/2+30) '(x, y, x2, y2)
line.SetColor(139,69,19) 'Saddle brown

'Create X using 2 lines
Local leftX := fE.CreateLine(0,0, cw,ch)
leftX.SetColor(255,255,255) 'White
leftX.SetAlpha(0.2) 'Set alpha to 20%
leftX.SetSpin(-2)
'leftX.SetHandle(0.0, 0.0)

Local rightX := fE.CreateLine(0,ch, cw,0)
rightX.SetColor(255,255,255) 'White
rightX.SetAlpha(0.2) 'Set alpha to 20%
rightX.SetSpin(2)
'rightX.SetHandle(0.0, 0.0)

Return 0
End
'------------------------------------------
Method OnUpdate:Int()
If KeyHit( KEY_CLOSE ) fE.ExitApp()
' Determine the delta time and the update factor for the engine
Local d:Float = Float(fE.CalcDeltaTime())/60.0

' Update all objects of the engine
If fE.GetPaused() = False Then
fE.Update(d)
Endif
Return 0
End
'------------------------------------------
Method OnRender:Int()
' Check if the engine is not paused
If fE.GetPaused() = False Then
' Clear the screen
Cls

' Render all visible objects of the engine
fE.Render()

Endif
Return 0
End
'------------------------------------------
Method OnResume:Int()
' Set the pause flag of the engine to FALSE so objects, timers and transitions are updated again
fE.SetPaused(False)

Return 0
End
'------------------------------------------
Method OnSuspend:Int()
' Set the pause flag of the engine to TRUE so objects, timers and transitions are paused (not updated)
fE.SetPaused(True)

Return 0
End
End

'***************************************
' The cEngine class extends the ftEngine class to override the On... methods
Class cEngine Extends ftEngine
'------------------------------------------
Method OnObjectUpdate:Int(obj:ftObject)
' This method is called when an object finishes its update

'If stickMan
If obj.GetID() = 1

'Jump
If KeyDown(KEY_UP)
If obj.GetPosY() >= _g.stickManY 'If stickman at or above ground
obj.SetSpeedY(-10) 'Move stickman up
Endif
Endif

'Fall
If obj.GetPosY() <= (_g.stickManY - 60) 'If stickman jump height is reached
obj.SetSpeedY(10) 'Move stickman down
Endif

'Stop
If obj.GetPosY() > _g.stickManY 'If stickman below ground
obj.SetPosY(_g.stickManY) 'Stop movement at ground
Endif

'Move right
If KeyDown(KEY_RIGHT)
obj.SetPosX(1, True)
Endif

'Move left
If KeyDown(KEY_LEFT)
obj.SetPosX(-1, True)
Endif

Endif

Return 0
End
End

'***************************************
Function Main:Int()
' Create an instance of the cGame class and store it inside the global var 'g'
_g = New cGame

Return 0
End

')


MikeHart(Posted 2013) [#4]
Should the collision type in the CreateLine method within cftEngine.monkey be changed to "obj.collType = ctLine"?



Sure, will change it.


Why0Why(Posted 2013) [#5]
Mike,

I would like to put in another request for support for SKN's great free texture atlas tool. It has an XML output and I think it would be easy to add since the texturepacker support works in a similar way.

Here is a link to the thread:

http://www.monkeycoder.co.nz/Community/posts.php?topic=5088#56832

Thanks again for your consideration. Really loving fE and going deeper with it all the time. And thanks for adding the GUI value to prevent it from moving with the camera.

Eric


MikeHart(Posted 2013) [#6]
I will look into it Eric. But the file format I use from TexturePacker is not XML based (LibGDX).


Why0Why(Posted 2013) [#7]
With a large project and classes split over many files, what is your preferred method using fE? Do you use globals for the engine, layers and other ftObjects such as player and UI?

I have been experimenting a lot, but they have all been individual files with everything located together. I have a multi file project that I am converting from mojo with each class having its own draw method which I obviously need to convert to ftObjects and use the engine rendering method.


ordigdug(Posted 2013) [#8]


:)

Link to Inkscape .svg: https://docs.google.com/file/d/0B8ZVTzxxMspjTWZUYXV1NnFfY0E/edit?usp=sharing
(Created with Inkscape)


MikeHart(Posted 2013) [#9]
Good job! :-)))


MikeHart(Posted 2013) [#10]
@Why0Why: I see that this texture packer tool can export to the sparrow file format, right? TexturePacker can too, so I can create some text maps with it. Looks easy to parse.

What is it about these multi page sprite sheets I read regarding SKN's tool?


Why0Why(Posted 2013) [#11]
It looks like you can define a sheet size and it will create more sheets if you have too many sprites. I was actually looking at how you implemented TexturePacker sheets and was going to just add a flag and put XML import in the same creatimage method in cftengine. The XML output is super simple and you can use almost the same methodology as the LibGDX format. But Sparrow works fine too :)

Did you see my question above about large projects? I would be interested in getting your feedback when you have some time. Does mixing draw methods with an engine.render for ftobjects have the potential to cause problems?


MikeHart(Posted 2013) [#12]
Sorry, I didn't notice your question, must have overread it :-/ I will think about it and reply later. Anyway, you can read Sparrow compatible XML files now with this change. Please exchange the corresponding method in the cftEngine.monkey file with this:

format_codebox('
Method CreateImage:ftObject(atlas:Image, dataFileName:String, subImageName:String, xpos:Float, ypos:Float, _ucob:Object=Null)
Local obj:ftObject
If _ucob = Null Then
obj = New ftObject
Else
obj = ftObject(_ucob)
endif
'Code provided by fantomEngine user TriGaDe, modified by Michael Hartlef >>>>>>>>>>>
'** TexturePacker variables
Local tpStringFromFile:String = LoadString(dataFileName)
Local tpAllStrings:String[] = tpStringFromFile.Split(String.FromChar(10))
Local tpXPos:Int
Local tpYPos:Int
Local tpWidth:Int
Local tpHeight:Int
If dataFileName.ToLower().Find(".txt") > 0 then
For Local count:Int = 0 To tpAllStrings.Length()-1
If( String(tpAllStrings[count]).ToLower() = subImageName.ToLower()) Then
'** Get rotation flag
Local strRot:String = tpAllStrings[count+1]
strRot = strRot.Replace("rotate:","").Trim()
If strRot.ToLower = "true" Then obj.offAngle = -90
'** Get X, Y
Local strXY:String = tpAllStrings[count+2]
strXY = strXY.Replace("xy:","").Trim()
Local strXYsplit:String[] = strXY.Split(",")
tpXPos = Int(strXYsplit[0])
tpYPos = Int(strXYsplit[1])

'** Get Width, Height
Local strWH:String = tpAllStrings[count+3]
strWH = strWH.Replace("size:","").Trim()
Local strWHsplit:String[] = strWH.Split(",")
tpWidth = Int(strWHsplit[0])
tpHeight = Int(strWHsplit[1])
Endif
Next
Else
For Local count:Int = 0 To tpAllStrings.Length()-1
Local s:String = String(tpAllStrings[count]).ToLower().Trim()

If s.Contains(String.FromChars([34])+subImageName.ToLower()+String.FromChars([34])) Then
Print (s)
'<SubTexture name="background2" x="2" y="2" width="320" height="480"/>
s = s.Replace(String.FromChars([34]),"")
Print (s)
'<SubTexture name=background2 x=2 y=2 width=320 height=480/>
s = s.Replace("<subtexture ","")
Print (s)
s = s.Replace("/>","")
Print (s)
'name=background2 x=2 y=2 width=320 height=480
Local strSplit:String[] = s.Split(" ")

'name=background2
'x=2
'y=2
'width=320
'height=480

'** Get X
Local strX:String = strSplit[1]
Local strXsplit:String[] = strX.Split("=")
tpXPos = Int(strXsplit[1])
'** Get Y
Local strY:String = strSplit[2]
Local strYsplit:String[] = strY.Split("=")
tpYPos = Int(strYsplit[1])
'** Get Width
Local strW:String = strSplit[3]
Local strWsplit:String[] = strW.Split("=")
tpWidth = Int(strWsplit[1])
'** Get Height
Local strH:String = strSplit[4]
Local strHsplit:String[] = strH.Split("=")
tpHeight = Int(strHsplit[1])

Endif
Next
Endif
'<<<<<<<<< Code provided by fantomEngine user TriGaDe, modified by Michael Hartlef

'Local obj:ftObject = New ftObject
obj.engine = Self
obj.xPos = xpos
obj.yPos = ypos
obj.type = otImage
obj.img = atlas.GrabImage( tpXPos,tpYPos,tpWidth,tpHeight,1,Image.MidHandle )

obj.radius = (Max(obj.img.Height(), obj.img.Width())*1.42)/2.0
If obj.offAngle < 0 Then
obj.h = obj.img.Width()
obj.w = obj.img.Height()
Else
obj.w = obj.img.Width()
obj.h = obj.img.Height()
Endif
obj.rw = obj.img.Width()
obj.rh = obj.img.Height()

obj.SetLayer(Self.defaultLayer)
obj.SetActive(Self.defaultActive)
obj.SetVisible(Self.defaultVisible)
obj.collType = ctCircle
obj.internal_RotateSpriteCol(obj)
Return obj
End
')

This code load everything that is not a TXT (LibGDX) file as a Sparrow file (XML).

I am in the process cleaning up the sprite sheet handling in fE for the next version so parts of this code will make it into its own class.


Why0Why(Posted 2013) [#13]
Once again, you are the man! Thanks!


MikeHart(Posted 2013) [#14]
Thank you Eric for your kind words :-)


With a large project and classes split over many files, what is your preferred method using fE? Do you use globals for the engine, layers and other ftObjects such as player and UI?



So far I had not the need for this but I can see it being useful for others. You will have your main class with OnCreate, OnRender, OnUpdate anyway and I would store this instance inside a global variable like I do in the examples (g or _g). So this could be reached from every other class. I would use the "game" class to store all the instances you have and call them from outside.


I have a multi file project that I am converting from mojo with each class having its own draw method which I obviously need to convert to ftObjects and use the engine rendering method.



Converting everything to a ftObject is the best approach as it makes sure that everything is taken care off. But of course, you could use custom objects and there overwrite the render method. Or you use ftEngine.OnObjectRender events to draw extra stuff. There are so many ways you could do it. What kind of drawing are you doing?

When you mix fE's render methods with your own, make sure that you restore the engines color, alpha and blend value if you need to change these for your render calls. Whenever a ftObject has a different color/alpha/blendmode as the last object, fE changes them and stores these values internally. This reduces calls to SetAlpha, SetColor, SetBlendMode. That is why you need to restore them with ftEngine.Restore.... calls.

You could even go so far that you create several instances of fantomEngine in one game and handle them differently. I am not sure how this would effect the performance but someone here mentioned it one time and I think it is doable.

I guess it is time to create a sample project over the next days to illustrate this. :-)


MikeHart(Posted 2013) [#15]
Btw. I have create a google group for a kinda support forum. It is located here:

https://groups.google.com/forum/?fromgroups=#!forum/fantomengine

Of course you guys can post here too.


Why0Why(Posted 2013) [#16]
I will probably just wind up converting everything over to ftobjects. The project I am converting had Dungeon Raid style matching where you swipe or use the mouse to slide across objects to match and it was an array of ints that I just drew at runtime using a sprite strip, as we had discussed when we had the dynamic tilemap discussion. I think it may just be easier to rewrite parts of it completely using fE and just pull out the matching logic where it is needed. I was just trying to avoid that, but it is probably best.


MikeHart(Posted 2013) [#17]
Eric,

grab the example from the link below that illustrates multiple classes/files and custom objects:

http://www.fantomgl.com/?p=521


Why0Why(Posted 2013) [#18]
Great Example! That is exactly what I am working on right now, so it is very timely.


Raul(Posted 2013) [#19]
Hello,

I have a problem with the creating of a tile map.

I made a map in Tiled using some custom textures.

When running you example with my map I receive:

Could not load image
maps/../../resources/2D/2D Circle Graphic/PAVE.bmp

I copy paste the PAVE.bmp near the json file but it seems that he is trying to search for the file in another location. How to fix that?

Thanks.


MikeHart(Posted 2013) [#20]
Remove the filepath from the texturename inside the json file.


Skn3(Posted 2013) [#21]
Hey cool, good to see MakeAtlas getting integrated. Good job on this engine, seems to be progressing very nicely!


MikeHart(Posted 2013) [#22]
Thanks, i TRY to listen to user suggestions. :-)

@Raul, i will see if can teach fR to ignore a filepath if it isn't found there.


Raul(Posted 2013) [#23]
hmm, ok. now can you explain me why every time I run the project, my "own custom textures" are not copied in the build folder? the game cannot load them now because they are deleted from the build folder...


MikeHart(Posted 2013) [#24]
No clue. Monkeys build mechanics are responsible to copy files, not fE.


MikeHart(Posted 2013) [#25]
Your image must be inside your data folder and the file extension must be allowed by your settings.


Raul(Posted 2013) [#26]
yeah i had bmp file.

I made them .PNG and now I receive this error:
"Monkey Runtime Error : Invalid image frame"


Raul(Posted 2013) [#27]
Well, I made another map (using only one texture) and I managed to load it and render it.

Anyway after I move my camera a phew units to the right or down, some regions dissapear :)


MikeHart(Posted 2013) [#28]
Difficult to say what it could be. Is the source available, so i can have a look?


Raul(Posted 2013) [#29]
sure. dwn it from here:

http://rvlgames.com/Tiled.zip


MikeHart(Posted 2013) [#30]
Ok, its a bug. Will release a fix soon.


Raul(Posted 2013) [#31]
good to hear that! thank you


MikeHart(Posted 2013) [#32]
@Raul, I have uploaded a fixed version of fE.


garyk1968(Posted 2013) [#33]
Mike,

Just downloaded (what I think) is the latest (v1.51b) fE and it failed on build with:


Module brl.Filepath not found

I looked in the brl folder and noticed there was a FileStream but no filepath so just changed it to filestream and it now works ok.

I'm using Monkey 0.69 btw

Regards

Gary


Raul(Posted 2013) [#34]
@garyk1968: I had the same problem with 0.69, but with 71c worked ok.

@Mike: I din't notice your fix. Thank man. Will have a look later.


garyk1968(Posted 2013) [#35]
No, ignore me its not filestream as it wont compile to html5.

I just searched and pulled filepath from github. For some reason on my Monkey distro its not there.

Will have a play with the engine anyway!


MikeHart(Posted 2013) [#36]
Do that, have a look at the samples and ask ask ask.

working on the Particle part for fE atm.


MikeHart(Posted 2013) [#37]
Sorry, sometimes when you update fE, you need the newer Monkey releases. I will try to add infos on that in the future.


Why0Why(Posted 2013) [#38]
I just commented the line out. I don't update the Monkey version regularly because they are experimental many times.


MikeHart(Posted 2013) [#39]
Hi folks,

I have just uploaded version 1.52 of fantomEngine. Get it here:

http://code.google.com/p/fantomengine

Cheers
Michael


RobB(Posted 2013) [#40]
Thanks, Mike. I really appreciate Fantom Engine.


MikeHart(Posted 2013) [#41]
Your welcome Rob. :-)


ordigdug(Posted 2013) [#42]
Mike, Thanks for the continued improvements to fantomEngine


MikeHart(Posted 2013) [#43]
Thank you for using fE!


DarkyCrystal(Posted 2013) [#44]
Hello :)

I would like to know if there is a way to test collision with a tile that is loaded with a json file and Tiled ?

Try to understand how in the documention but I would like to test a collision between a sprite and a tile (Tiled map) Thank you in advance :)


MikeHart(Posted 2013) [#45]
For this you can use

yourMapObject.GetTileAt(x,y)

or

yourMapObject.GetTileIDAt(x,y)

I didn't implement collision checks between mapobjects and other objects directly because I thought it would be very CPU consuming and I couldn't think about an optimized logic so I don't have to check every tile there is of a map.

At the moment I am working on a platformer tutorial that uses Tiled maps and objects. So collision check will be one part of it.


DarkyCrystal(Posted 2013) [#46]
Fantastic :) so the better is to test the x and y position of the player with the tile position with map.GetTileAt(x,y) that right ?


MikeHart(Posted 2013) [#47]
Yes, or something below.

Look into ftObject.GetEdge to get the coordinates of the edges of an object.


DarkyCrystal(Posted 2013) [#48]
I think with this, I have to test each game loop the position and test the "content" of tiles to see if they match'up with a sort of tile that the player can collide with.

(sorry for my english...lol).


MikeHart(Posted 2013) [#49]
Yes. I will see if I can think about something more "automatically".


DarkyCrystal(Posted 2013) [#50]
Ho that's not an obligation :) I just wanted to know how to deal with tiles :) I think it's a good thing to have some controls too.


MikeHart(Posted 2013) [#51]
Ok, then I will concentrate on the animation features for now; and the tutorial.


DarkyCrystal(Posted 2013) [#52]
You make a great job ;)


Why0Why(Posted 2013) [#53]
Mike and FE are great. He was always a huge help to me with both feature requests and help when I needed it. Thanks for all the work you have done Mike! People like you are what makes the Monkey community great.

And if you haven't yet, buy his book too :)


MikeHart(Posted 2013) [#54]
Thanks guys for your kind words. It is always great to see people appreciate your work. And thanks to everyone who bought the book.

If you are interested, here are some of my short-/midterm plans I have for fantomEngine.

1) Redoing the animation system to make it more flexible.

- Usage of several single images to create an animation.
- Animating position, angle, scale. Usefull to implement Spine/Spriter like animation.
- Switch animations by names instead of frame indexes.

2) Create the requested platformer tutorial to show how to work with Tiled maps, collision detection and map objects.

2) Redo the website. With more examples and a user app gallerie.

3) Offer a Pro license, where I help with custom tutorials and personal online training via Skype, Facetime, etc.

4) Create tools/editors for maps, physics, particles, localization, etc.

5) Writing a so called "fantomEngine Black Book" which explains the functionalities more detailed and with more examples.

6) Adding other stuff to fE of course :-)


MikeHart(Posted 2013) [#55]
Besides that, I have created a dedicated twitter acount for fantomEngine.

http://www.twitter.com/fantomEngine


DarkyCrystal(Posted 2013) [#56]
4) Create tools/editors for maps, physics, particles, localization, etc.


awesome :)


DarkyCrystal(Posted 2013) [#57]
Just a question about FE. Are we be able to define a view in a game ? for example, I have a map of 1000 X 1000 but only 640x480 is visible on the screen ?

May be with SetCam ?

Thank you.


MikeHart(Posted 2013) [#58]
You set your view with SetCanvasSize and the position with SetCam.


DarkyCrystal(Posted 2013) [#59]
thank you I will get a try, sorry for my stupid questions ^^


vmakar85(Posted 2013) [#60]
fantomEngine Black Book - wow you do Mike, we will wait!!!!


MikeHart(Posted 2013) [#61]
DarkyCrystal, there are no stupid questions. Keep them coming.


DarkyCrystal(Posted 2013) [#62]
Hello there :)

I would like to know if there is a solution to make a map warp on the opposite side of the screen when it leaves the screen on the right or left. The map is made with Tiled the map editor.

I didn't see anything about that in the documention.

Thank you in advance,


nikoniko(Posted 2013) [#63]
Hi!

Where do change ball's direction when it has collision with border?

In OnObjectCollision() or in OnObjectUpdate()?

I tried do that in OnObjectCollision()

format_code('
If obj.collGroup = _g.grpBall And obj2.collGroup = _g.grpBorder Then
If True Then
'Print "Collision"
obj.SetSpeedAngle(180 - obj.GetSpeedAngle())
Endif
Endif
')

But this code generates some artefacts as a ball goes trough border.
Is obj.SetSpeedAngle(180 - obj.GetSpeedAngle()) wrong for change direction?

If I change direction in the OnUpdateObject() need to add more lines of code to define object to change direction (check collision again?), but no artefacts in this case.


MikeHart(Posted 2013) [#64]
OnObjectCollision is the right place but depending on how far it will go into the border, it can still bring up a collision on its way back during the next frame because the ball can still be on that border. You need some logic in your game that takes care of that.


MikeHart(Posted 2013) [#65]
@DarkyCristal. No, there is no functionality to repeat the map.


DarkyCrystal(Posted 2013) [#66]
ho, and do you have an idea how to make this ?

Thank's.


MikeHart(Posted 2013) [#67]
Repeat the map in Tiled for at least 1,5 as the screen width. Then if your character reaches the regular end of the map, scroll it back to the beginning, reposition the character and there you have the imagination of a scrolling endless map.


DarkyCrystal(Posted 2013) [#68]
Thank you. I'm not sure to understand your idea. May be I should make some tests. It's a little difficult to imaginate :)

I tried your idea, there is something wrong. I use setCam to make the camera moves but I didn't find something to test the x position of the camera. Also I don't know exactly when I have to switch back to position "0" to simulate infinite scrolling.

Edit : That doesn't work with me, if you have a sample to show what you try to explain to me, it would be cool :)


MikeHart(Posted 2013) [#69]
Sorry, I have no sample laying around.

>>I use setCam to make the camera moves but I didn't find something to test the x position of the camera.

LOL, when you set the position, you have it already or? But I will add soem functions to return the camera pos.

>>Also I don't know exactly when I have to switch back to position "0" to simulate infinite scrolling.

You should know how wide your map is, or? So assuming you are scrolling from right to left, here is some pseudocode.

format_code('
If (WidthOfCanvas + PositionCameraPositionX) > WidthOfMap then
'scroll back
Endif
')


DarkyCrystal(Posted 2013) [#70]
mmmmh May be.

But when I said when I set the x position of the cam, I mean with the SetCam instruction , this is a setter not a getter... So If you want to test the x pos of the cam you need a getter, and in the doc I didn't find any getter for the position of the cam. I need to set up a variable that handles the position of it every frame.

I will make some extra test with your pseudo code.


MikeHart(Posted 2014) [#71]
Hi folks,

fantomEngine version 1.53 was released: http://www.fantomgl.com/2014/02/06/fantomengine-v1-53-released/


Neuro(Posted 2014) [#72]
Cool :)!


Nobuyuki(Posted 2014) [#73]
@MikeHart: psst, GitHub has zip downloads of current source snapshots, just don't tell anyone I told ya


MikeHart(Posted 2014) [#74]
@Nobuyuki: Really? :-p Guess what, I tell you something. But don't tell anyone! I don't like Github or similar services. :-)


Nobuyuki(Posted 2014) [#75]
Then what the heck were you doing on Google Code, lol


MikeHart(Posted 2014) [#76]
I thought you meant that i should put it up there like others. Like a repro and stuff like that. Or can you simply upload a zip file there without a client? GC allowed to do this.


MikeHart(Posted 2014) [#77]
Hey folks,

I would love to showcase games that are powered via fantomEngine on my website. So please let me know about them. From over 280 downloads of fantomEngine v1.52, some games must have been made :-)

http://www.fantomgl.com/2014/02/08/looking-fantomengine-games/

Cheers
Michael


Neuro(Posted 2014) [#78]
i sent mine :).


MikeHart(Posted 2014) [#79]
Cool, thanks! Guys, keep them coming!


MikeHart(Posted 2014) [#80]
I have gotten the first entries in the fantomEngine game gallery and would love to see more:

http://www.fantomgl.com/games-powered-fantomengine/

So please, if oyur fantomEngine powered game is not inside the gallery, let me know about it. I would love to display it there!


MikeHart(Posted 2014) [#81]
As the former wordpress integrated forum gave trouble regarding user registration, I have installed a regular forum now on my webspace. You can post all fantomEngine, Flurry for Monkey and things regarding my book there:

http://forum.fantomgl.com


nikoniko(Posted 2014) [#82]
I am playing with box2dintegration.monkey and found than SetDensity an SetFriction method don't apply new value to objects

format_code('
box2D.SetDensity(crate, 100.0)
box2D.SetFriction(crate, 111.0)
box2D.SetRestitution(crate, 0.0)
')

I tried different values to set. They are stores to internal var (GetDensity() returns new value) but objects behavior doesn't change.


MikeHart(Posted 2014) [#83]
Well, here they behave differently when you set different values. OSX and HTML5.


nikoniko(Posted 2014) [#84]
MikeHart wrote:
Well, here they behave differently when you set different values. OSX and HTML5.


Calling box2D.ResetMassData(crate) helps me to fix it.


nikoniko(Posted 2014) [#85]
oh, yes. It was in the b2fixture.monkey

format_code(' #rem
'/**
'* Set the density of this fixture. This will _not_ automatically adjust the mass
'* of the body. You must call b2Body::ResetMassData to update the bodys mass.
'* @param density
'*/
#end
Method SetDensity : void (density:Float)

'//b2Settings.B2Assert(b2Math.b2IsValid(density) And density >= 0.0)
m_density = density
End')


MikeHart(Posted 2014) [#86]
Yup. Thanks for the hint so others do not run into the same weird results.


debonzi(Posted 2014) [#87]
Hi Mike,
I am searching for some time but could not found the answer. So, I guess it is the right (or best) place to ask it.

Is there a way to make collision detection when using a tilemap imported from tiled?
Lets say I have a line of tiled in the bottom as a ground and some others in the edges to as walls. As far as I didn't find direct way to do it, I tried loop over every tile and create boxes (CreateBox) using the current tile parameters (witdth, height, etc) and set ColGroup, ColType, ColWith... But with this approach FPS goes really down what makes me believe it is far from an ideal solution.

Just to illustrate the code is following:
format_code('
'Load Tiled tilemap
level_tm = CreateTileMap("tiled/level_1.json", 10, 10 )
level_tm.SetLayer(layerGame)

Local tmpBox:ftObject
Local mapCount := level_tm.GetTileCount()
For Local mc:Int = 1 To mapCount
Local index:Int = mc-1
Local tileID:Int = level_tm.GetTileID(index)
Select(tileID)
Case 0 'Exit
tmpBox = CreateBox(level_tm.GetTileWidth(index), level_tm.GetTileHeight(index), level_tm.GetTilePosX(index), level_tm.GetTilePosY(index))
tmpBox.SetAlpha(0.4)
tmpBox.SetID(exitBoxID)
tmpBox.SetLayer(layerGame)
tmpBox.SetColGroup(exitGrp)
tmpBox.SetColWith(laryGrp, True)
tmpBox.SetColType(ftEngine.ctBound)
Case 1 'Floor
tmpBox = CreateBox(level_tm.GetTileWidth(index), level_tm.GetTileHeight(index), level_tm.GetTilePosX(index), level_tm.GetTilePosY(index))
tmpBox.SetAlpha(0.4)
tmpBox.SetID(floorBoxID)
tmpBox.SetLayer(layerGame)
tmpBox.SetColGroup(floorGrp)
tmpBox.SetColWith(laryGrp, True)
tmpBox.SetColType(ftEngine.ctBound)
Case 2 'Wall
tmpBox = CreateBox(level_tm.GetTileWidth(index), level_tm.GetTileHeight(index), level_tm.GetTilePosX(index), level_tm.GetTilePosY(index))
tmpBox.SetAlpha(0.4)
tmpBox.SetID(wallBoxID)
tmpBox.SetLayer(layerGame)
tmpBox.SetColGroup(wallGrp)
tmpBox.SetColWith(laryGrp, True)
tmpBox.SetColType(ftEngine.ctBound)
Case 3 'Portal Wall
'Case 4 'Unused
'Case 5 'Entrance
End
End

lary = CreateImage("lary.png", 100, 200)
lary.SetColType(ftEngine.ctBound)
lary.SetLayer(layerGame)
lary.SetID(laryID)
lary.SetColGroup(laryGrp)
lary.SetSpeedY(3)
')

Best Regards,
Debonzi


malick(Posted 2014) [#88]
Personally, I wrote a separate routine in which I use GetTileID to check the tiles 1 pixel below, left of, and right of the player and call it right after doing the normal collision check. If the tile ID is an ID that is assigned to a solid tile, I consider that a collision. That's probably not ideal, but it seems to run plenty fast enough for me.


MikeHart(Posted 2014) [#89]
Basically what malick said. Or, when you have loaded the map, scan through its tiles and create a correponding zone object (CreateZoneBox, CreateZoneCircle) which then you can setup for collision checks. In v1.53 there is a new Platformer example that shows a way how to do collision checks against a tilemap based on zone objects.


MikeHart(Posted 2014) [#90]
The example is located under

fantomEngine/Examples/TileMaps/Platformer


debonzi(Posted 2014) [#91]
Hi Mike, hi malick.
Thank you guys for the quick reply.
The example Mike gave will fit perfectly for my needs. I had already seen this example but didn't realize it was loading a map from Tiled. Shame on me :)


Neuro(Posted 2014) [#92]
site is down?


MikeHart(Posted 2014) [#93]
Wow you are quick. I am doing some reorg of my webspace. Still in the decision phase. Check back after the weekend please.


Neuro(Posted 2014) [#94]
Actually i havent looked at monkey in months and oddly enough, and fantomengine was the first thing i thought of when returning back to monkey. Talk about bad timing lol.


nikoniko(Posted 2014) [#95]
Where I may find info about ftScene - how and when is it using?


MikeHart(Posted 2014) [#96]
Scenes are basically container for layers. A scene can have several layers attached to it. A layer can be attached to more then one scene. You can do basic operations to a scene which will affect each attached layer. Position, Alpha, Transistions, visibility, activate.

There is an examples script shipping with fE.

When do you wanna use them? Stupid answer, but... it depends. Any time you want to modify several layer at once which are logically combined. Maybe you create a scene for each level in your game. I don't know. It was a user request where he wanted to have the ability to control layers together. Some kind of scene managment.


nikoniko(Posted 2014) [#97]
thks!


MikeHart(Posted 2014) [#98]
Question about tools for fantomEngine and/or Monkey.

Seperate tools or one big integrated tool?


nikoniko(Posted 2014) [#99]
what are the tools?


ordigdug(Posted 2014) [#100]
Mike, There are advantages & disadvantages to both concepts. Can you enlighten us on your ideas/thoughts related to this question.

I think most people would prefer one big integrated tool, if it does each tool/function well and can provide its own fully functional output independent from the other tools.
Each tool can be built individually within one large integrated tool program design/program. A large advantage is you only have to build the main user interface once and use tabs to select the different tool sets, this way you can easily add/remove tool sets from the main program.


MikeHart(Posted 2014) [#101]
The tools I have in mind are

- a animated image strip editor
- a particle editor
- a physics editor
- a texture packer
- a Spine like animation tool
- a map editor
- a bitmap font editor
- a localization editor

I can create for all of this seperate apps or bundle this inside one big app. With one big app, the step towards a tool like Game Maker is not really far. Why I want to create all these tools? To remove the dependency from 3rd party apps.

What would you think about a gamemaker like tool? What are your favorite 3rd party tools for your games/apps?


ordigdug(Posted 2014) [#102]
I say bundle inside one app, but make it modular so you can add tools/editors/features over time.


vmakar85(Posted 2014) [#103]
My compliments MikeHart ..

I honestly try to avoid tools that are monsters Swiss knives and food processors, in my opinion the tool must beat TOOLS narrowly focused, keep in mind that the hammer can nail down the screws but the screw with a screwdriver to tighten better =)

I think you need to create a poll on the site, in any case I think you will create a very good tool - whether it is all in one or many small and easy to use tools.

It is waiting! Thank you!


MikeHart(Posted 2014) [#104]
Version 1.54 was released.


nikoniko(Posted 2014) [#105]
Mike,

I am playing with waypoints example (for my future puzzle slider game) and have found that it works correct with eng.SetCanvasSize(480, 800, ftEngine.cmPerfect) only
with others canvasmode the waypoints is not matched cars' ways.

Screenshot for default value of canvasmode SetCanvasSize(480, 800)



Is it correct?


MikeHart(Posted 2014) [#106]
You have discovered a bug. Fixed already. Will post the fix in my forum tonight or tomorrow.


MikeHart(Posted 2014) [#107]
To all, it is better to post support requests in the forum on my website as I hardly visit this forum anymore.


MikeHart(Posted 2014) [#108]
The fix to ftPath.RenderAllWP is available now here:

http://forum.fantomgl.com/viewtopic.php?f=14&t=31&p=132#p132


navyRod(Posted 2014) [#109]
Sounds like a good plan--, I have bought your book and am now exploring your box2d module implementation

I have been checking out some of the box2D tutorials on the web with flash that Emanuele Feronato has posted

He shows some pretty cool stuff with destructible terrains and water demo's with box2d --

Seem like the flash tutorials he shows is able to run with several dozen box2d objects and keep a pretty good frame rate .


Interesting -- seems I pasted t wrong thread ... could have sworn I was posting to a different post by mike but I guess I really am getting old...

Should the monkey box2d translation have just as good of performance ??

Thanks


navyRod(Posted 2014) [#110]
Sounds like a good plan--, I have bought your book and am now exploring your box2d module implementation

I have been checking out some of the box2D tutorials on the web with flash that Emanuele Feronato has posted

He shows some pretty cool stuff with destructible terrains and water demo's with box2d --

Seem like the flash tutorials he shows is able to run with several dozen box2d objects and keep a pretty good frame rate .


Interesting -- seems I pasted t wrong thread ... could have sowrn I was posting to a different post by mike but I guess I really am getting old...

Should the monkey box2d translation have just as good of performance ??

Thanks


MikeHart(Posted 2014) [#111]
I think it is as good as it can be.


MikeHart(Posted 2014) [#112]
Hi folks,

version 1.55 is released. http://www.fantomgl.com/2014/09/05/fantomengine-v1-55-released/


Neuro(Posted 2014) [#113]
Awesome on the sprite sheet functionality now! But is there a particular sprite packer you are using to build out the sheets now?


MikeHart(Posted 2014) [#114]
I use Texturepacker.


MikeHart(Posted 2014) [#115]
fE is on GitHub now. Anyone who would love to take it over and is motivated?

https://github.com/MikeHart66/fantomEngine


Steve Oliver(Posted 2014) [#116]
@MikeHart

Mike, does that mean you're finished with fE?


MikeHart(Posted 2014) [#117]
Steve, fE is not finished. And I told my wife about my thoughts about handing it over and you should have seen the look on her face. A "Don't you dare" kinda look. LOL
So, I guess I keep going :-)


Nobuyuki(Posted 2014) [#118]
no offense Mike, but I'm glad your wife has some sense! When Mark started winding down on Monkey updates you made it sound like it was literally the end of the world; I wasn't gonna be surprised if you ended up dumping all your Monkey projects shortly thereafter but like I said, I'm glad someone's making you keep going, lol.


Steve Oliver(Posted 2014) [#119]
Send my regards to Mike's wife!


Neuro(Posted 2014) [#120]
+1 for Mike's wife


MikeHart(Posted 2014) [#121]
Hehe, she is smiling I can tell you.


MikeHart(Posted 2014) [#122]
Hi folks,

please welcome Vili Lehtinen as he has just joined the fantomEngine development team. After seeing his Monkey X creations, I had no choice but to ask him to join the dev team. I am positive that his ideas and skills will raise fE to a new level. We are already planning the next incarnation of fantomEngine. More about it in the not so distant future.

Take care
Michael


RobB(Posted 2014) [#123]
Sounds exciting. Thanks for your program and enjoy creating together.


spintop(Posted 2014) [#124]
What would you think about a gamemaker like tool?


To MikeHart,

If fantomEngine 2 becomes a GameMaker like tool, it will be very powerful. Many beginners may start learning Monkey and use fantomEngine 2. Moreover, I think that fantomEngine 2 should be a commercial product. FantomEngine 2 should be sold on this Monkey official website. Just like Ignition X.!!!


ziggy(Posted 2014) [#125]
@MikeHart: That's nice!


MikeHart(Posted 2014) [#126]
Thanks guys for your suggestions and your kind words.


MikeHart(Posted 2014) [#127]
..


Danilo(Posted 2014) [#128]
Noticed yesterday that you deleted the github stuff at https://github.com/MikeHart66/fantomEngine

Will the project continue exclusively at http://www.fantomgl.com/fantomengine-monkey-x/ ?


MikeHart(Posted 2014) [#129]
Just temporarily.


MikeHart(Posted 2015) [#130]
Hello fellow fantoms,

I have uploaded version 1.56 of your favorite game framework for Monkey-X. Biggest features in this release are the support for multiple tilesets in Tiled maps, automatic pooling of objects and the ability to use custom objects with every basic object type now.



So grab the new fantomEngine from the download section.

But here is the list of changes:

New functionalities

fantomEngine now automatically pools ftObject.
New method ftObject.GetColor:Float[]() – Returns the color of an object in an array
You can use custom objects now with basically all type of fantomEngine objects.
Added GetCam:Float[](), GetCamX:Float() and GetCamY:Float() methods to the ftEngine class.
When returning TRUE from ftEngine.OnObjectTouch, no further touch checks are performed this frame.
When returning TRUE from ftEngine.OnObjectCollision, no further collision checks of this object are done in this frame.
Use ftObject.GetTileMap:ftTileMap() to return the ftTileMap object of your ftObject.
fantomEngine now supports Tiled maps with multiple tilesets.

Fixes

fixed constant ftEngine.otPivot which caused points not to be rendered since version 1.55.
fixed Platformer example which didn’t show the whole screen anymore.
fixed ftObject.CheckTouchHit when object has the touchmode ftEngine.tmBox and was rotated.

Changes

Cleanup sources from Print statements.
Changed all Error messages to only be checked and shown in DEBUG mode.
Moved ftObject tilemap properties and duplicate methods into the new ftTileMap class.
ftEngine.TouchCheck:Void(touchID:Int=0) will now check the layer in the backwards order. The last created layer (the top one) at first.
Changed all ftObject._internalPointInside… methods so the check includes the borders of an object too, not only inside the object.

New example

Objects/Creation/PoolingObjects/PoolingObjects.monkey
TileMaps/EndlessMap/EndlessMap.monkey
TileMaps/Tiled/MultiTileSets.monkey


Neuro(Posted 2015) [#131]
oooohh....nice!


Amon(Posted 2015) [#132]
Very Cool!


Why0Why(Posted 2015) [#133]
A lot of nice work there, Mike. Are you working on a project that spurred on all of the updates?


MikeHart(Posted 2015) [#134]
Sorry, I didn't notice your message before. Thank you for your kind words.

Are you working on a project that spurred on all of the updates?


Kinda. My wife and I designed an action RPG atm. It will be 3D so I am not sure if I will be able to do it in Monkey.
But reagrding fantomEngine I am much more motivated right now and have more time for it. And that is why I published a little tutorial about the virtual canvas system of fantomEngine here:

http://www.fantomgl.com/2015/03/29/fantomengine-handling-virtual-canvas/




MikeHart(Posted 2015) [#135]
I have posted a new tutorial on my blog to show how to drag an object around the canvas:

http://www.fantomgl.com/2015/04/06/fantomengine-tutorial-dragging-objects/




Why0Why(Posted 2015) [#136]
Thanks for the tutorials. Always nice to have!


apamment(Posted 2015) [#137]
EDIT: Please disregard, I discovered that I need to have the same margin as the spacing for it to work properly. It's working perfectly now.

I'm trying to make a platformer with fantomEngine and using Tiled to design the levels. I'm having issues with image filtering and the tiles leaving artifacts when you move, I read somewhere that the way you get around that is by having spacing between your tiles as a copy of the edge pixel, However I am still having the problem, and fantomEngine appears to be scaling the tiles + edge instead of clipping the edge off.

Also, I noticed that when adding padding, GetWidth of the tile map returns the width of a tile plus spacing, so a 64 pixel tile it says 66 pixels if you have 1 pixel margin and 2 pixel spacing. I've tried a few different spacings/margins the higher i go the more corrupt it gets. Here is some example pictures with 4 pixel margin and 8 pixel spacing.



This is what that part of the level should look like (how it looks in tiled)




MikeHart(Posted 2015) [#138]
Hi appament, i won't have access to my computer for another 2 weeks. Please look into ftObject.Settilescale... To see if that will help. When i am back i can look closer into it.