Recent posts by NineFiveThree on Kongregate

Flag Post

Topic: Game Programming / Custom Class

http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b8ea63-7fee.html

It’s a convention to start class names with a capital letter, which makes it easy to distinguish them from variables and other things.
It’s not a good idea to add things to stage. Add them to the main time line instead.
So your code would probably look more like this:

var enemy:Enemy = new Enemy();
addChild(enemy);
 
Flag Post

Topic: Game Programming / The anormal case of the pear [FINALLY SOLVED YEEEEEEEEE!]

As I explained earlier, the point of the container is to hold the second frame of the coin animation.

Originally posted by dragon_of_celts:

The code works, okay. That doesn’t mean that it doesn’t have parts that can be excised. Maybe oldPearContainer does something, but I don’t see how: nothing, in the code on this page that I can see, ever adds anything to it, nor does it do anything but removeChildren (which, if it never has children, won’t do anything).


953 wrote, I assume regarding oldCoinContainer: ‘Your coin “animation” only has one additional frame. I picked the shortcut of putting them in a container that is cleaned every frame.’


OK, I’ll take his word for it, but I don’t see where that’s happening. Where is anything put in the container? Please point to the line(s) of code where this happens, because for the life of me, I can’t see it.


You’re right, I missed adding it to the container and instead add it to the main time line.
My bad.

The original code had the problem of switching to the second frame of a collected pear, which required the MC to persist on the display for one more frame.

Originally posted by chachon2:

#dragon_of_celts:

The oldPearContainer was a stuff created by 953 in the code that works, but I didn´t even know that it serves….

Then why didn’t you ask?

In your current code, you never remove the collected pear asset.

 
Flag Post

Topic: Game Programming / The anormal case of the pear [FINALLY SOLVED YEEEEEEEEE!]

Great to hear you could solve it.
It will now always save the state the game is in.

I’m not sure why the other way caused a problem.

 
Flag Post

Topic: Game Programming / PHP and AS2

If servers burst into flames when somebody saves password in plaintext on them, the world would be a better place.

And probably a lot warmer.

 
Flag Post

Topic: Game Programming / The anormal case of the pear [FINALLY SOLVED YEEEEEEEEE!]

Originally posted by chachon2:

The friend evan999333, in 2013 helped me with and wrote this code…WORKS!!

So in this thread you ask for a solution to a problem that was solved a year ago?!

 
Flag Post

Topic: Game Programming / The anormal case of the pear [FINALLY SOLVED YEEEEEEEEE!]

I guess the checkData method causes the issue. It calls getLocal, which loads the stored object.

I’m not sure why I also call it in the save function.
This sounds like a terrible idea because it would obviously overwrite the current status with the old one before saving that back to disk.
Getting rid of this one line that calls checkData in the save function should make this work.

Sorry for the inconvenience, I never worked with shared objects and wrote this from the top of my head.

 
Flag Post

Topic: Game Programming / The anormal case of the pear [FINALLY SOLVED YEEEEEEEEE!]

Yes, CollectedCoin would be the class that represents what ever you had on that second frame originally.

before: on class with two frames
now: two classes each for one frame.

If this confuses you, disable the code by wrapping it in a block comment and see if the rest works.
As I said this is not an ideal solution.

The problem with your original code was that from the logical standpoint, the coin was gone.
But the visual thing was to keep the coin for one more frame.

 
Flag Post

Topic: Game Programming / The anormal case of the pear [FINALLY SOLVED YEEEEEEEEE!]

Use sane variable names.

Having several redundant data structures often causes trouble. (you have 3 arrays!)
There’s no real need to do that. Have only one array with the objects and serialize that array when you save the data.

// here’s some untested code

package 
{
	import flash.display.Sprite;
	
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	
	import flash.ui.Keyboard;
	
	import flash.net.SharedObject;

	import flash.geom.Point;

	public class Pears extends Sprite
	{
		private var so:SharedObject;
		private var coins:Array = [], coinPos:Array = [new Point(200, 100), new Point(280, 100), new Point(360, 100)];
		private var oldCoinContainer:Sprite = new Sprite();

		public function Pears()
		{
			if(stage) 
				init();
			else
				addEventListener(Event.ADDED_TO_STAGE, init)
			
		}
		
		private function loadCoins():void
		{
			checkData()
			
			for (var i:uint = 0; i < 3; i++)
			{
				if(so.data.pearSaved[i])
				{
					var coin = new Coin (); // if this is all about pears, why are there coins? wtf?
					
					coin.x = coinPos[i].x;
					coin.y = coinPos[i].y;
					
					coins.push(coin);
				}
				else
				{
					coins.push(null);
				}
					
			}
		}
		
		private function saveCoins():void
		{
			checkData()
		
			for (var i:uint = 0; i < 3; i++)
			{
				so.data.pearSaved[i] = (coins[i] != null);
			}
			
			so.flush();
		}
		
		private function checkData():void
		{
			so = SharedObject.getLocal("pears");
		
			if (!so.data.pearSaved)
			{
				so.data.pearSaved = [true, true, true]; // default value, true means coin is still there;
			}
		}
		
		private function init(e:Event = null):void
		{
			addChild(oldCoinContainer);
			
			loadCoins();
			
			addEventListener(Event.ENTER_FRAME,onEnterFramer);
			stage.addEventListener(KeyboardEvent.KEY_DOWN,pabajo);
			stage.addEventListener(KeyboardEvent.KEY_UP,parriba);
		}
		
		
		private function onEnterFramer(event:Event):void
		{
			oldCoinContainer.removeChildren();		
			
			
			if (player.hitTestObject(reset))
			{
				so.clear();
			}
			
			for (var i = 0; i < coins.length; i++)
			{
				
				if (coins[i] == null)
					continue;
				
				var coin:Coin = coins[i];
				
				if (player.hitTestObject(coin))
				{
					coins[i] = null;
					removeChild(coin);
					
					var collectedCoin:CollectedCoin = new CollectedCoin(); // this is the class containing the second frame that was previosuly in "Coin" time line
					collectedCoin.x = coin.x;
					collectedCoin.y = coin.y;
					addChild(collectedCoin); 
				}
				
				if (ball.hitTestObject(save))
				{
					saveCoins();
				}
			}
		}
	}
}

Your coin “animation” only has one additional frame. I picked the shortcut of putting them in a container that is cleaned every frame.
If you want a better solution, the coins would dispatch an Event at the end of their animation.
Upon that event remove the object from display in the Main class.

 
Flag Post

Topic: Game Programming / Image stack

Originally posted by AshAbeAdd:

How can I make sure that a sprite is behind a different sprite/textobject.

You either add the one that’s behind first, or:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObjectContainer.html#addChildAt%28%29

 
Flag Post

Topic: Game Programming / Image stack

Well, as I said, you should not add it to the stage. Try to understand that the stage property is not “the stage” you have in Flash where you can draw stuff. These are two different things. Add it, just don’t add it to stage.

I didn’t understand anything else you tried to say.
Could you please try to provide a description that’s a little more clear?
Just describe in plain english what you want to do without trying to use programming terminology.

If it’s easier, post a screen shot or sketch.

 
Flag Post

Topic: Game Programming / Image stack

First of all, adding things to the stage directly is not recommended, just get rid of “stage.” so it’s attached to the main time line.

Secondly, you should always be able to click on a textbox, the question is what you expect to happen then. Do you want to make the text editable?
Post your entire code and further explanation.

 
Flag Post

Topic: Game Programming / as3 what is the most efficient way to use enterframes

Originally posted by player_03:
Originally posted by NineFiveThree:

But sure enough your logic goes haywire if that “deal one damage to the player every frame” object persist in memory and keeps on doing its thing.

This won’t happen with enter frame events (assuming you remove the object from the stage), but it could certainly happen with timers. Yet another reason to use ENTER_FRAME.

In this example, the Event keeps firing (at least for me).

package 
{
    import flash.display.Sprite;
    
    import flash.events.Event;
    
    public class FlashTest extends Sprite 
    {
        private var _count:uint = 0;
        
        public function FlashTest() 
        {
            var s:Sprite = new Sprite();
            
            s.addEventListener(Event.ENTER_FRAME, onEnterFrame, false, 0, true);  
            
            s = null;          
            
        }
        
        private function onEnterFrame (e:Event):void
        {
            trace(_count++);
        }

    }
}

The variable is local, but I set it to null anyway.

 
Flag Post

Topic: Game Programming / as3 what is the most efficient way to use enterframes

Originally posted by theruss16:

always remember to remove them with removeEventListener once you don’t need them (you can also use weak references by passing true as the last parameter (addEventListener(event, listener, false, 0, true);) and then the event listener should be garbage collected along with the object, but I have read that they aren’t very reliable so I’d rather be safe and remove the listeners with removeEventListener)
//

Well, there’s no such thing as an event listener being collected.
This is mixing two things up in a way that it sounds confusing.
Let’s have a look:

Adding a listener to an EventDispatcher means nothing else but adding a reference to a function to that dispatcher.
“Hey you, when that event happens, call that function”

Then you add the garbage collector to the whole thing.
This is a process that wipes all objects that are not referenced and aren’t referencing anything from memory. (that’s super simplified)
“If you don’t have any connections to it and it has no connections to you, consider it dead”

With that in mind, we can take a look at that first statement again:
Adding a listener to a dispatcher means adding a reference (to a function).
That’s why you should remove listeners from unwanted objects, because only objects without references can be collected.

So far so good.

But how is adding a weak listener different?
After all, this would add a weak reference that’s not counted as a “strong” reference.
Therefore, the object should still be collected even though this reference still exists, right?

Yes. That’s all correct.
But guess what?
Nothing guaranties it actually happens. Just because some object could possibly be collected doesn’t mean the collector actually runs.
Collecting garbage is serious work and you don’t want to run after every small piece of junk.
That’s why the garbage collector runs at some arbitrary point that you cannot determine.
After all that’s the beauty of managed memory. (pun intended)

So if you null the last reference to an object with a weak referenced ENTER_FRAME listener added to it, you have no guarantee when this function you added as a listener will be called for the last time.
Maybe the flash runtime that executes your application can never be bothered to collect that one object, because it wouldn’t make much sense from a memory management / performance point of view.

But sure enough your logic goes haywire if that “deal one damage to the player every frame” object persist in memory and keeps on doing its thing.

 
Flag Post

Topic: Game Programming / Array elements

Originally posted by AshAbeAdd:

Preferably in the prototypes?

It’s not recommended to work with prototypes.

I’m not aware of a way to truly limit the size of an array in C.
Sure enough you set an amount of elements, but nothing prevents you from crossing that line. You’d have to write a function that does this.

In As3, Arrays do not have a set size and grow as you add or remove elements.
Vectors can be set to have a fixed size.

I’d just write a function that keeps the index within your desired boundaries.

 
Flag Post

Topic: Game Programming / String conversion

Post your code. You are probably doing something else wrong. Referencing the array in a local variable for example.

 
Flag Post

Topic: Game Programming / Revolving Circles'

Originally posted by zoorroo4:
I wish i had some good idea for how to use this in a game.

In terms of games, gravitee wars comes to my mind.
I would not force it into a game if you cannot think of any. It’s really nice as an interactive piece.

If it’s interactive, you can play with it. If you can play with it, it’s some kind of game, right? ;)

 
Flag Post

Topic: Game Programming / Revolving Circles'

Congratulations on achieving your goal.

As far as feedback goes: this is just a rotation nested into itself, nothing too new or interesting.
But sure enough, that doesn’t mean it’s not interesting. I’m sure people will find a tutorial helpful if it’s done well.

If you are afraid that the simple illustration of geometric ideas scares people of, you can extend the whole thing.
This could end up being a little solar system for example, with trails of the planets, etc.

 
Flag Post

Topic: Game Programming / AS3: what containers are there

Vector is the only data structure that let’s you specify the stored type.
An Array is – as you found out – a list of anything.

If you want to associate String keys to any value, a generic object will do.
To use any kind of key similar to a Hashmap, Dictionary is the way to go.

There’s nothing as sophisticated as the STL/Collections built into the language.

 
Flag Post

Topic: Game Programming / Wait for URLRequest to Finish

As javascript, C#, java, Qt and probably many more also call it an “event”, I don’t think it’s that uncommcon for Actionscript to do the same.

 
Flag Post

Topic: Game Programming / Learning Flash

Eclipse and intellij IDEA run fine on linux (they are java based)

 
Flag Post

Topic: Game Programming / Lag test

Originally posted by PanisRahl:

interesting, but would i still be able to interact with each ‘blitted’ tile as an independent object? In other words, can my copied tiles still be independently interacted with, each holding there own unique variables extended from a base tile?

You can still create objects for each tile.
You just don’t want to have an individual DisplayObject for each one.

 
Flag Post

Topic: Game Programming / as3: Changing rotationpoint

What is the desired behaviour?

If you don’t want the object to move, why do you change its position then?

 
Flag Post

Topic: Game Programming / Lag test

Again, using an object pool is not going to get rid of every lag.

Originally posted by PanisRahl:

I know having around 1000 objects held in an array is not very good. But i assume its better than constantly having to use the New function 192 times then the delete function 192 times each time u switch areas

Assumptions are a good start, they stem from experience and often lead in a right direction.
But optimisation without measurement is pointless.

Use a profiler to check what the bottleneck actually is instead of applying random optimization techniques you heard are good to have.

When it comes to display objects, MovieClips could be considered worst practice.
They bring along quite a bit of overhead because of the time line they have.
Time lines are great for animation, but guess what? You don’t have any animation in your tiles.

Blitting refers to displaying a single BitmapData object that you draw() or better copyPixel() your content into.
Take a look at this article explaining it

Here’s another article with some tips on optimization

“somebody told you it’s faster that way” should not be the reason that you apply a certain technique, but the fact that you significantly improve performance.

 
Flag Post

Topic: Game Programming / Lag test

You mention that you use an object pool as if that would be the general solution to get rid of lag.
It’s not. It can help reduce lag when a lot of objects are created.

I’m not sure what you mean by “holding 192 of each tile type”.
It sounds like you are creating that many displayobjects.
If that’s the case, it could be your bottleneck.

Use some profiler to check what is causing the problems.
If you have nothing else going on it’s likely that the many display objects are causing issues.
Blitting can help with that.

 
Flag Post

Topic: Game Programming / Getting back into Flash

The language did not change much.

I know the book is old, but it explains the whole thing very thoroughly.
It introduces the object oriented aspects first and then applies them to the existing API of As3.
Of course new versions of the Flash player extended this API, but the knowledge still applies.

If the reason you asked for books is that you have problems with the low quality of free online resources I have to agree that some are quite bad.
This series of articles is very good, check it out

If you go through the Adobe tutorial and the other one I linked to above, you should have some basic understanding of how the language works.
If you need/want the book is up to you. If books are your thing, download a sample chapter and if you want it, get a used one. I just checked ebay and you can find them for around 6$

You will not find a tutorial for everything. Get started with small projects.
You can always come to forums like this and ask for help. Great people here.

Also note that there are other books out there that teach As3 by applying it to game development for example.
I have no such book so I cannot recommend any, but a lot of people seemed to like them.
You did not mention any application that you want to create.
Have fun.