This post act as a survey about orx and a "hidden" functionnality. Actually Iarwain wrote something like a C++ wrapper for orx, but it's not released, because of the lack of documentation.
I discuss with him to release this code for you, and I suggest him to explain this wrapper in a post to get your feeling on it. So, you can reply to give us your opinion. Tell us if you want to try it, if you think this is useless, usefull or something else.
I said wrapper, but it's not really a C++ wrapper around orx. I'll try to explain.
First, the name of this project is Scroll.
So, I don't know if you prefer C programming or C++, in my case, I prefer C++ because I use it for a long time.
Scroll doesn't provide an COrxObject, COrxCamera, COrxSound, COrxViewport etc, it's not the kind of this project. It simply manage "object", called ScrollObject. To be simple, here is a description of what Scroll is doing :
- define a central part, called ScrollBase (derived in a class named GameEngine in my case). This is a "singleton" pattern, only one instance. This class manage some objects, called ScrollObject.
- ScrollObject define a lot of methods, for example : Update(), OnCollide(), OnSeparate(), OnCreate(), OnDelete, etc. It's very easy to get the orxOBJECT binded with a scrollobject, so you can use your favorite function on it.
Suppose you have a game, with an object that have a particular behaviour. For exemple, a ball. With Scroll, you just have to implement your CBall class, derived from ScrollObject and bind it with the name of the object in the config file. That's all. You just have to implement your ball in your .h/cpp.
Another big part of Scroll is an editor. You can run your game without the "main loop". You can change camera position/zoom, moving/scaling/creating objects (with a layer functionnality). All of those settings can be saved in a .ini file and can be used as a "level" in runtime. Scroll will load and create/delete those objects for you, so you didn't have to manage all of that by yourself.
For example again, ScrollBase provide some methods like OnMapLoad(), Pause(), and other stuff.
So, it's not really a C++ wrapper. When you implement your object, you have to use all of the orx functionnality. Each functionnality provided by Scroll have a real interest. For exemple, ScrollObject doesn't provide a SetPosition() method, there's no interest. To do that, you have to do something like : orxObject_SetPosition(GetOrxObject(),&vPos) (where GetOrxObject() is a method of ScrollObject)
I tried to do a summary here, it's an easy explanation. It not cover all the power of Scroll.
This post was just to have your feeling about this project. Do you prefer to use orx alone, or do you want to try Scroll ?
I know there're few users of Scroll, perhaps they can add some comments or corrections to my post
And to finish, sorry for my poor english ^^
I do a lot of non-standard things like implementing my own primitive collision detection, generating objects on the fly, using a custom "repaint tiles" method instead of screen scrolling.
I have also been separating up many things into their own code files to keep things organised, while the main code file controls the updates in each. So the organised custom classes serve well.
I don't think I would shift to Scroll for the current project. From the examples you mentioned above, I am not sure that it would save that much time. Perhaps for simpler stuff, I'm not sure.
With all that said, my c++ is not overly strong. But it's from an active working perspective.
I just wanted to add some details:
- Scroll is a thin layer, ie. it's only a bunch of non precompiled files so it's easily expandable by anyone and even more easy to integrate.
- There's actually a SetPosition! It's only a convenience wrapper that uses vector references instead of pointers and that allows to set the position locally or globally. So it wasn't probably the best example on that one.
As for me, I'm not using the editor part of it but I'm still using Scroll for all my projects because I'm lazy. Instead of listening for events and registering update callbacks, I'd rather simply override a method. That and the object management that allows easy linking between orx objects and my game classes. That's about it!
Sausage, I'm also using a tiled rendering for a project I recently started so I guess it's not that uncommon for an orx use. I couldn't find any other easy and efficient alternative that would allow me to emulate the ZX Spectrum color bleeding for people who don't have shader supports.
I would love to try it out for my current game project.
I actually was about to write my own C++ wrapper but if Scroll is already there then why would i bother? I could probably add something to Scroll underway..
You can get the most recent version here, including some instructions on how to use it in the forum thread. Let me know if you have any questions/suggestions.
Thanks a lot
I will try to combine Scroll and the iPhone demo.
So i have a working iPhone demo without any objects but with Scroll. It just creates a viewport (had to rename Viewport to MainViewport in the config). Then it runs and calls the Run method all the time.
I tried to add a "player" object:
Graphic = FullGraphic
AnimationSet = AnimSet
and in code i have this:
However, it fails inside the orxObject_GetName(const orxOBJECT *_pstObject) function.
In particular this line fails with "_pstObject == NULL": orxSTRUCTURE_ASSERT(_pstObject);
Ah well, where would be the fun if you hadn't run into any problems?
At first glance, I'd say it might be a debug/release mixup. That happens when defining __orxDEBUG__ and linking with the release lib or when not defining it and linking with the debug lib.
Could it be what happened on your side?
Another possible issue would be that your config wasn't loaded properly, either not loaded at all or inside a file saved with non UTF-8 unicode (in which case you'd get an error message in debug if you're using the SVN version of orx and not the 1.3rc0).
Actually, I assume you're using the latest SVN as this version of Scroll is unlikely to work properly with 1.3rc0 which is over 9 months old now.
Lemme know if you get more info.
I am ready to give Scroll a try if it is recommended for beginners.
Thanks for your reply.
Yes I rebuilt everything from subversion. Basically I took your iPhone demo from svn and stripped it down to an empty orx-on-iphone project. Then I added Scroll headers and created my simple game class and some ScrollObjects (character, player). I think you might be right that I have a situation with release game running debug library. I will check that tonight. However, would a debug build of orx library even show a coloured screen at all? I though it would crash at startup.. But I had a coloured viewport visible on iPhone! The problems started when I added the Player bit.
Anyway I will check your assumptions tonight and report back.
I will try to code something meaningful and report back if anything goes wrong
When a Debug/Release mismatch happens, the grain of salt (huhu) breaks the whole thing.
@acksys: I'll setup a temp Hg repository on Bitbucket for now as I still don't know if I want to host orx and scroll under the same roof.
When I'm done with the 2D skeletal anim system (yes, I very recently started to work on it again after months), orx will probably turn 1.4 and get hosted with Hg either on Bitbucket or GoogleCode, haven't settled on which one yet. I'll then take the decision if I reunite orx/scroll in the same repo or not.
Now when i have a bunch of objects with animation working i have many more questions then i thought i would
1) So i have my player object. In the config file, Player has some animations which I need to turn on/off at some point. The only way I found to do this is:
This looks like a really dirty hack to me. I would expect a way to inform the player that it should change animation. And indeed, there are a couple of virtual methods: OnNewAnim and OnAnimEvent. But how do I trigger them?
2) Sound is not working. I couldn't find any sound code in Scroll so i did this in OnStartGame:
bg_music_ = orxSound_CreateFromConfig(orxConfig_GetString("Music"));
This code used to work without Scroll but with Scroll it won't work for some reason. Maybe this code belongs in Init though. Didn't check.
3) How do I capture input?
I don't mean keyboard because I'm on iPhone. I know that the MOUSE_LEFT event works as a touch but how do I actually detect a tap on some orxObject (or better my ScrollObject subclass). I have an onscreen "pad" with two buttons. For each button I have a ScrollObject. All I want is some way to get notified inside the button class that a touch happened.
Thanks for your time
There's currently no wrapper for accessing anims on a ScrollObject but they're easy to add.
OnNewAnim is where you get notified when your ScrollObject is playing a new animation, letting you know if the previous anim was cut or not.
OnAnimEvent is where you'll get notified of encountered custom event (ie. the ones defined in config).
Scroll doesn't wrap any sound code as they'd be the same as orx. I've only done convenience wrapping or added new features in Scroll but I'm still using calls to the underlying orx API as I didn't want to clutter too much Scroll's API. That being said, it's totally possible to entirely wrap orx in Scroll if someone has the patience to do so.
OnStartGame should be called after the init phase, so I'm not sure why it's not working in your case. Are you in the correct config section, just in case?
Also, I personally avoid doing calls to the sound API when I can. For music playing I simply define in config a BackgroundMusic object that will play the music for me when created. I usually then add this object as a child of my scene, add it using the level editor or create it programmatically when loading the level.
However it's simply a matter of taste, there's nothing wrong with using the sound API, it's just that I like to use the object as wrappers as much as I can.
I usually call Scroll::PickObject in my game loop and then forward call a method of the class Button if the ScrollObject is of the right class (or you can extend the ScrollObject interface with a virtual method if you'd rather).
Lately I've bypassed this by simply using the config and input modules:
- I pick the object using the mouse's world position
- I push its section and look for an Action attribute
- if found, I'll then activate the matching input with orxInput_SetValue(orxConfig_GetString("Action"), orxFLOAT_1);
- I simply handle the input within an event handler, that allows me to easily add other way of activating a button (like keyboard shortcuts when debugging on PC) by simply modifying the config and not touching the code.
My pleasure! Let me know if some of my answers weren't very clear.
Thanks for your detailed explanation. I got most if it working and even extended Scroll to support SetTargetAnim and OnInput. I also fixed my sound problems.
Now I need to know how to handle multitouch input. Is there a way? I thought MOUSE_RIGHT would do the trick but no luck :-)
Yeah, I only plugged MOUSE_LEFT for single touches, but I could potentially plug all the other touches on MOUSE_RIGHT, MOUSE_MIDDLE, etc... even though they won't cover all the touches.
As for getting the multitouch info, it's not yet completely unified, so it's a bit different on Android and on iOS. Both will send you the same events (orxSYSTEM_EVENT_TOUCH_BEGIN/_MOVE/_END) but the payload will be different. On Android it'll be orx-defined values whereas on iOS it'll be directly the NSSet containing all the touches.
I'll try to unify that soon-ish, probably within a week or two.
You can find all those info in code/include/core/orxSystem.h
Oh wow it's good to know that touch_begin/end events are available! At this moment I'm trying to compile my stuff for android so it's really good timing to know about this differences now :-)
As you are yet to unify stuff I will add my 50c with a small request: When you will have unified structures to transfer touches into orx, don't forget to add the timestamp (hardware touch timestamp) to that structure as in some games (rhythm games for sure) it's crucial to get the real timestamp of the event even though the actual event may occur with a delay (milliseconds are important!).
I have an interest in this also and faistoiplaisir was a good help in the other thread.
My designers have said we don't need multitouch for the current project, but I have a suspicion I may be required to implement it before release
Also, I'll need someone to test the modifications for me as I can't test on iOS devices right now.
Well, so I wasn't really awake 2 days ago. There's a good reason why only MOUSE_LEFT is plugged on the touch event right now: a mouse can only have one position whereas each touch has its own position. The workaround this would be to support more than one mouse, in the same way we support more than one joystick.
It can be done but it's not on my short term todo list.
That being said, I'm on my way to the touch event payload uniformization.
NB: for now it won't compile on Android till faistoiplaisir has the opportunity of updating that version.
That should probably be resolved before a day or two. No pressure, faistoiplaisir!
But the work is only done for android 'non-native' (the one that use the NvEvent framework).
For now, if you want to compare the timestamp provided by the payload, you have to compare it with orxSystem_GetTime().
In another post, about the multitouch, I sent a Multitouch.zip file including a TouchManager class. I use it in my actual game. This manager provide a "bIsActive" and "bStatusChanged" member for each touch. In addition, you can now check the pressure and the timestamp.
So, in case of you use this touch manager, you can get the new version here (supporting the new payload). https://forum.orx-project.org/uploads/legacy/fbfiles/files/TouchManager.zip
Do you think you could have a look at the native part at some point? No rush though.
I took a look at the native version. I think it's easy to do. Similar methods are available in Java and Native API.
But, since I never compile myself the native version, and because I don't use it, I think I don't do that quickly.
But If someone need that immediatly, I can do an effort
If no one need it immediatly, it can wait ^^
In the futur (probably my next game) I will use the native version. In this case, I will change that to support more than one touch (for now, I confirm, the native version manage only one touch).
So, just be patient ^^
The second tutorial (object binding) is in progress and should be finished soon.