tag:blogger.com,1999:blog-40831310790658527682024-02-18T18:23:23.457-08:00Corona Development BlogPaul Robsonhttp://www.blogger.com/profile/12278875872815047472noreply@blogger.comBlogger41125tag:blogger.com,1999:blog-4083131079065852768.post-21581758598366166082014-07-05T12:40:00.004-07:002014-07-05T12:40:39.444-07:00I should update more often.Well, Phantom Slayer is pretty much done and dusted. I'm actually really pleased with it, and there's an awful lot of reusable code in there. <br />
<br />
It all seems to work really nicely ; it's dead easy to build Composer Scenes, and change them, there's a library which does tutorials for games, where it sort of plonks comments on top of the game, again, pretty much automatically.<br />
<br />
It's open source ; it's another demo for Executive really, but I'll probably build it and upload it.<br />
<br />
<a href="https://github.com/autismuk/Phantom-Slayer">https://github.com/autismuk/Phantom-Slayer</a>Paul Robsonhttp://www.blogger.com/profile/12278875872815047472noreply@blogger.com0tag:blogger.com,1999:blog-4083131079065852768.post-7011207746835857822014-06-27T11:47:00.004-07:002014-06-27T11:47:39.420-07:009 1/2 days<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0L97aadSsyQJLs_NEbl3JV9T3I5ilizqglGc9L1NWxWIVJo4dRZxOLPO1sJ3w_LRj0ILsR_PnM25b2DeCWsaRiP6Keisfno3YoCRC_qM4xtTa4YafScW3SS8JFYk76Ili1aDL9Qw7pGM/s1600/grab.tiff" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0L97aadSsyQJLs_NEbl3JV9T3I5ilizqglGc9L1NWxWIVJo4dRZxOLPO1sJ3w_LRj0ILsR_PnM25b2DeCWsaRiP6Keisfno3YoCRC_qM4xtTa4YafScW3SS8JFYk76Ili1aDL9Qw7pGM/s1600/grab.tiff" height="215" width="400" /></a>Well a fair bit has been going on ; I finished the Executive and got the state transition working, and<br />
that now works like a simple, but proper game.<br />
<br />
I'm working on a remake of a game called Phantom Slayer, which was originally for the Dragon / TRS80 Co-Co computer (a 6809/6847 based home computer from the 1980s).<br />
<br />
<a href="http://www.lcurtisboyle.com/nitros9/phantom_slayer1.gif" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="http://www.lcurtisboyle.com/nitros9/phantom_slayer1.gif" height="300" width="400" /></a>It originally looked like the one below (and with a switch, it still does look like that), pretty much - it's a fairly simple explore a 3D Maze sort of game.<br />
<br />
It's a useful test more than anything else (though the original game is <i>really</i> creepy) writing to something of a specification rather than something just knocked together to test the Executive system.<br />
<br />
It can be sort-of played (at the moment you can walk about and teleport but not do anything else) and it is at https://github.com/autismuk/Phantom-Slayer if anyone wants to tinker with it. I will probably put it in the App stores when I've finished just for the sheer heck of it.<br />
<br />
As it is under development, obviously, both it and the Executive are prone to change. I did make one change ; the ability to pass parameters into FSM events and through into the preOpen (think 'Create') phase of the scene manager. Though this is a backwards compatible extension ; I'm hoping that there won't be any major changes.<br />
<br />
<br />
<br />
<br />Paul Robsonhttp://www.blogger.com/profile/12278875872815047472noreply@blogger.com1tag:blogger.com,1999:blog-4083131079065852768.post-50465301213780657862014-06-18T03:36:00.003-07:002014-06-18T03:37:48.026-07:00Dumb Design Decisions 101Feeling dim this morning.<br />
<br />
I realised I'd done something really stupid. OOP is supposed to be about Classes and Object Instances, right ? In a 'hack' designed to get round the problem of attaching game objects to instances of executives, I'd designed it so that when you created a new GameObject Class to subclass (the Executive:createClass() method) you provided an instance of a parameter.<br />
<br />
So .... all instances of that class now belonged to one, and only one, instance of the executive.<br />
<br />
Fortunately this dumb mistake has been fixed and the executive is where it belongs in the object constructor. When you create an object of some sort, you tell it which executive it is to be added to.<br />
<br />
This is a hangover from SOE, which is the same basic idea, except there is one, only one, executive, it's a singleton.<br />
<br />
I'm writing a scene sort of thing. The idea is that there is a Factory Class for executives, this is the equivalent of a Corona Scene. This factory class has a constructor/destructor (for resources), and methods to create a new 'scene' (e.g. create an executive and populate it with objects', start it, and methods to stop it, and tidy up (delete the executive). The last two don't do much, as the executives objects are responsible for actually stopping it (as in, say, Flappy Sphere, the game stops when there are no bird objects left).<br />
<br />
These belong to a global class, probably called 'Game' which is a collection of such, and it just transitions between them using an FSM and the TransitionManager library.<br />
<br />
To this end, I've added a couple of things ; there is a very simple finite state manager, which just maintains a list of states and states events , and broadcasts messages as you switch between them. Additionally, <i>every </i>executive now has, on demand an owning displayGroup object - I need this because there needs to be some way of having all the graphics in a particular setting together so you can transition them in or out.<br />
<br />
With a bit of luck it will be dead simple. I will end up with a FSM for the game outline, which has attached Executive Factory objects, and the FSM just switches from scene to scene automatically.<br />
<br />
You can see the outline of this at the end of Flappy Sphere (at the time of writing)Paul Robsonhttp://www.blogger.com/profile/12278875872815047472noreply@blogger.com0tag:blogger.com,1999:blog-4083131079065852768.post-6383072354170280322014-06-15T10:31:00.000-07:002014-06-15T10:35:01.303-07:00Flappy ... Sphere ?<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLvnYplyXiZ3QMoDNDVv8lpw39WiiL_koadTrFStqKAZSNmfCugYk2fzQGmVPXVmNqulQsuqDa0sZt07YmR9-iuxPiColnvtRBHvriVPCY-Ftj-uYfrO0P6iJcg05tFTudFaBef1p6Y_0/s1600/grab.tiff" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLvnYplyXiZ3QMoDNDVv8lpw39WiiL_koadTrFStqKAZSNmfCugYk2fzQGmVPXVmNqulQsuqDa0sZt07YmR9-iuxPiColnvtRBHvriVPCY-Ftj-uYfrO0P6iJcg05tFTudFaBef1p6Y_0/s1600/grab.tiff" height="215" width="400" /></a></div>
I have written a separate simple game, this one called 'Flappy Sphere' (guess what it is based on ....) which includes particle effects and bitmap fonts.<br />
<br />
This is complete and working, but I want to add an FSM library and associated Scene manager, and Flappy will become a host of that (at the moment it is a 'one scene' game, so to speak.<br />
<br />
Flappy Sphere is about 250 lines of code (including comments), but that's with external libraries for the particle system and bitmap font.<br />
<br />
There's not much to it really - pipes, 'bird', score, 'get ready' text and a background that pass a few messages about - so for example, the background sends a message to the bird when it is tapped.<br />
<br />
The neat thing about this is it is trivially easy to add more birds (spheres ?) just at will, just by creating them, bit like in the 'Pong' demo. Or pipes, want 25 pipes on the screen, dead easy. You can even have more than one score and it will work (because the score is implemented by messaging)<br />
<br />
The only code that is actually specific to multiple 'birds' is when a collision is detected and a bird blown up, it checks to see if there any bird objects in the game before ending it.<br />
<br />
So you could add another bird just with:<br />
<br />
<span style="color: blue;">Bird:new({ gravity = 100, x = 100 })</span><br />
<br />
and it will just work. Flappy Bird with several birds is really hard :) Changing the gravity for different birds is even harder.<br />
<br />
Some things are more optical. When you move a sphere it doesn't use messaging to query for collisions, it gets a list of 'obstacle' tagged objects and asks each of them if it's hit them by calling it's 'has collided' method. It's a trade off between decoupling and efficiency. Isn' t everything ? :)<br />
<br />Paul Robsonhttp://www.blogger.com/profile/12278875872815047472noreply@blogger.com0tag:blogger.com,1999:blog-4083131079065852768.post-91668735438694042482014-06-13T13:53:00.002-07:002014-06-13T13:53:56.197-07:00Executive is up and running.<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisgP_3WtVKj25Xpht2SXafiLwV5qTcQ50hoCWDcdUCBo52VLLkRD5q4qkrxmreyaIYM3Mb7RWmOxFcQir9if32WwdFvoooIKGWUNi4qSH7cvUUAkPGU1d3npQZRtBMhFGFfXSMJklRS2M/s1600/grab.tiff" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisgP_3WtVKj25Xpht2SXafiLwV5qTcQ50hoCWDcdUCBo52VLLkRD5q4qkrxmreyaIYM3Mb7RWmOxFcQir9if32WwdFvoooIKGWUNi4qSH7cvUUAkPGU1d3npQZRtBMhFGFfXSMJklRS2M/s1600/grab.tiff" height="215" width="400" /></a></div>
The executive engine/framework is up and running, this is an example of it running.<br />
<br />
There are four classes here - the bat, the score, the ball and the controller, everything is controlled by the executive.<br />
<br />
The controller is a self contained object, so it just can be loaded and used - you require it in and attach it, and you can then access it via executive.e.controller - I decided not to use a messaging system.<br />
<br />
Messages are used for the ball delay at the start, to update the score, and the balls each broadcast a message to 'obstacles' to check for collisions.<br />
<br />
It allows you to switch pretty much as you want between asynchronous messages and direct messages - so for example to increment the score you can either use<br />
<br />
<span style="color: blue;">self:sendMessage("score",{points = 10})</span><br />
<br />
or you could with an extra line or two do it something like<br />
<br />
<span style="color: blue;">exec.e.score:addScore(10)</span><br />
<br />
I quite like this design. This code is almost completely unchanged from the SOE demo, except for the basic API stuff which has changed slightly.<br />
<br />
Because objects are automatically attached (normally, the controller isn't yet) then you can simply add bats and balls as often as you want and it just works. The main code looks like this:<br />
<br />
<span style="color: blue;">Bat:new({ x = 32 }) <span class="Apple-tab-span" style="white-space: pre;"> </span>Bat:new({ x = display.contentWidth/3 })</span><br />
<span style="color: blue;">for i = 1,33 do Ball:new({}) end <span class="Apple-tab-span" style="white-space: pre;"> </span>Ball:sendMessage("ball",{},1000)</span><span class="Apple-tab-span" style="white-space: pre;"><span style="color: blue;"> </span> </span><br />
<br />
Two bats, 33 balls, and a delay of 1000ms before balls receive an empty message which tells them to start moving.<br />
<br />
One problem, which is a lua issue, is with executive objects now being non-singletons, when you require an object it doesn't know which instance of the executive to attach itself to. So at the moment it is added as a mixin (this is used for objects with non-nil metatables, like Corona display objects, see the score in the pong Demo as an example).<br />
<br />
<span style="color: blue;">executive:addMixinObject(require("controller"):new({}))</span><br />
<br />
i.e. require the controller class, create a new instance, and add it as a mixin object. May be a case for having an addRequireObject("controller",{}) method. I will give it some thought.<br />
<br />Paul Robsonhttp://www.blogger.com/profile/12278875872815047472noreply@blogger.com0tag:blogger.com,1999:blog-4083131079065852768.post-27747165014639586872014-06-13T04:23:00.003-07:002014-06-13T04:23:48.893-07:00More experimental enginesI got Comet to where I want it, but then decided it was too theoretical. Coding is a mixture of structure and pragmatism, and both a classical OOP design and a pure component design are too much of one.<br />
<br />
So I'm working on "executive" which is a combination of the two. It is an object aggregator and controller, with built in functionality - currently updating, inter object messaging and timers, which allows a semi-component approach via mixins. Objects are tagged (the tags are recorded in the executive) and it can be queried for all objects with 'ammo' tags, or whatever.<br />
<br />
For its frame system, tagging an object with 'update' causes it to have its onUpdate() method called on a regular basis.<br />
<br />
It's on its second design, the first one , called SOE (Simple Object Engine) is okay, but I improved the design and cleaned it up.<br />
<br />
None of these various engine ideas are particularly long, maybe a few hundred lines of code each.<br />
<br />
Because the executive itself is an object, I'm going to try and build a FSM/Composer system where each scene is an Executive object, thus making the scene transitions semi automatic.Paul Robsonhttp://www.blogger.com/profile/12278875872815047472noreply@blogger.com0tag:blogger.com,1999:blog-4083131079065852768.post-42839013298296151472014-06-05T06:27:00.001-07:002014-06-05T06:27:53.647-07:00So version 4 of Comet is now the master branch<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiytuD8DBc7iL-eY7PJAmBrS354OkprzUWv2evjfN-keRXF5qNaLE775Dmbb15Edea_jCLV9f3cS7znrD6e8P6U0xq5bcBbdKURploHvithNWNS8C7lR8iTmoYPhJEJh3_F8002j0iEwSs/s1600/grab.tiff" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiytuD8DBc7iL-eY7PJAmBrS354OkprzUWv2evjfN-keRXF5qNaLE775Dmbb15Edea_jCLV9f3cS7znrD6e8P6U0xq5bcBbdKURploHvithNWNS8C7lR8iTmoYPhJEJh3_F8002j0iEwSs/s1600/grab.tiff" height="320" width="172" /></a></div>
and can be downloaded from https://github.com/autismuk/Comet - there's a very simple demo there with rotating crabs which is just really a placeholder.<br />
<br />
Later on I should bring the controller thing back and a better commented demo.<br />
<br />Paul Robsonhttp://www.blogger.com/profile/12278875872815047472noreply@blogger.com0tag:blogger.com,1999:blog-4083131079065852768.post-53894623197600955812014-06-04T02:05:00.002-07:002014-06-04T02:05:16.709-07:00I'm still not happy with it ......So it is going into version 4.......... proper design document this time, and I know what I want to do. I'm <i>hoping</i> this will be the last one.Paul Robsonhttp://www.blogger.com/profile/12278875872815047472noreply@blogger.com0tag:blogger.com,1999:blog-4083131079065852768.post-32522149210297209272014-06-02T08:11:00.000-07:002014-06-02T08:11:14.744-07:00A working demo of C/E Systems<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; margin-left: 1em; text-align: right;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidJdP34y2ophAGKicH2N1CHlzNPb7Op9uRbn0lBWsYnTffh3ALYc9JmK6qUDGKae1fREN00bKETBLhMwSw4n8B77C4ZoXIprzP9Z1nZefsMzYB2QvKRe5GBKOcfyy4KIJSVuV6PNpe7-k/s1600/grab.png" imageanchor="1" style="clear: right; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidJdP34y2ophAGKicH2N1CHlzNPb7Op9uRbn0lBWsYnTffh3ALYc9JmK6qUDGKae1fREN00bKETBLhMwSw4n8B77C4ZoXIprzP9Z1nZefsMzYB2QvKRe5GBKOcfyy4KIJSVuV6PNpe7-k/s1600/grab.png" height="400" width="206" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Squares and Crabs</td></tr>
</tbody></table>
There's now a useable demo of this system on https://github.com/autismuk/Comet.<br />
<br />
You can see a piccy of it here. It has several components, mostly very basic - position, size, colour, coronaObject, velocity,power and so on.<br />
<br />
Then there are two slightly more complex ones that create a sprite and a square respectively.<br />
<br />
Because it is a hybrid, the controller isn't a component though. Partly because if it was, you'd have one every time you created an entity. What it is is a link to an instance of the controller.<br />
<br />
So what it does is move the crabs and squares round in response to the controller, at varying speeds.<br />
<br />
The systems are as follows :<br />
<br />
There are position/CO and size/CO and colour/CO that update the corona object from the position, colour and size components.<br />
<br />
There's a controller/velocity/power component that updates the velocity from the single controller instance. Power is how fast it goes, the scalar value of the velocity as opposed to the direction which comes from the controller.<br />
<br />
Lastly there is a position/velocity component that updates the position from the velocity. This last one uses a thing called deltaTime (okay, I pinched the name from Unity ....) which scales movements to consistent units.<br />
<br />
It did strike me that people might know what C/E systems are.<br />
<br />
You can read about it here http://en.wikipedia.org/wiki/Entity_component_system<br />
<br />
Basically, think of the things on the screen as entities (e.g. each crab is built out of an entity) that are built out of components, which are things like speed, position, alpha, a sprite and so on.<br />
<br />
The nifty thing is the automation. If you add a velocity component it automatically moves the position component. If you add a controller component it starts being controlled by it. If you remove it, it takes it away again.<br />
<br />
It sounds a bit mad, really. But one of Corona's biggest rivals, Unity3D, works pretty much like this.<br />
<br />Paul Robsonhttp://www.blogger.com/profile/12278875872815047472noreply@blogger.com0tag:blogger.com,1999:blog-4083131079065852768.post-75879519708752265472014-06-01T01:05:00.005-07:002014-06-01T01:05:58.231-07:00And more stuff about Entity/Components/SystemsSo Comet is now in its third version.<br />
<br />
Like many systems, ECS work okay in theory but there are often problems in practice. One of the problems is the conceptual idea that components should be very basic, data only.<br />
<br />
The problem with this sort of concept is it works okay up to a point, but if you want something as a dedicated component which does a lot you end up with umpteen systems to handle it.<br />
<br />
I experimented with this in v2, which had a joystick control component (touch one), that you could just plug in and it worked as if it was (say) a square in Corona. All you had to do was something like:<br />
<br />
<span style="color: blue;">spriteEntity:addC("joypad")</span><br />
<br />
But what it did do was operate on the components that do work as very simple ones - coordinate pairs, velocities and so on. I had this very simple demo which was a couple of sprites with coordinate positions, velocities and sizes. You could then add the joystick component and it would update the velocities and so on automatically, which propagated into the positions, which meant in practice that you controlled the sprite with the joystick automatically.<br />
<br />
This is, I think, the way forward, having code not so much in the components as associated with it. So your component members might be a joystickReference only, but the component has an associated constructor and destructor that create and delete it as you add or remove the component.<br />
<br />
It seems to work quite well, though v3 (again, learning from mistakes and better engineered - I've never written an ECS framework before) doesn't do this yet it probably will soon.<br />
<br />
In many ways, what I'm creating is a 2D Lua based version of Unity3D without the GUI interface (and without the enormous price tag)<br />
<br />
This is what Unity does pretty much, taking components that do stuff and sticking them together. But it does it at a higher level than classic ECS systems do. All Unity really does is operate on the properties directly via the GUI, which looks very clever but actually isn't that difficult to do, it is like Visual Studio, you just expose properties of objects that you can then manipulate via a slider or checkbox or whatever. There are javascript and QT systems that do the same sort of thing.<br />
<br />
It is a pragmatic ECS (sometimes known as a hybrid). You say, well, there are some things the model just doesn't fit, so try to use the best of both worlds. But you try to keep, as far as possible, the data driven idea - v3 does this, when you create an entity you give it a pile of data for its components (and this could be extended to tell it what components as well) <i>but</i> you allow simplifications like having a singleton map which you can access directly.<br />
<br />
If you think in terms of say, Pacman, you can see how the various items in the game might be entities - ghosts, pacman, fruit, score, power pills and so on. The collisions you can do. You can control them , none of this is difficult.<br />
<br />
The odd thing is the map. Is it one entity; or lots of entities (are all the dots entities, if so is this workable ?). All the other entities access it all the time, do you really want to put all that through a message system ?<br />
<br />
The answer - pragmatically - is like the joystick. The map is a single entity which you can put things on, and interrogate to find out which way you can go (say). The individual dots in the maze are managed by the one entity.<br />
<br />
If you didn't do that, and had 200 of the dots or something as individual entities, you'd have to render them all individually, you'd process them in your systems, and you'd have to check collision for all of them (or write special collision systems).<br />
<br />
In other news (?) the font library does seem to be fairly stable, but we do seem to be having problems with BmGlyph.Paul Robsonhttp://www.blogger.com/profile/12278875872815047472noreply@blogger.com0tag:blogger.com,1999:blog-4083131079065852768.post-31329006411209193942014-05-29T01:46:00.000-07:002014-05-29T01:46:04.482-07:00More stuff ....Not posted much for a few days - this is what I've been up to.<br />
<br />
<br />
<ol>
<li>Bug fixing / improving / tweaking the Bitmap Font system, known as "Font Manager". Even though it doesn't. This is now perfectly useable (padding is not supported but will be added soon) and pretty stable and appears to work.</li>
<li>There's a new repository called 'Particle Classes' which are some simple classes which wrap the Particle System in Corona.</li>
<li>I've written a Component/Entity/System library (called 'Comet') which is an alternative game framework. This is still really in beta, but there is a demo of it in the github repository.</li>
</ol>
<div>
<a href="https://github.com/autismuk">https://github.com/autismuk</a></div>
Paul Robsonhttp://www.blogger.com/profile/12278875872815047472noreply@blogger.com0tag:blogger.com,1999:blog-4083131079065852768.post-37693139070727304832014-05-24T03:31:00.004-07:002014-05-24T03:31:46.285-07:00Animation Manager renamed To Coccyx. Well I got fed up with dull names. It's a little bit of the spine .....<br />
<br />
I hope to start some more experimenting with this now I'm happy the Font tool is in a stablish state.<br />
<br />
<a href="https://github.com/autismuk/coccyx">https://github.com/autismuk/coccyx</a>Paul Robsonhttp://www.blogger.com/profile/12278875872815047472noreply@blogger.com0tag:blogger.com,1999:blog-4083131079065852768.post-20930780389691890462014-05-23T13:24:00.000-07:002014-05-23T13:26:34.970-07:00Re-engineered Font ManagerThe font manager has been replaced by something which does the same thing, but it has been rebuilt largely from scratch.<br />
<br />
It offers most of the same functionality, actually slightly more. The main change is that it is now a display object in its own right rather than pretending to be one. So you can use it much as if it was a display.newText() object.<br />
<br />
The one downer is that if you turn animation on, and you rely on the system to remove it, (e.g. garbage collection in Composer) it will keep the reference to the bitmap string - it needs it to generate the animations.<br />
<br />
So in your exit events, turn animations off on any bitmap strings you use (or remove them). If it's not animated, there's no reference.<br />
<br />
<a href="https://github.com/autismuk/Font-Manager">https://github.com/autismuk/Font-Manager</a><br />
<u><br /></u>
<u>List of changes</u><br />
<br />
a) setScale() no longer functions. Adjust font size to suit, or scale overall.<br />
<br />
b) there is no FontManager object, really, though setEncoding(),setTintBrackets() and setAnimationRate() still work as there is a 'pretend' FontManager. These are now all methods of BitmapString, though all affect the global state of the fonts, so setAnimationRate() sets the rate for all the bitmap strings, not just one.<br />
<br />
c) curve and scale have been switched so they are the right way round. Previously they were 'visual' opposites.<br />
<br />
d) FontManager:Clear() does not exist. The primary reason for this is that it maintained a reference to the object. If there is sufficient demand I will add a tracking of creation on demand approach which will do the same thing.<br />
<br />
e) You cannot directly subclass BitMapString, because it is now a mixin.<br />
<br />
Your new method for a subclass should look something like<br />
<br />
local function SubclassBitmapString:new(font,fontSize)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>local newInstance = BitmapString:new(font,fontSize)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>.. do class specific initialisation.<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>.. create mixin - you can do this with a for loop as well.<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>newInstance.someFunction = SubclassBitmapString.someFunction<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>return newInstance<br />
end<br />
<br />
f) Curve is now a static class in its own right rather than being a method of FontManager.Paul Robsonhttp://www.blogger.com/profile/12278875872815047472noreply@blogger.com0tag:blogger.com,1999:blog-4083131079065852768.post-1087297079832221112014-05-15T08:08:00.003-07:002014-05-15T08:08:23.476-07:00Support for tinting added.FontManager can now tint characters - change their colours, effectively. If you have a white font, this gives you a multicolour font.<br />
<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; margin-left: 1em; text-align: right;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7LUhZsjW1iFaPZ6x8KGSs6T3vBKtLOo4z8Bj8V9eIanLuwF8SPTkunKZjI_uEX6hHlEOMEBmH4xfNeLFDUEuJSeAzCsc4p8Wr-Mb3eUBeuX-FGa6MMW_aFdZn0OzlSKokp_TglAWac4o/s1600/grab.tiff" imageanchor="1" style="clear: right; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7LUhZsjW1iFaPZ6x8KGSs6T3vBKtLOo4z8Bj8V9eIanLuwF8SPTkunKZjI_uEX6hHlEOMEBmH4xfNeLFDUEuJSeAzCsc4p8Wr-Mb3eUBeuX-FGa6MMW_aFdZn0OzlSKokp_TglAWac4o/s1600/grab.tiff" height="320" width="172" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Multiline, tinting and UTF-8<br />support added.</td></tr>
</tbody></table>
There are three ways to do it - you can set the tint for the whole string using a method, you can use modifiers to change it (e.g. the e in pulse) and you can put inline colour definitions.<br />
<br />
e.g. Hello{blue}World ! This {1,0,0.5}is {} text"<br />
<br />
The {} can be set to any pair of bracketing characters that are not alphanumeric or a decimal point.<br />
<br />
Both the library and demo have been updated for the new improved library - though the demo is still unchanged.<br />
<br />
<br />Paul Robsonhttp://www.blogger.com/profile/12278875872815047472noreply@blogger.com0tag:blogger.com,1999:blog-4083131079065852768.post-3129686765933918762014-05-14T01:06:00.001-07:002014-05-14T01:06:43.512-07:00FontManager enhancementsThanks to Richard9 on the forums who gave me some good ideas for enhancing the font library. It now supports the following<br />
<br />
<ul>
<li>Multiline text - separate with \r or \n - this only works in forward or backward orientation ; vertically orientated text doesn't start a new line.</li>
<li>Support for extended characters. Originally it just used unicode strings (e.g. 0-255) but it can now cope with UTF-8 strings up to two bytes long - if anyone wants three or four byte UTF-8 characters please let me know and I will code it. These are still, however, converted to unicode characters, all the font designers use unicode as far as I can tell !</li>
<li>Word and Line effects. So for example, pulse originally operated on individual characters, now you can easily pulse words in a line, or lines in a multiline, or do anything with it really :)</li>
</ul>
<div>
Richard also suggested tinting characters, which I will experiment with. I'm not totally convinced what the API should be yet, but it will be consistent with the multi-level design.</div>
<div>
<br /></div>
<div>
One feature of the multiline text is that in bmglyph and Glyph Designer fonts the height is often more than you think it is - there seems to be a tendency to have odd characters will really low descenders or high ascenders (?) especially if you use exotic fonts. This means the text in multiline text is further apart than looks natural. </div>
<div>
<br /></div>
<div>
This actually threw me for a while, I was sure the spacing had to be a bug. It wasn't until I looked at the .FNT file that I actually realised it was right.</div>
<div>
<br /></div>
<div>
However, to fix this there is a new method setVerticalSpacing(scalar) which is a scalar (default value 1) applied to the vertical spacing so you can squeeze or stretch this to your hearts content.</div>
<br />
<br />
You can see most of these things by running the main.lua and experimenting with it.<br />
<br />
<a href="https://github.com/autismuk/Font-Manager">https://github.com/autismuk/Font-Manager</a>Paul Robsonhttp://www.blogger.com/profile/12278875872815047472noreply@blogger.com0tag:blogger.com,1999:blog-4083131079065852768.post-51847187971224783652014-05-12T22:05:00.005-07:002014-05-12T22:05:57.212-07:00FontManager, small API changeWell, I don't like changing the API of something that's been released, but in this case it's necessary. It only affects the call to the modifiers and I suspect no-one other than me has written one yet.<br />
<br />
It was a bad call in the first place anyway - in the modifier calls, the parameters are normal parameters, but in the extensions I have in my head it would end up with ten of them :(<br />
<br />
What I have changed is the signature of the modifier, rather than providing the information as a parameter e.g.<br />
<br />
<span style="color: blue;">function pulser(modifier, cPos, elapsed, index, length)</span><br />
<br />
it passes everything except the first two as a table<br />
<br />
<span style="color: blue;">function pulser(modifier, cPos, info)</span><br />
<br />
the names are the same, so to use it in modifiers all you need to do is add "info." before elapsed, index and length so this:<br />
<br />
<span style="color: blue;">function pulser(modifier, cPos, elapsed, index, length)</span><br />
<span style="color: blue;"><span class="Apple-tab-span" style="white-space: pre;"> </span>local w = math.floor(elapsed/250) % length + 1 <span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="color: blue;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if info.index == w then <span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="color: blue;"><span class="Apple-tab-span" style="white-space: pre;"> </span>local newScale = 1 + (elapsed % 250) / 250 <span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="color: blue;"><span class="Apple-tab-span" style="white-space: pre;"> </span>modifier.xScale,modifier.yScale = newScale,newScale <span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="color: blue;"><span class="Apple-tab-span" style="white-space: pre;"> </span>end</span><br />
<span style="color: blue;">end</span><br />
<br />
becomes this:<br />
<br />
<span style="color: blue;">function pulser(modifier, cPos, <i>info</i>)</span><br />
<span style="color: blue;"><span class="Apple-tab-span" style="white-space: pre;"> </span>local w = math.floor(<i>info</i>.elapsed/250) % <i>info</i>.length + 1 <span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="color: blue;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if <i>info</i>.index == w then <span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="color: blue;"><span class="Apple-tab-span" style="white-space: pre;"> </span>local newScale = 1 + (<i>info</i>.elapsed % 250) / 250 <span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="color: blue;"><span class="Apple-tab-span" style="white-space: pre;"> </span>modifier.xScale,modifier.yScale = newScale,newScale <span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="color: blue;"><span class="Apple-tab-span" style="white-space: pre;"> </span>end</span><br />
<span style="color: blue;">end</span><br />
<br />
internally there is a bit of reengineering to support some new features, but externally this is the only change.<br />
<br />
Sorry ! It shouldn't happen again.<br />
<br />Paul Robsonhttp://www.blogger.com/profile/12278875872815047472noreply@blogger.com0tag:blogger.com,1999:blog-4083131079065852768.post-69907572155545676432014-05-11T23:26:00.002-07:002014-05-24T03:30:16.853-07:00Experimenting with Skeletal Animation ideas.<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; margin-left: 1em; text-align: right;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEga_OE_63T__crtypN7eO5ALn2ljqix4xVdie4bb2oV2kwn-h3_QsAUWPM3RuslqGeRbVN0qUyOCdtOANaf7IMkQpQwFwdPRPecO3KZkU0SM94twV1BFVn6tqtGvDrtjWrnGk7BSSiCQuc/s1600/grab.tiff" imageanchor="1" style="clear: right; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEga_OE_63T__crtypN7eO5ALn2ljqix4xVdie4bb2oV2kwn-h3_QsAUWPM3RuslqGeRbVN0qUyOCdtOANaf7IMkQpQwFwdPRPecO3KZkU0SM94twV1BFVn6tqtGvDrtjWrnGk7BSSiCQuc/s1600/grab.tiff" height="400" width="268" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Graphics by Ray Wenderlich</td></tr>
</tbody></table>
I've been experimenting with some Skeletal Animation bits and bobs. The demo shows my first go, on the right (the Elf image is from <a href="http://www.raywenderlich.com/54511/2d-skeletal-animation-with-spine-tutorial">Ray Wenderlich's Spine Tutorial</a>)<br />
<br />
Actually it's the second go but I can't draw for toffee, you wouldn't have wanted to see the original graphics....<br />
<br />
I wanted something Spine-esque but simpler, however great Spine is the Corona library doesn't work (v1 Graphics) and it's still £100.<br />
<br />
This makes some simplifications for simplicity and speed. All the graphics have to be aligned vertically top-up and their anchor points are on a vertical line through that graphic, though they can be moved up and down that line - see where the anchor point is on the bottom part of the body, it's 20% inwards.<br />
<br />
This vertical line can be moved though - if you look at the legs the vertical line is way over to the left<br />
<br />
If you look below (perhaps) you can see the arm - having it automatically in this vertical position saves a lot of math, but it <i>does</i> add limitations<br />
<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_OmukUTCVV4eLERx-PpVZEw2zHTQGJVutx4ggDxFubLc7XPQa1E0nT8k0M29gh2RkBFbOuwPQ8AfrLz_NNs8nGSAoFuwsTPP_dl7ETLPUiFnDn_CpWjkrERiEBo0kiZts8Q3Dz936DBk/s1600/arm2.png" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_OmukUTCVV4eLERx-PpVZEw2zHTQGJVutx4ggDxFubLc7XPQa1E0nT8k0M29gh2RkBFbOuwPQ8AfrLz_NNs8nGSAoFuwsTPP_dl7ETLPUiFnDn_CpWjkrERiEBo0kiZts8Q3Dz936DBk/s1600/arm2.png" height="200" width="100" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The arm - notice<br />
the vertical orientation</td></tr>
</tbody></table>
Any of those images can be placed between any two points on the skeleton (highlighted for debugging purposes as a yellow line) and then those points can be moved arbitrarily.<br />
<br />
The big advantage of the simplification in the graphics bit is that there is no complex munging of the image or the line to make it work, it is about 3 or 4 Corona API calls and a little bit of simple mathematics.<br />
<br />
I plan to experiment a bit further and then once that's done see if people have any useful suggestions or ideas.<br />
<br />
The development version is currently at <a href="https://github.com/autismuk/coccyx">https://github.com/autismuk/coccyx</a> and should normally be in a working state though of course it is in regular development.Paul Robsonhttp://www.blogger.com/profile/12278875872815047472noreply@blogger.com0tag:blogger.com,1999:blog-4083131079065852768.post-70800094300227077972014-05-10T03:09:00.000-07:002014-05-10T03:09:16.121-07:00A minor tweakWhen I was writing the demo, I realised it would be handy if I could arbitrarily remove strings as well as add them - completely remove them from the whole system.<br />
<br />
The FontManage controls the texts - it has an internal list of them. So if you remove a text from the view say, it will still physically be there, creating resources. It's really needed for transient displays, so suppose you pop up a screen over a game displaying some information and want to use a bitmapped font, then you can create bitmap strings on entry and remove them on exit.<br />
<br />
None of this should affect any prior written code in any way.Paul Robsonhttp://www.blogger.com/profile/12278875872815047472noreply@blogger.com0tag:blogger.com,1999:blog-4083131079065852768.post-86521624838095842372014-05-07T12:55:00.000-07:002014-05-07T13:21:07.956-07:00Think it can go out now.....<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; text-align: right;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB3RuZ14iuSAW1z1Ao2l9_yW9kelG71J11FsPaQ6cjfJ3HWE20VQ90UIpR4W_nje_7NSuxOYmkj4zvV4Ws225ZXh8Ny5BA1bjIQEFWLRq3nydcBx7sow8UBXUlOvWV-mFNCq3j1tBozRk/s1600/grab.tiff" imageanchor="1" style="clear: right; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB3RuZ14iuSAW1z1Ao2l9_yW9kelG71J11FsPaQ6cjfJ3HWE20VQ90UIpR4W_nje_7NSuxOYmkj4zvV4Ws225ZXh8Ny5BA1bjIQEFWLRq3nydcBx7sow8UBXUlOvWV-mFNCq3j1tBozRk/s1600/grab.tiff" height="400" width="215" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Demo Program</td></tr>
</tbody></table>
So my font manager is ready to go, in alpha (beta ?).<br />
<br />
Apart from the sort of running commentary here, there are two places to go - first is the demo program, shown on the right.<br />
<br />
<a href="https://github.com/autismuk/Font-Demo">https://github.com/autismuk/Font-Demo</a><br />
<br />
This is a quick and dirty program that displays various text effects in action, built in and coded ones. There are six (four of which are built in).<br />
<br />
<a href="https://github.com/autismuk/Font-Manager">https://github.com/autismuk/Font-Manager</a><br />
<br />
is the other, which is the current version of the library and has its own demo program.<br />
<br />
All the code is commented and the library has a HTML document file.<br />
<br />
One thing the demo doesn't show (but the demo program in the library does) is that you can transition these objects like anything else.....Paul Robsonhttp://www.blogger.com/profile/12278875872815047472noreply@blogger.com0tag:blogger.com,1999:blog-4083131079065852768.post-37096806923786219712014-05-06T07:48:00.003-07:002014-05-06T07:48:46.215-07:00Github Cloning issueI did have one problem. I was using links to keep libraries in sync, there's a copy of the transition manager in the scene manager.<br />
<br />
Git stores them as links, so if you clone SceneManager it wouldn't work, because the link goes nowhere. They are now hard copies, annoyingly.<br />
<br />
Git does do sub projects and things, but it seems a nightmare just to have one file out of a repository and have that kept up to date.Paul Robsonhttp://www.blogger.com/profile/12278875872815047472noreply@blogger.com0tag:blogger.com,1999:blog-4083131079065852768.post-43447167023110213652014-05-06T05:57:00.000-07:002014-05-06T13:10:43.127-07:00luavadoc (sic ?)The documentation of the libraries leaves a little to be desired (euphemism for 'rubbish') so I have been working on that ; I have created my own version of Javadoc for Lua - which is designed to operate in sync with my coding style. It's in github, but it's pretty useless if you don't code like me.<br />
<br />
So, I've been working on the three libraries bringing them more up to scratch, commenting main.lua and other bits that needed it and so on. So far, I have only done the transition manager <a href="https://github.com/autismuk/Transition-Manager">https://github.com/autismuk/Transition-Manager</a><br />
<br />
The doc does come up as HTML, but I haven't figure out (yet) how to set up git so that html files within git display as html rather than as the raw text.<br />
<br />
L8R: Have done the same for Scene Manager.<br />
Even L8R: Have done the same for Font Manager.Paul Robsonhttp://www.blogger.com/profile/12278875872815047472noreply@blogger.com0tag:blogger.com,1999:blog-4083131079065852768.post-9847692542588387072014-05-05T13:11:00.001-07:002014-05-05T13:11:37.874-07:00Something close to releasable .....<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; margin-left: 1em; text-align: right;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgw0YW6DmE6v7Ofj04UbEuCHNSOfPHBvku_AkgzRu04_bcrqfSh6OqYLu9Ma1gH3_LVEdCGEadknkP-YcPQkmyYAb6QKMW5GSExYM9-DcTM7FAWwrjS01q5WaQNMsXaTozxPqypKKsFXrQ/s1600/grab.tiff" imageanchor="1" style="clear: right; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgw0YW6DmE6v7Ofj04UbEuCHNSOfPHBvku_AkgzRu04_bcrqfSh6OqYLu9Ma1gH3_LVEdCGEadknkP-YcPQkmyYAb6QKMW5GSExYM9-DcTM7FAWwrjS01q5WaQNMsXaTozxPqypKKsFXrQ/s1600/grab.tiff" height="400" width="215" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Too much of this stuff will give you <br />a headache<br /></td></tr>
</tbody></table>
I must figure out a way of saving videos from the Simulator.<br />
<br />
Anyway, this is sort of releasable, a version 0.1 alpha, or as Microsoft would call it 'bug free final release'. It needs commenting more and documenting better, well at all :)<br />
<br />
Also, I think I'll make it so it reads the .fnt file in directly rather than parsing it separately. And it needs a better demo than what I have here (latest state of my testing)<br />
<br />
You can't really see it here, but the top curve is oscillating, the middle word 'pulse' is highlighting each letter in turn by blowing it up, and 'Another one' is wobbling.<br />
<br />
These are standard effects (except for pulse) - there is a fourth at the bottom right as well.<br />
<br />
All of these are being transitioned.to ; one of the pleasant surprises is that you can scale a view and its parts independently, so the 'pulse' is being zoomed at the same time as the letters are.<br />
<br />
The code to do this is not too long winded. The blue bits are usual Corona stuff ; the other four colours show the creation of four different strings. The only thing that's unusual is the pulser() function.<br />
<br />
It works out the current character by dividing the elapsed time in ms by 360 and making it in the range 1 .. length (the string length), that character (index identifies the character) then is scaled to 2,2. If you uncomment the modifier.rotation line it spends while it is highlighted which is nifty from a demo point of view but completely unreadable. It just bangs it out there x 2 at the moment but it wouldn't be hard to make it zoom.<br />
<br />
The thing I like about this is you can do all kinds of utterly insane things with it if you want, but if you just want a simple effect there's a library of them (currently only about six of them)<br />
<br />
The animate() methods tell it to animate - if you don't have this it just applies it once and leaves it, so you'd get a non moving curve on "Another demo curve" for example.<br />
<br />
<a href="https://github.com/autismuk/Font-Manager">https://github.com/autismuk/Font-Manager</a><br />
<br />
<span style="color: blue;">display.setStatusBar(display.HiddenStatusBar)</span><br />
<span style="color: blue;"><br /></span>
<span style="color: blue;">fm = require("system.fontmanager")</span><br />
<span style="color: blue;"><br /></span>
<span style="color: red;">local str = fm.BitmapString:new("retrofont",48)</span><br />
<span style="color: red;"><br /></span>
<span style="color: red;">str:moveTo(160,240):setScale(2,2):setText("Another demo curve")</span><br />
<span style="color: red;">str:setModifier("curve"):animate(4)</span><br />
<span style="color: blue;"><br /></span>
<span style="color: purple;">local str2 = fm.BitmapString:new("font2",45):setDirection(270):setText("Bye!"):setAnchor(0,0):setScale(-1,1)</span><br />
<span style="color: blue;"><br /></span>
<span style="color: #351c75;">local str3 = fm.BitmapString:new("demofont",30):moveTo(160,400):setText("Another one"):setScale(2,2)</span><br />
<span style="color: #351c75;"><br /></span>
<span style="color: #351c75;">str3:setModifier("wobble")</span><br />
<span style="color: #351c75;">str3:animate()</span><br />
<span style="color: blue;"><br /></span>
<span style="color: magenta;">function pulser(modifier, cPos, elapsed, index, length)</span><br />
<span style="color: magenta;"><span class="Apple-tab-span" style="white-space: pre;"> </span>local w = math.floor(elapsed/360) % length + 1</span><br />
<span style="color: magenta;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if index == w then </span><br />
<span style="color: magenta;"><span class="Apple-tab-span" style="white-space: pre;"> </span>modifier.xScale,modifier.yScale = 2,2</span><br />
<span style="color: magenta;"><span class="Apple-tab-span" style="white-space: pre;"> </span>-- modifier.rotation = elapsed % 360</span><br />
<span style="color: magenta;"><span class="Apple-tab-span" style="white-space: pre;"> </span>end</span><br />
<span style="color: magenta;">end</span><br />
<span style="color: magenta;"><br /></span>
<span style="color: magenta;">local str4 = fm.BitmapString:new("retrofont",80):setText("pulse"):moveTo(160,240):setModifier(pulser):animate()</span><br />
<span style="color: blue;"><br /></span>
<span style="color: blue;">local t = 8000</span><br />
<span style="color: blue;">transition.to(str:getView(),{ time = t,rotation = 0, y = 100, xScale = 0.4,yScale = 0.7,onComplete = function() --[[ FontManager:clearText()--]] end })</span><br />
<span style="color: blue;">transition.to(str2:getView(), { time = t,x = 300, y = 400, alpha = 0.4,xScale = 0.4,yScale = 0.4 })</span><br />
<span style="color: blue;">transition.to(str3:getView(), { time = t,rotation = 360 })</span><br />
<span style="color: blue;">transition.to(str4:getView(), { time = t, xScale = 2,yScale = 2})</span><br />
<br />Paul Robsonhttp://www.blogger.com/profile/12278875872815047472noreply@blogger.com0tag:blogger.com,1999:blog-4083131079065852768.post-15652640801890734992014-05-05T08:46:00.003-07:002014-05-05T08:46:50.607-07:00Getting there<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyAI39utsZ-cWo8TgHUqRV0UJXg_trBVYp6aBu21r3XEmmr0dpeudYLB6Nnx4698BmiOZho-ZgDVLNVMIknAoYdH7mVgb44FX_NuBhz6leV4HYErkWkK4tJZl40JW6fo8MfOZETW06hFE/s1600/grab.tiff" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyAI39utsZ-cWo8TgHUqRV0UJXg_trBVYp6aBu21r3XEmmr0dpeudYLB6Nnx4698BmiOZho-ZgDVLNVMIknAoYdH7mVgb44FX_NuBhz6leV4HYErkWkK4tJZl40JW6fo8MfOZETW06hFE/s1600/grab.tiff" height="215" width="400" /></a></div>
Something of a milestone.<br />
<br />
You can't see it on here, but the system is animating at the dual level now - so this text is moving up the screen (under the control of transition.to) while vertically scaling up and down following a sine curve (under the control of the Font Manager).<br />
<br />
It all seems to be working very nicely.<br />
<br />
<br />Paul Robsonhttp://www.blogger.com/profile/12278875872815047472noreply@blogger.com0tag:blogger.com,1999:blog-4083131079065852768.post-79222429981486211802014-05-04T11:45:00.004-07:002014-05-04T11:45:52.056-07:00Dumb mistake of the week :(Affects scene manager, transition manager and font manager.<br />
<br />
What's wrong with this ?<br />
<br />
<span style="color: blue;">_G.Base = _G.Base or { new = function(s,...) local o = { } setmetatable(o,s) s.__index = s s:initialise(...) return o end, initialise = function() end }</span><br />
<br />
This is my one line OOP. Like an idiot I modified it slightly but didn't test it thoroughly.<br />
<br />
Answer : the initialiser which I added, s:initialise(...) works perfectly - except it initialises the passed in prototype (s) not the newly created object (o), should be.<br />
<br />
So instead of nicely constructing a new object, it "reconstructed" the prototype.<br />
<br />
<span style="color: blue;">_G.Base = _G.Base or { new = function(s,...) local o = { } setmetatable(o,s) s.__index = s o:initialise(...) return o end, initialise = function() end }</span><br />
<div>
<span style="color: blue;"><br /></span></div>
Aarggh !<br />
<br />Paul Robsonhttp://www.blogger.com/profile/12278875872815047472noreply@blogger.com0tag:blogger.com,1999:blog-4083131079065852768.post-50003043238890593322014-05-04T03:24:00.001-07:002014-05-04T03:24:21.612-07:00Making some progress<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaQZrjVW3rh9-NPiLVqLGAL1GxR34Zru9COmXpPV2imMNNiR9wEasp3oNud9YXxArGS1_9e9TIIsYKd0WuWQK2qEMOXWByCm6Li3b7cP2QbrVwt2B1I0nAEl2n7e-BOOAx_hFAbaxGsfY/s1600/grab.tiff" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaQZrjVW3rh9-NPiLVqLGAL1GxR34Zru9COmXpPV2imMNNiR9wEasp3oNud9YXxArGS1_9e9TIIsYKd0WuWQK2qEMOXWByCm6Li3b7cP2QbrVwt2B1I0nAEl2n7e-BOOAx_hFAbaxGsfY/s1600/grab.tiff" height="229" width="320" /></a></div>
Progress is being made, the BitmapFont class (see picture) is now pretty much complete and tested. This is a picture of it with a sine function applied to the yScale.<br />
<br />
The slight slant on the images is nothing to do with the font library, incidentally, it's the way the letters were when I created the working font with bmGlyph.<br />
<br />
As usual you can see the actual demo (it spins and zooms this) in the github account <a href="https://github.com/autismuk/Font-Manager">https://github.com/autismuk/Font-Manager</a> though obviously this is still very much a work in progress.<br />
<br />
Things left to do are:<br />
<br />
<ol>
<li>The Font Manager - this tracks font usage, allows texts on a screen to be easily managed, and provides animation support.</li>
<li>The Animation Support - the code will support this at the moment (e.g. you could make the 'curve' on the letter pictures move, or zoom in and out, or spin round (you can spin the letters individually or the whole thing).</li>
<li>Some Animation Providers - these are some classes that provide some standard easily configurable animations and shapes. These aren't hard to write, you can pretty much make the letters do anything you want.</li>
<li>Some sort of demo showing it working. This isn't a real demo, it's just the current state of my build - which is why the run code is still in the library - I will try to arrange it so every commit does do something, but what it will do depends largely on what I am testing at the time.</li>
</ol>
<br />
But it's looking quite promising. If anyone's wondering, this will be a freebie as well (pretty much you can do what you want with it, don't pretend someone else wrote it :) )<br />
<br />
The guts of this demo, e.g. the bit to run it looks something like this (cut n pasted straight from the code)<br />
<span style="color: blue;"><br /></span>
<span style="color: blue;">local modClass = Base:new()</span><br />
<span style="color: blue;">function modClass:modify(m,cPos,elapsed,length) </span><br />
<span style="color: blue;"><span class="Apple-tab-span" style="white-space: pre;"> </span>local a = math.floor(cPos * 180*2) % 180</span><br />
<span style="color: blue;"><span class="Apple-tab-span" style="white-space: pre;"> </span>m.yScale = (math.sin(math.rad(a))+0.3)*3</span><br />
<span style="color: blue;">end</span><br />
<span style="color: blue;"><br /></span>
<span style="color: blue;">display.newLine(0,240,320,240):setStrokeColor( 0,1,0 )</span><br />
<span style="color: blue;">display.newLine(160,0,160,480):setStrokeColor( 0,1,0 )</span><br />
<span style="color: blue;"><br /></span>
<span style="color: blue;">local font = BitmapFont:new("demofont")</span><br />
<span style="color: blue;">local str = BitmapString:new(font,44)</span><br />
<span style="color: blue;"><br /></span>
<span style="color: blue;">str:moveTo(160,240):setAnchor(0.5,0.5):setScale(1.3,1):setDirection(0):setSpacing(0):setFontSize(64)</span><br />
<span style="color: blue;">str:setText("Another demo")</span><br />
<span style="color: blue;">str:setModifier(modClass:new())</span><br />
<span style="color: blue;"><br /></span>
<span style="color: blue;">transition.to(str:getView(),{ time = 4000,rotation = 720, xScale = 0.5, yScale = 0.5})</span><br />
<span style="color: blue;"><br /></span>
This is actually more than is needed. the two lines are just drawing the lines, and the system will support fonts-by-name directly (e.g. you can write BitmapString:new("demofont",44) . Some of the chained function calls are unnecessary (e.g. anchor is 0.5,0.5, direction is 0, spacing is 0 and you could put the 64 in the BitmapString:new() call) but just there so I can tinker with them.<br />
<br />
The modifier (the first five lines) is implemented as a class but in can be implemented as a function as well (shorter but less flexible) and there will be a bunch of standard ones so people can have special effects without writing modifier classes/functions at all. The modifier kind of says<i> "well, it's this character, this amount of time has elapsed, how do you want to muck about with this one ?"</i> - in this case it's applying a sine curve to the yScale. If you applied it to yOffset the characters would move up and down but would all be the same height. In the final version (doesn't work yet) if you added elapsed into that formula the curve will move about. The standard ones will be much easier than this, you won't have to faff around with trigonometry to get some effect or other.<br />
<br />
So you'd only need about half the code in the final version.Paul Robsonhttp://www.blogger.com/profile/12278875872815047472noreply@blogger.com0