Recent posts by a3lex33 on Kongregate

Flag Post

Topic: Game Programming / AS3 array display/sort problem.

EndlessSporadic described most of the good way to do that process for you, just don’t forget to remove the old images. It is also easier to keep two arrays – first holds all pictures data, second holds images on screen(so you can easily remove them later in some kind of update/refreshDisplay function). Also, try sortOn function for arrays, it allows you to sort by property of object.

 
Flag Post

Topic: Game Programming / hitTestPoint bug[as3]

Sorry, found the bug by myself and it was not in this 2 functions. If anyone ever finds this thread and get the same bug, the problem was in accidentally assigning speed to objects already lying on ground. While the Image was not moving, object would negate speed on one frame and assign minimal possible speed(acceleration) on another. It would have no effect with static Image, but with Image changing positions, things started clipping through small platforms rather badly.

 
Flag Post

Topic: Game Programming / hitTestPoint bug[as3]

If i remember correctly, i have to use localtoglobal even if ground objects are in containers. And it also works while Image is not moving, does not matter if it was not moved before or not. The problem happens while the Image is moving and only during movement.

 
Flag Post

Topic: Game Programming / hitTestPoint bug[as3]

Hello everyone. Can you help me to find out the reason of the strange bug with platformer physics?

There is a platformer game and i try to emulate falling physics by doing this. First, Main method creates an empty sprite and stores in in “Global” class public static member called “Image”. Second, everything else – the ground and falling object – is added to it in specific positions. Now, on each frame gravity is added to falling speed of an object. A special function(code below) checks if object will collide with ground on the next frame.

public static function botSensor(obj, speed):int
		{
			var i:int;
			var p:Point = new Point(0, 0);
			for (i = 0; i < speed; ++i)
			{
				var tp:Point = obj.localToGlobal(p);
				if (hitTestLevel(tp.x,tp.y + i) != null)
				{
					return i;
				}
			}
			return -1;
		}

Where hitTestLevel simply iterates through platforms(stored in ground array) with hitTestPoint function:

public static function hitTestLevel(px, py)
		{
var i:int, l:int;
			l = ground.length;
			for (i = 0; i < l; ++i)
			{
				if (ground[i].hitTestPoint(px, py, true))
				{
					return ground[i];
				}
			}
			return null;
		}

Now, this 2 functions work good when the Image does not move. However, when the Image starts moving(changing y position each frame)(for example, to emulate camera), objects start clipping through ground. “botSensor” function starts returning values in 3-7 range, meaning that object can go down 3-7 pixels before it stops.

Can you help me understand if why does that(getting different hitTestPoint results on Image movement) happen? If it helps, ground array objects are stored on Image the following way:
Image→SomeContainer→MoreContainers→ground object, ground array is just a shortcut.

 
Flag Post

Topic: Game Programming / My Game Frame Lags

What are you doing later on with this? Do the things move? Do you recalculate if what goes in background and what goes in foreground? With how much tiles do you encounter the slowdowns?

 
Flag Post

Topic: Game Programming / Totally lost with Bitmaps and BitmapData

Originally posted by Aesica:

Those calculations will be made no matter what you use, since they kind of have to. Standard displayobjects don’t get to rotate for free, but it’s easy to forget that since rotating is so easy to do when working with them. If you’ve ever tried load testing, you’d see that nonrotated displayobjects don’t put as much drag on the flash player as rotating ones do. With blitting, even if you force the calculations every frame, what you end up with is still going to be faster than easy-rotating through standard displayobjects.

I’m working on this right now (crappy graphics are subject to change and are only for testing purposes) and it is 100% blit-based. There are 3 things going on in this image that attempt to optimize rotations in 3 different ways. The shuriken-things use animation frames to fake a rotating appearance, meaning the rotated images have already been drawn out and are part of the sprite sheet. The skulls are rotated only once, when initially fired, and the rotated image is then cached into a bitmapdata that is then rendered through copypixels. Finally, the blue beam segments rotate every frame (creating the arching appearance) through draw, which of course puts the heaviest load on the engine.

Once you get the hard part of figuring it all out and make a good library, you never have to think about the bad stuff again—only the good. :)

Edit: I don’t mean to seem like I’m twisting your arm, by the way. Just that, as someone who used to think displayobjects were fine, I’ve since come to realize that blitting is so much better once you take the time to learn it. I won’t even touch displayobjects for game sprites/particles anymore. Use whatever works for your project (of course) but keep an open mind at the same time.

Can you compare if by how much draw is slower than everything else you have used? For example, if i would want to draw a ray(there is a predrawn ray segment MC, stored in any form needed) from any point A to point B, what would be better – using single draw call to rotate and scale the segment or predefining 180 rotations of ray before and placing multiple segments through copyPixels? For the heaviest load, it would be awesome if 200-2000 of those could be placed each frame.

 
Flag Post

Topic: Game Programming / AS3 help - removeChild of a different class

I use ‘Global’ class for this kind of tasks. This approach is hated by this forum and is ‘bad’ and stuff, but still:

package  
{
	import flash.events.EventDispatcher;
	
	public class Global extends EventDispatcher
	{
		public static var Toolbar;
	}
}

Simply save the code above as .as file in your project source files. Next, you can do:

...
tBar = MakeToolbar(); //you probably have something like this already or any other method in Main to create your toolbar
Global.Toolbar = tBar;
...
Global.Toolbar.visible = false; //you can do this from ANY class. Assuming Toolbar is a DisplayObject

And this will work. If it does not, import Global.

 
Flag Post

Topic: Game Programming / Best way to store ingame level?

Hello everyone. Can you tell me from your experience, what is the best way to store a game level in memory, especially in RTS/platform game, where game levels are extremely important and might take a lot of space. Right now i know of 3 ways, all of them i don’t like very much:

1)Storing level in 2d array somewhere
2)[as3]Storing level in movieclip, other movieclips inside marking important things
3)Creating your own level editor with function, which converts level in text string. Copypasting string in your game and writing a function to decode the string.

Is there a better way to store levels?

 
Flag Post

Topic: Game Programming / Quick question about time[as3]

Hello everyone. Lets imagine that i want some feature in my game, which will depend on real time. For example, making something happen in 1 hour of real time. To do this, i can use user system time. Now, the question: is it possible to somehow prevent user from ‘cheating’ – changing their system time in order to fool the system(in this example, adding 1 hour to system time)? Is it possible to do so without using date from a internet/server? If not, is it possible to do so without using my own server/host and get date from somewhere for free? Language used: as3.

 
Flag Post

Topic: WarLight: Multi-Player / Cheaters

Originally posted by raa275:

Creating multiple accounts to curry things in your own favor is not cheating because everyone does it. You are simply giving yourself an equal edge against other players. This is worst in Rise of Rome and Africa maps because the stakes are so huge.

Seriously? If everyone do it, everyone are cheating. And so do you, guessing by this post.

I am rather disappointed in some people on this thread. Instead of playing fairly and not using multiple accounts, they are behaving aggressively and protecting their holy right to cheat. GG.

 
Flag Post

Topic: Game Programming / This piece of code causes memory leak. Unsure, why.[as3]

Draco, thanks for answer, i was worried about using lot of dots too, will remove “Global.”. About memory leak. I have managed to trace down (new) source of memory leak. It happens after change of TLF textfield text. I have no idea, if how does that happen, but i saw some bug reports about this. It was also in the function above, i just thought that it was not important piece of code to post. Well, blitting made everything faster anyway, that helped too.

Anyone heard of same problem and solution, by any chance?

 
Flag Post

Topic: Game Programming / This piece of code causes memory leak. Unsure, why.[as3]

Originally posted by NineFiveThree:

I suggest you drop the bad habit of using a Global class.

A HUD is only a display. If the fuel gauge in your car fails and displays zero even though you still have fuel, can you still drive the car?
Why is your HUD involved in creating the bullets?

Is there a particular reason why you set your local variables to null?

Why is it a bad habit? It is rather useful to have Global and Data classes, defined like this, to keep most important/most used functions and data in special place.
HUD is not creating bullets. Its only creating images of bullets for users to see on user interface, instead of standard “ammo/clips”.
Yes, there is a reason – me going crazy because of memory leak and discarding all possible sources. I never set variables to null like this usually.

Quick question – is there a way to notice the FPS drop faster? By switching to bitmaps/blitting i lowered the FPS drop speed – FPS went from 30 to 15-17 in 5 minutes before, now its 15 minutes, so there is still something. Is there a way to somehow limit your RAM amount or something for flash player?

 
Flag Post

Topic: Game Programming / This piece of code causes memory leak. Unsure, why.[as3]

Ok, i will try that now. I thought that this could be avoided because there were not so much elements on display(10-20), and the condition to recreate those is rarely true.

 
Flag Post

Topic: Game Programming / This piece of code causes memory leak. Unsure, why.[as3]

The only as3 shootorial i found was the first one. Are you suggesting to do the same thing in document class? Well, i will try, but it would still be great to know if what went wrong on this one.

Edit: moving contents of function inside another function, this time in document class, private, and calling that function instead of old one did not help.

 
Flag Post

Topic: Game Programming / This piece of code causes memory leak. Unsure, why.[as3]

Hello everyone. Can anyone help me with a little problem? I have detected a memory leak, but i am not sure if why does it happen. Below is some code in as3.


//package, imports

public class Global extends EventDispatcher
{

public static function updateHud():void
{
	//some code, in which t is defined
	var curw = Global.curturner.curweapon; //An object
	if (Global.HUD.curam!=curw.ammoleft||Global.HUD.curamm!=curw.maxammo)
	{
		Global.HUD.curam = curw.ammoleft;
		Global.HUD.curamm = curw.maxammo;
		for (i = 0; i < Global.HUD.ammoh.length; ++i)
		{
			if (Global.HUD.ammoh[i].parent!=null)
				t.removeChild(Global.HUD.ammoh[i]);
			Global.HUD.ammoh[i] = null;
		}
		Global.HUD.ammoh = [];
		for (i = 0; i < Global.HUD.curamm; ++i)
		{
			var a;
			if (i < Global.HUD.curam)
			{
				a = new pbullet();
			}
			else
			{
				a = new pempty();
			}
			t.addChild(a);
			Global.HUD.ammoh.push(a);
			a = null;
		}
	}
	curw = null;
}

}

The function above is called on each frame. It have some more code, but this exact piece of code is causing memory leak(memory leak does not happen if that piece of code is commented out). If i understand it correctly, as3 garbage collector collect an object when there are no more active references to this object. This is why i am turning everything in null at end of block. But that does not help, game memory increases and FPS drop. Also, objects are getting removed from “t” correctly, tested with numChildren.

Is there a way to fix it? Is it somehow connected with function being static and vars inside function? If yes, what is the safe way to do the same thing?

 
Flag Post

Topic: Game Programming / Animating via code plus other issues

You will probably want to split character on multiple parts, at least hands and body. This way you can control both. It will look somehow like:


if (running)
{
 body.gotoAndPlay(runninganimationframe);
 if (attacking)
  hands.gotoAndPlay(handsattackingframe);
 else
  hands.gotoAndPlay(handsrunningframe);
}

Or you can do it the hard way and make animations for each kind of movement your character can do: standing-attacking, walking-attacking, standing-not attacking, walking-not attacking. But the amount of all possible combinations will greatly increase that way, you will have to draw each of them.

 
Flag Post

Topic: General Gaming / The "What was that game called?" Thread

Originally posted by gabenn12301:

I searching for a game it was a steampunk like game, it was a turn based game where u could make a 3 person party, the characters had many "role"s like berserker or archer and medic and these all was availeable for all character if u wanted u could easilly switch beetwen them, there was more roles but i cant remember exatly, in the main story u must explore a big tower. In the village was a lot of craftable armors and weapons, in the village u could build buildings like woodcutter store and etc, if anyone know this game name pls tell me. The first boss used flame tipe attack.

The Grinns Tale probably. Not alive anymore.

 
Flag Post

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

Did anyone create a game which uses frame enter events in the way Aesica do? I wonder if how big is the performance difference. Also, does switch from pseudo parallel(multiple enter frame events) to linear(loop) affect anything?

 
Flag Post

Topic: Game Programming / Feedback to my new game (critics are very welcome)

Few issues:

Programming:

Strange controls
Cursor only distracts you. Also, it should change position each frame and not only when you are moving the mouse.
The game is slow

Design:

It is unclear if what hurts you and what does not.
A lot of jumps require to be perfect, else you fall to your doom.
It is unclear if what is your goal and where shall you go.
Secrets require too much pixelperfect jumping and are not rewarding.

 
Flag Post

Topic: Game Programming / Convert Shape or Polygon Boundaries To X and Y Coordinates

I don’t know much about differences between quickbox2d and box2dflash, but latter allows you to add multiple fixtures to the body. Create a rectangle first, add it to the body, create circle and add it too. It shall solve your first problem which you have described.

 
Flag Post

Topic: Game of Thrones Ascent: Recruitment (Expand Your House) / Boss Quest Links

http://www.kongregate.com/games/DisruptorBeam/game-of-thrones-ascent?kv_origin=/play/join_quest/280409175

 
Flag Post

Topic: Game of Thrones Ascent: Recruitment (Expand Your House) / Boss Quest Links

http://www.kongregate.com/games/DisruptorBeam/game-of-thrones-ascent?kv_origin=/play/join_quest/280409175

 
Flag Post

Topic: Game Programming / Is our game too hard?

Took me a while to understand if how game works without reading your instructions on this forum. You don’t have enough time to read the instructions when you show them in game. It looks like you have to somehow jump for the gaps in the middle, while in reality you only have to find other way/break walls. It is really hard or impossible to do 3 small gaps ducking chain(red walls), since you can not see if where to move, the possible solution would be making walls transparent.

 
Flag Post

Topic: Game Programming / Is self-promotion of games acceptable in this forum?

Do any of you have a problem with it? Is not it always fun to see if what did other create? I can rarely help with advice and try to solve my programming problems on my own, so i post here rarely. But i visit this forum daily – the community here is good and people always discuss something interesting. Self promoting posts only add to this, so why do you want to ban those kind of posts?

 
Flag Post

Topic: Game Programming / Isometric objects depth[as3]

Sorry, it is hard for me to describe the problem in English. Shake_N_Baker gave a link to the post which illustrates the problem, but i can provide my own pictures if it will help. I am not using any of isometric libraries(the best i found was as3isolib, but it was hard to understand and work with), so i am doing everything manually.

NineFiveThree, i meant that after trying to find solution in google, i found some pages which told that there is no algorithm to calculate object depth for object of any size. Tell me, if i am wrong and there is one.

Shake_N_Baker, can you give me some ideas on how to break objects on 1×1 sized ones? I am not sure if how to slice the texture of object for that.