BobJanova
857 posts
|
Topic: Game Programming /
Using music in my game
Originally posted by Drakim:
If you are planning to stream it, you need to find some places to host it yourself though.
While true, they only need to be statically available HTTP downloads, and they will get cached by users’ browsers, so you should be able to do that on any cheap or even free hosting package. And if they’re not too enormous they can even go on Kong as extra files.
|
|
|
BobJanova
857 posts
|
Topic: Game Programming /
AS3 Get and Set Methods
I use them a lot in any language that supports them (see the other thread about that), including AS3. They allow you to perform method actions, e.g. validation or resource cleanup of a previous value, while retaining the syntactic simplicity of a field access.
|
|
|
BobJanova
857 posts
|
Topic: Game Programming /
Using music in my game
Alternatively you can pack some music and stream the rest after the static content loads.
|
|
|
BobJanova
857 posts
|
Topic: Game Programming /
getters and setters in other languages
Delphi also has getter/setter functions that look syntactically like fields. In fact I believe that’s where the idea came from that the C# crew implemented (Microsoft poached several people from Borland when they developed .Net 1.0), and I suspect that AS3 is copying C#, so Delphi is probably the mainstream daddy of this syntax.
|
|
|
BobJanova
857 posts
|
Topic: Game Programming /
rotation on a slope
Put the function into a base class of Locomotive and Carriage or whatever you call the classes that are linked to the movie clips, and call that from the enterFrame handler of the world.
|
|
|
BobJanova
857 posts
|
Topic: Game Programming /
Deeper Topic (part 3): Events to the rescue!
Originally posted by RTL_Shadow:
Instead of using a PositionComponent I decided to make my Entity class extend DisplayObjectContainer, this way I can add Sprites and such from my assets file.
Don’t do that! Entities should be capable of existing completely separately to whatever mechanism you’re using to display your world. Have a View property on entities instead which refers to a view object (which in a 2D environment could well be a DisplayObject).
|
|
|
BobJanova
857 posts
|
Topic: Game Programming /
Logical OR help
XOR and not-equal are equivalent operations on booleans. You always have to evaluate both sides for an XOR.
And books have mistakes; learn to believe it! I learnt that at primary school with my maths textbook, and that was probably a more valuable lesson than any of the basic arithmetic it had in it.
|
|
|
BobJanova
857 posts
|
Topic: Game Programming /
Logical OR help
AS3 doesn’t have a logical XOR operator
Yes it does: !=
|
|
|
BobJanova
857 posts
|
Topic: Game Programming /
Deeper Topic (part 4): Examples and advanced techniques
There’s no reason you shouldn’t combine this with an entities-can-contain-entities model, and have a main entity which has weapons entities (and those weapons can have components), as well as weapon management components that issue ‘fire_primary’ or ‘fire_secondary’ type messages.
I’d actually do away with getComponent entirely and allow adding of multiple components of the same type. I don’t see the point of forcing yourself into manager classes when you really just want to DamageReduction components of different types. If there’s a direct link between components then you should have them all available at instantiation time, and you can write the dependencies directly into code.
I also wouldn’t use priority for entity sorting, either for activity purposes (i.e. only running entity actions in the visible world or something like that) or for drawing. Have a separate entity storage mechanism in your game world to depth sort.
|
|
|
BobJanova
857 posts
|
Topic: Game Programming /
How Do You Pronounce...
char, like burning
var as it looks (rhyme with car)
Jason
Ekma-script
Hacks
U-Int
Swuff (not really a ‘u’, it’s the ‘schwa’ unvoiced vowel)
Es doubleyou see (yeah, inconsistent I know)
I don’t have reason to pronounce FLA because I don’t use Flash
Instantiate is a real word so you should pronounce it correctly :-)
I’ve never used vi, but probably like the name Vi (like the first syllable in viable)
Like auk
Oh-ex
Do you require any more insights into my character?
|
|
|
BobJanova
857 posts
|
Topic: Game Programming /
Deeper Topic (part 2): Composition over inheritance
If you want me to host these three posts as an article for you (with attribution/linkbacks/whatever obviously) then I’d be happy to, if you don’t have a website or blog of your own. If you do, or feel like starting one, I encourage you to post them there. I agree with some other people that they deserve better than to be buried in this forum.
Also, note that a component based architecture can also separate view from the object, so you can have a game that is GPU accelerated with a blitting fallback if your target does not support it.
Whether you’re using a component based architecture or not, you should do this. I experimented with this approach for the ‘Outside the Box’ GiTD challenge, and while I didn’t complete it, the MVC pattern for game entities is really helpful.
|
|
|
BobJanova
857 posts
|
Topic: Game Programming /
Deeper Topic (part 1): A criticism of OOP in game development
The answer to this problem in short form is ‘compose, don’t inherit’ (though in fact you generally want to do both, inheriting particular sets of composed behaviour within a hierarchy of related entities). Unfortunately we don’t have any good tools in AS3 to help with composition.
I’ve taken a half way position of putting ‘hooks’ in my top level GameObject or Entity class which allows particular entities to adjust the behaviour on particular events by providing a list of hook objects … essentially behaviour modifiers that can be composed. For example a shield behaviour would modify the damage received when the entity was about to take damage from an attack, or a regen effect would hook into the update process. I also allow entities to spawn other entities, which accounts for weapon firing (spawn a projectile), explosions (spawn an explosion entity which immediately expires and does damage within its collision space) and spawning things on death.
|
|
|
BobJanova
857 posts
|
Topic: Game Programming /
[as3]Making calculations step by step
Instance state is less bad but still bad if there’s no reason for it. In such a simple situation it won’t cause you concrete problems, but it’s a bad habit to get into; for example if you move into multithreaded environments this code could break in weird ways if it was run twice in parallel, particularly if several methods use the same instance variables.
|
|
|
BobJanova
857 posts
|
Topic: Game Programming /
[as3]Making calculations step by step
A path two or three cells long should be very quick to calculate. Are you sure it’s this code that’s slowing you down?
You should have your GetNei function return the neighbours, not put them in a global variable, and you should localise opened and closed and pass them to your isOpened/isClosed functions. Global state is bad and can get you into trouble. That won’t help your speed issue but it’s a general point.
|
|
|
BobJanova
857 posts
|
Topic: Game Programming /
[as3]Making calculations step by step
A* on a large network can be noticeably slow … to lag your game it only needs to take 30ms, after all, so that’s 2ms per object if you try to do 15 all in the same frame.
Try to break your network and path down into sections so you don’t have to pathfind on the full network every time, particularly if it’s a recalculation due to a broken path, and see if you can have different objects calculate their paths in different frames.
You can spread calculation over several frames (for example here’s how I do that), but if you’re trying to calculate too much, that won’t actually help you. If you’re trying to do a second’s worth of pathfinding once every 15 seconds, though, it will.
|
|
|
BobJanova
857 posts
|
Topic: Game Programming /
GiTD [#32] Entries and Discussion
Looks like the return of the prize has upped the ante for the professionalism in these entries! Some really cool stuff there!
|
|
|
BobJanova
857 posts
|
Topic: Game Programming /
actionscript multiplayer
TCP is not ‘slow’ unless your network is congested or you want something very time critical. The overhead from using TCP is a tiny fraction of the ping time if you are a long way apart geographically.
I don’t believe it’s possible to do game hosting in Flash (in browser) because of security restrictions on what browser plugins can do, even if the user has the relevant firewall and router permissions set. The best you’re likely to be able to do is hosting through a central server, similar to (or using) a particular room type on Player.IO.
|
|
|
BobJanova
857 posts
|
Topic: Game Programming /
Classes and keyboard
Timers will trigger in a frame, you just don’t know which one if the frame rate starts to drop. It also gets stuck in a lag loop much more easily: if you have a 30ms timer but your frame actually takes 35ms to render, in not very long (6 frames) you’ll get two timer invocations in the same frame, that frame will take 70ms to render, so then you’ll get 3, and very quickly the game locks solid.
To avoid the problem SumGato mentions (‘if you have to change the frame rate at some point you have to rewrite almost everything’), I use enter-frame events, but to determine what actually gets done in a frame, I time how long it is between frames. This gives relatively graceful degradation (I use stepwise physics so if lag gets too bad it stops being a reasonable approximation, but if a frame is 40ms not 33 it doesn’t cause a serious problem) and makes it easy to change the frame rate or ‘slice’ frames into multiple simulation steps.
|
|
|
BobJanova
857 posts
|
Topic: Game Programming /
Classes and keyboard
Indeed, referring to the stage in a constructor is generally a bad idea and I’d expect that to throw a null reference exception in fact.
|
|
|
BobJanova
857 posts
|
Topic: Game Programming /
Payment
I think it’s net earnings. Also make sure you check whether you are eligible for a tax reduction through that form; most western countries have a tax treaty with the US so you won’t have to pay that 30%, only the income tax in your own country.
|
|
|
BobJanova
857 posts
|
Topic: Game Programming /
[AS3] TextField deformation [Solved!]
I don’t think you understand what ‘arbitrary’ means, imp2.
I’m pretty sure you can’t mess with text in this way. You’d have to either render it to a bitmap and then transform that, or render the text as vectors under a transformation … and since Flash doesn’t support non-affine transform matrices you’d have to do that yourself too.
|
|
|
BobJanova
857 posts
|
Topic: Game Programming /
Type Coercion failure when pulling class from byteArray
You should never need to save a display object. They should be used for the View, if we switch to MVC parlance for a moment, and you should only need to save the Model.
|
|
|
BobJanova
857 posts
|
Topic: Game Programming /
[AS3] Finding adjacents and selecting borders.
Firstly you have a horrible mix of logic and UI here. Separate your idea of a map and the view of it. You probably want a GridElement class
class GridElement {
var type:int, countyName:String;
var view:GridElementView;
...
}
… and a view class which derives from Sprite in some way and knows about borders:
class GridElementView extends Sprite {
function set rightBorder(value:Boolean) : void {
... // switch the visibility of a child or something
}
function set bottomBorder(value:Boolean) : void { ... }
}
You probably only need right and bottom borders, because that is the same as the left and top of the next tile.
Now for the logic itself:
function setBorders(grid:Vector.<Vector.<GridElement>>){
for(var x:int = 0; x < grid.length - 1; x++) for(var y:int = 0; y < grid[x].length - 1; y++) {
grid[x][y].view.rightBorder = grid[x][y].countyName != grid[x+1][y].countyName;
grid[x][y].view.topBorder = grid[x][y].countyName != grid[x][y+1].countyName;
}
}
|
|
|
BobJanova
857 posts
|
Topic: Game Programming /
Help with saving a class to a SharedObject
I don’t think you need a singleton here, no.
The byte array trick works as long as (i) you have only simple types in your data object (no object references and really definitely no references to the display list), and (ii) Adobe don’t change their data format.
Personally I’m a bit cagey about (ii) so I write everything into my SOs as arrays or keyed objects (i.e. Object, not a specific class).
|
|
|
BobJanova
857 posts
|
Topic: Game Programming /
Where is the API?
I have a KongregateAPI.swc which I grabbed a long time ago, probably in AS2. This link is to what gets loaded as the shadow services; you can probably add that to your library (right click/save target).
|