Draco18s
5875 posts
|
Topic: Game Programming /
Odd issue with two identical, simultaneously attached, objects
Originally posted by UnknownGuardian:
Can I see where you remove bullets? I used to get shifted bullets like that when I forgot to decrement the loop when looping up after splice() or arr[index] = arr[arr.length-1]; arr.length--;
This post
There’s a remove handler at the bottom
|
|
|
Draco18s
5875 posts
|
Topic: Game Programming /
AS3 or AS2
Originally posted by GameBuilder15:
If it takes twice as long to do everything in AS3, then it takes twice as long to make a game.
Ahh, but here’s the catch:
It doesn’t take twice as long to do everything.
|
|
|
Draco18s
5875 posts
|
|
|
|
Draco18s
5875 posts
|
Topic: Game Programming /
AS3 or AS2
Originally posted by NineFiveThree:
The difficulty of a language is not determined by how many lines it takes to create a button.
This.
Sure, it takes more lines to make a button, but those event listeners are far and away more logical than onPress and onRelease.
As it provides a framework of understanding for more complex tasks, such as custom events.
|
|
|
Draco18s
5875 posts
|
Topic: Game Programming /
Odd issue with two identical, simultaneously attached, objects
that’s why i suggested he find out what’s calling the function and how with the stack trace Error can give you.
I’ll look at it Monday when I’m back at work with the code. :P
|
|
|
Draco18s
5875 posts
|
Topic: Game Programming /
AS3 or AS2
Originally posted by qwerberberber:
Awesome demo BTW draco, does it use the custom perlin noise from a while back?
Yup. I’m still quite impressed that I can generate as much as I can as quickly as I can, despite the non-native perlin noise solution. But it gave me much more flexibility. The clouds, for example, use the following code:
OptimizedPerlin.octaves = 2;
j = i+onY*(chunkWidth*chunkHeight);
x = (j % chunkWidth) / (chunkWidth/4) + int(onX*4);
y = int(j / chunkWidth) / (chunkHeight/4);
ox = OptimizedPerlin.noise(x/ratio,y/ratio, ozdepth);
ox = (ox - .5) * 2;
oy = OptimizedPerlin.noise(x/ratio,y/ratio, ozdepth * 2);
oy = (oy - .5) * 2;
x += c*ox;
y += c*oy;
//tweak the color based on this initial output
var nb = nc + ox + oy;
OptimizedPerlin.octaves = 4;
//take the output of Perlin noise and put it back in again.
ox = OptimizedPerlin.noise(x/ratio, y/ratio, z);
ox *= 256;
ox -= (ox % 1);
a = ox;
a = a * 200 / 255 + 56;
a = int((Math.atan(Math.max((a-128)/r-m,-1*m)))*128 + 128);
//the more "solid" the cloud is, the more towards one color it will be
a = (a < v) ? a : Math.sqrt(a * v);
nb += ((a/255)+0.5)*((a/255)+0.5)-.25;
if(a > 0) {
R = int(NEBULA_COLORS[int(nb)][0] * (1 - (nb-int(nb))) +
NEBULA_COLORS[int(nb)+1][0] * (nb-int(nb)));
G = int(NEBULA_COLORS[int(nb)][1] * (1 - (nb-int(nb))) +
NEBULA_COLORS[int(nb)+1][1] * (nb-int(nb)));
B = int(NEBULA_COLORS[int(nb)][2] * (1 - (nb-int(nb))) +
NEBULA_COLORS[int(nb)+1][2] * (nb-int(nb)));
vect[i] = (a << 24) + (R << 16) + (G << 8) + (B);
}
else {
vect[i] = 0;
}
Half way down is the important part. By altering where on the perline noise function the end value comes from, I get a kind of recursive perlin function that gives a very “whispy” feel.
Then there’s the color…that too ages to get right.
|
|
|
Draco18s
5875 posts
|
Topic: Game Programming /
AS3 or AS2
Originally posted by GameBuilder15:
Draco, I don’t make games because of the money either. I just want to make games, and the money is a bonus.
I only used you as an example, because you’d already been used as an example.
|
|
|
Draco18s
5875 posts
|
Topic: Game Programming /
Odd issue with two identical, simultaneously attached, objects
Originally posted by vesperbot:
here seems to be your issue, your Ship causes alteration of Dictionary, making it ignore the next bullet or plain screw up the index, resulting in a bullet getting omitted.
Ah ha.
Clever.
|
|
|
Draco18s
5875 posts
|
Topic: Game Programming /
Odd issue with two identical, simultaneously attached, objects
Originally posted by Solanix:
What’s calling the update/enterframe that spawns bullets, and more importantly is it part of this dictionary that is in the middle of being updated?
The Ship.as, which I believe is in the Dictionary, yes.
Originally posted by NineFiveThree:
Originally posted by Draco18s:
Also, I do believe that it’s called a singleton.
That implementation of the Singleton is awful.
The purpose of a Singleton is btw to only have one instance of that class.
It is not that static variable dumping ground.
I’ve never worked with Singletons before, but I do agree that the implementation here is awful.
Originally posted by Draco18s:
It’s the shootorial-for-mobile AS3 code..
So what did you expect? Proper code?
Not in the slightest! I’m just trying to figure out why it’s doing what it’s doing.
|
|
|
Draco18s
5875 posts
|
|
|
|
Draco18s
5875 posts
|
Topic: Game Programming /
AS3 or AS2
GameBuilder’s latest
One, small, insignificant portion of my ongoing project
I’m not even sure that what I’ve managed to do is even possible in AS2 (that is, I doubt it would ever run fast enough without timing out).
I’ll admit, he’s finished some games, gotten a few sponsored, and I haven’t. But you know what? I don’t actually care that much. I program because I find it fun, not because I want money (although my day job is also programming).
|
|
|
Draco18s
5875 posts
|
Topic: Game Programming /
Odd issue with two identical, simultaneously attached, objects
Hell if I know, Vesperbot. I didn’t write it.
Also, I do believe that it’s called a singleton.
|
|
|
Draco18s
5875 posts
|
Topic: Game Programming /
Odd issue with two identical, simultaneously attached, objects
Originally posted by qwerberberber:
I’m guessing it’s somewhere in the complicated logic of your code. I suggest writing the system again since it’s doesn’t look that complicated.
It’s the shootorial-for-mobile AS3 code. I understand it, and it’s not really a big deal that it’s doing wonky stuff (it’s going to get reskinned). It was just bugging me.
|
|
|
Draco18s
5875 posts
|
Topic: Game Programming /
Odd issue with two identical, simultaneously attached, objects
FrameTimer.as
package
{
import flash.display.*
import flash.events.*
import flash.utils.Dictionary;
public class FrameTimer extends Sprite
{
public static var instance:FrameTimer = new FrameTimer();
private var displayObjects:Dictionary = new Dictionary(true);
private var paused:Boolean = false;
public function FrameTimer()
{
super();
addEventListener(Event.ENTER_FRAME, enterFrame);
}
public static function pause()
{
instance.paused = true;
}
public static function unpause()
{
instance.paused = false;
}
public static function paused():Boolean
{
return instance.paused;
}
//this logic will happen at frame rate
public function enterFrame(e:Event)
{
if(paused)
{
return;
}
for(var object:Object in displayObjects)
{
object.enterFrame(e);
}
}
public static function add(displayObject:DisplayObject):void
{
instance.displayObjects[displayObject] = true;
}
public static function remove(displayObject:DisplayObject):void
{
if( instance.displayObjects[displayObject] )
{
delete(instance.displayObjects[displayObject]);
}
}
public static function clear():void
{
instance.displayObjects = new Dictionary(true);
}
}
}
|
|
|
Draco18s
5875 posts
|
Topic: Game Programming /
Odd issue with two identical, simultaneously attached, objects
Bullet.as
public function Bullet(x_, y_)
{
//make a sound when a bullet is fired
numBullets++;
if(numBullets % 4 == 0){
var transform:SoundTransform = new SoundTransform(0.1);
var s = new Shot2();
s.play(0,0,transform);
}
//set the bullet speed
speed = 20;
//set the bullet position based on x and y values passed in (it needs to be created at the hero ship's position)
x = x_;
y = y_;
//draw a bullet using the drawing API
//start with a fat black line
graphics.lineStyle(7,0x000000,2);
graphics.moveTo(-2,0);
graphics.lineTo(2,0);
//then draw a thinner white line on top of it
graphics.lineStyle(3,0xffffff,2);
graphics.moveTo(-2,0);
graphics.lineTo(2,0);
//add an ENTER_FRAME event to control the bullet's logic at frame rate
FrameTimer.add(this);
//this improves perfromance of vector graphics
//this.filters = [getGlowFilter()];
cacheAsBitmap = true;
}
|
|
|
Draco18s
5875 posts
|
Topic: Game Programming /
Odd issue with two identical, simultaneously attached, objects
The above code is in Ship.as
As for removing all movement code, no, that won’t help, as the offset is based on their speed.
But get this:

I can get that a frame update could, potentially, happen in the interval between the two creations…but how does it effect the first bullet in one case and the second in the other?
|
|
|
Draco18s
5875 posts
|
Topic: Game Programming /
Odd issue with two identical, simultaneously attached, objects
Originally posted by BobTheCoolGuy:
Something in the movement code?
They’re identical objects, they both have 20 pixels worth of movement per interval.
It’s not like one gets ahead of the other over time, it’s actually spawned offset from the other.
Or somehow the one spawns, gets a movement update, then the other spawns…
|
|
|
Draco18s
5875 posts
|
Topic: Game Programming /
Odd issue with two identical, simultaneously attached, objects

var b = new Bullet(x+50, y+6);
Game.main.spriteClip.addChild(b);
b = new Bullet(x+50, y-6);
Game.main.spriteClip.addChild(b);
What would cause the occasional offset between the two shots? I’ve never seen this before.
|
|
|
Draco18s
5875 posts
|
Topic: Game Design /
[Game Theory] [Game Design] Zombie PACs (A game about politics)
Originally posted by Ace_Blue:
Actually, the biggest problem with this idea is that it’s time sensitive. If you’d come to this forum with it a few months ago someone could have run away with it and made a game out of it in time for the primary. At this point, there is still time to do one for the general election but the dynamic is not quite the same, since I don’t think a GE candidate has ever dropped out of the race (correct me if I’m wrong).
Or, I have them a head start on 2016. 8)
In either case, I didn’t even have the idea a few months ago. The idea is….2 days old? Yeah, Wednesday evening.
The way I see it, you (the player, the SPAC) have to be tied to a candidate, because that’s how you get funding. The higher your candidate places in opinion polls, the more money you get but if, come convention time, your candidate wins the nomination, you lose (since you don’t become a zombie SPAC but must continue to support your candidate through the general election). Therefore you are constantly vying for second place.
Yup! :D
Which is why I think it would make for a great board game. Staying in second is hard (although there are a lot of games where this is the place to be).
Mechanics problems:
1) Who attacks the leader?
Since nobody wants their candidate to be the front runner, who in their right mind would run an attack ad against the front runner? Only their own SPAC, which is somewhat silly. Of course other factors can change the popularity of a candidate, such as their performance in the debates. One option is to give a significant monetary advantage to the SPAC whose candidate is the front-runner, so being first isn’t so much a problem as a calculated risk. Another option it to set a minimum amount of money for victory (one yacht). If nobody gets one yacht worth then the SPAC whose candidate won the nomination wins the game (on the assumption that they can skim enough off the top in the general election to buy the yacht at a later date).
Yeah. It is a problem. But at the same time, I’d really like it if the rise-and-fall was similar to what we’ve seen this year: the guy out in front gets a few weeks of nice coverage, then wham, something stupid and back to the bottom they go. Gingrich has been that “top” guy twice. Obviously, as a game, it’d be ideal to be more “round robin” than real life.
2) Positive feedback loop
There is a great risk of a SPAC being stuck in a positive feedback loop if their candidate starts at the bottom of the pack. They won’t get funding, therefore can’t pull others down, therefore stay at the bottom where they are easily maintained by their better funded competitors. It’s realistic, but boring for the player. I don’t really have an answer for that one.
Actually, that’s a negative feedback loop. Also called the Slippery Slope: that is, the farther behind you are, the harder it is to make a recovery. And yes, it’s also an issue. But it can be mitigated through the use of things that help you more the farther behind you are. E.g. the less-popular your candidate is, the less money it costs to run ads (the TV stations can really price-gouge those doing-well candidates). Or “random events” that help out the “guy in last.” For example, I’m playing Through the Ages, and there’s a card that gives you N victory points per other player with more victory points than you (the value of N depends on the number of players, it works out to 6 if you’re in last place in all cases—unfortunately 6 VP are largely worthless, as a game will tend to end with a 40+ point disparity between first and second).
|
|
|
Draco18s
5875 posts
|
Topic: Game Programming /
[Solved] Timer not firing as it is supposed to
Also, trace is god awful slow. You dump too much stuff into trace at once, or call it too often, and you’ll get lag. It’ll all get there, but it’ll be significantly behind where the program actually is.
Also:
Timer(1) means you’re running a 1 millisecond timer. Which is 1000 frames per second.
|
|
|
Draco18s
5875 posts
|
Topic: Game Programming /
help
This post has been removed by an administrator or moderator
|
|
|
Draco18s
5875 posts
|
Topic: Game Programming /
help
Originally posted by osomo:
i need an empty game file
Open your IDE of choice.
Hit new.
Hit publish.
You know, if that wasn’t too much trouble.
|
|
|
Draco18s
5875 posts
|
Topic: Game Programming /
Beginner needing help..!
Originally posted by Cartmane:
addChild( enemy );
Thanks for the help by the way
Now, find where it says var enemy and copy paste that line here.
Also find the line that says class Enemy and copy paste that line.
|
|
|
Draco18s
5875 posts
|
Topic: Game Programming /
Beginner needing help..!
Double click the error.
Copy that line.
Paste it here.
|
|
|
Draco18s
5875 posts
|
Topic: Game Design /
[Game Theory] [Game Design] Zombie PACs (A game about politics)
Originally posted by lawsome1997:
I think your idea could work but it could also go very wrong. Some good writing and a light heated feel will probably be the best choice. The problem with ideas like this is that if they are not done quite right they are done very wrong.
Oh, this group would be able to do it, I’m sure. We’ve already made light of velociraptors running around eating their own children and ripping people’s legs off.
|