Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411414 Posts in 69360 Topics- by 58415 Members - Latest Member: sophi_26

April 16, 2024, 12:03:29 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsCommunityTownhallForum IssuesArchived subforums (read only)TutorialsLearn to code flash games for $0! An introductory tutorial to actionscript 3.0
Pages: 1 2 [3] 4
Print
Author Topic: Learn to code flash games for $0! An introductory tutorial to actionscript 3.0  (Read 49058 times)
agj
Level 10
*****



View Profile WWW
« Reply #40 on: October 26, 2008, 01:23:57 PM »

Cagey, thanks for this great tutorial, it was very useful for me to do a smooth transition from the Flash IDE to Flex SDK. Since I'm not taking advantage of the Flash IDE's characteristics in my project, the comparatively lightweight FlashDevelop is a lot easier to work with. Good stuff.
Logged

Terry
TIGSource Editor
Level 10
******



View Profile WWW
« Reply #41 on: October 26, 2008, 01:36:19 PM »

I got a hello world working last night thanks to this Smiley Looking forward to the next one!
Logged

Skofo
Level 10
*****



View Profile
« Reply #42 on: October 26, 2008, 02:07:18 PM »

Someone needs to make a vector editor that exports to Flash code, or an Inkscape XML to Flash code/Movieclip converter.

AM I UP TO THE CHALLENGE? We shall see!
« Last Edit: October 26, 2008, 02:55:04 PM by Skofo » Logged

If you wish to make a video game from scratch, you must first invent the universe.
Cagey
Level 1
*



View Profile WWW
« Reply #43 on: October 26, 2008, 04:07:09 PM »

Why it's your lucky day!

http://musprite.sourceforge.net/

Also, tutorial forum much?
Logged

Skofo
Level 10
*****



View Profile
« Reply #44 on: October 26, 2008, 04:33:09 PM »

Why it's your lucky day!

http://musprite.sourceforge.net/

You are a God.

Thank you.
Logged

If you wish to make a video game from scratch, you must first invent the universe.
agj
Level 10
*****



View Profile WWW
« Reply #45 on: October 26, 2008, 11:22:54 PM »

Isn't importing an SVG the same thing?

(Actually, obviously not, because I tried doing that today and for some reason the picture came out wrong...)
Logged

ஒழுக்கின்மை (Paul Eres)
Level 10
*****


Also known as रिंकू.


View Profile WWW
« Reply #46 on: January 18, 2009, 07:54:54 PM »

I've two questions about this tutorial. I don't know if you're still around but I figure I'd ask.

1) In your final example code of your example painting program, you have this function:

Quote
public function clickColourButtons( buttonNumber:int ):void
      {
         colour = colours[buttonNumber];
      }

Why have a single-line function that is only used in one place? Doesn't it make more sense to just do colour = colours[buttonNumber] instead of having a whole function for it?

2) In this function, you have

Quote
public function isOverColourButtons( x:int, y:int ):Boolean
      {
         if ( x < colourButtons.x ) return false;
         if ( x > colourButtons.x + colourButtons.width ) return false;
         if ( y < colourButtons.y ) return false;
         if ( y > colourButtons.y + colourButtons.height ) return false;
         return true;
      }

But width and height are not defined anywhere. Yet they work, even when I vary the width by adding more buttons. I find that very weird. Does an object know its actual width and height even though you don't define them or set them?
Logged

imaginationac
Level 2
**


Makin' games instead of makin' money.


View Profile WWW
« Reply #47 on: January 18, 2009, 10:11:41 PM »

2) In this function, you have

Quote
public function isOverColourButtons( x:int, y:int ):Boolean
      {
         if ( x < colourButtons.x ) return false;
         if ( x > colourButtons.x + colourButtons.width ) return false;
         if ( y < colourButtons.y ) return false;
         if ( y > colourButtons.y + colourButtons.height ) return false;
         return true;
      }

But width and height are not defined anywhere. Yet they work, even when I vary the width by adding more buttons. I find that very weird. Does an object know its actual width and height even though you don't define them or set them?

width, height, x, and y are inherited properties from DisplayObject, so yes.
Logged

Youtube channel | Charger! Dev Log
              
ஒழுக்கின்மை (Paul Eres)
Level 10
*****


Also known as रिंकू.


View Profile WWW
« Reply #48 on: January 18, 2009, 10:14:54 PM »

Well, I assume the property exists, so what I was really surprised at is not that they weren't declared, but that they adjust themselves automatically as you draw stuff on the shape. Like, it feels weird that if you draw a rectangle that's 100 pixels by 100 pixels on a shape, and then another one next to it on the same shape, that it would automatically adjust its width to 200 and height to 100, instead of you having to tell it that. Not that it's a bad thing by any means, just that it's unexpected behavior for it to add up the two rectangles and know its own new width.
Logged

Cagey
Level 1
*



View Profile WWW
« Reply #49 on: January 19, 2009, 12:30:07 AM »

Long time no post.

1. I find its a good habit to put things like that in to functions so that if I change something related, I only have to change the one function rather than sorting through my code to see what I have to change. If you know you won't change the code later on you can avoid the use of the function but in creating complex projects is usually not a bad idea to abstract it like that. Could be I was just coding crappily though Tongue

Hideous has convinced me to make the next tute (sorry anyone who was expecting this earlier!) so i'll be posting a bit in a couple of days. If you have anything you'd like covered or any ideas feel please post!
Logged

BorisTheBrave
Level 10
*****


View Profile WWW
« Reply #50 on: January 19, 2009, 03:35:07 AM »

Not that it's a bad thing by any means, just that it's unexpected behavior for it to add up the two rectangles and know its own new width.
If you think about it, it makes perfect sense. Of course something should know it's own width, it would be tedious to be constantly calculating that for yourself. A lot of variables like that update "behind the scenes", they are a useful way of using objects to hide more complex behaviour. You don't need worry about how width is calculated, just that objects can do it for you.
In fact, properties like width are not variables at all, they are getter/setter functions. I.e. when you read or write to them, this is translated into a function call which can do more complicated stuff. So it's not like adding a single shape updates hundreds of variables, instead the true width is probably calculated on the spot when you request it (but done internally by the Flash Player, so fast). That's how when you say
object.width *= 2, it changes an awful lot of stuff, not just a single variable.
Logged
Problem Machine
Level 8
***

It's Not a Disaster


View Profile WWW
« Reply #51 on: January 19, 2009, 04:05:50 AM »

I hate custom-coded getter/setters, because they almost always result in more confusing code with no commensurate benefits, but I must admit to a certain affection for the built-in getter/setters.

That said, (and now drifting somewhat OT), would anyone have suggestions on how to code equivalent functions in C++? I'm making a Sprite class for use with SDL/OpenGL with an interface inspired by the Flash Sprite class, and I'm having trouble with functions like getWidth and getWorldX that require traversing the parent tree and taking into account all the rotation/translation matrices. If anyone knows of any example code I could work from it would be super useful.
Logged

BorisTheBrave
Level 10
*****


View Profile WWW
« Reply #52 on: January 19, 2009, 04:36:59 AM »

I hate custom-coded getter/setters, because they almost always result in more confusing code with no commensurate benefits, but I must admit to a certain affection for the built-in getter/setters.
As always, with great power, comes great responsibility. Here's a simple example I think where they are definitely good:
Rectangles in Flash (IIRC), have a width, left, and right property. Obviously, they are constrained that width = right - left. But you can set any one of them, and still have this relationship maintained. You don't need tons of boilerplate getLeft(), setLeft(), or even need worry that it's doing extra work for you.
Another vital use for them is making read-only variables, obviously.

That said, (and now drifting somewhat OT), would anyone have suggestions on how to code equivalent functions in C++? I'm making a Sprite class for use with SDL/OpenGL with an interface inspired by the Flash Sprite class, and I'm having trouble with functions like getWidth and getWorldX that require traversing the parent tree and taking into account all the rotation/translation matrices. If anyone knows of any example code I could work from it would be super useful.
If you are traversing the tree, you can "push" the current nodes transformation matrix when you enter it, and "pop" it when you leave, where push and pop mean multiply the current world transformation matrix by it or it's inverse. OpenGL does this all the time, have a look at an intermediate tutorial.
More likely though, you are not traversing the tree, in which case you have to make up your mind whether to store two matrixes (local and world transformation), or recalculate the latter each time. Or maybe there's more advanced ways of doing this, I don't know.

In any case, having got a world transformation matrix for each sprite, it should be easy to write getWidth, getWorldX etc.
Logged
Problem Machine
Level 8
***

It's Not a Disaster


View Profile WWW
« Reply #53 on: January 19, 2009, 05:07:38 AM »

Quote
If you are traversing the tree, you can "push" the current nodes transformation matrix when you enter it, and "pop" it when you leave
That's how I traverse it on the way down (for rendering), but in this case I'm going up from the sprite to the stage. It was easy to do for the alpha function:
Code:
float Sprite::getTotalAlpha() const
{
return (mParent)?mAlpha*mParent->getTotalAlpha():mAlpha;
}
But I'm having a difficult time figuring out how to get any sort of elegant solution to this when parental rotation and translation come into play. I could have the sprite memorize its world matrix on each render pass, but that would a) be ugly and b) not work in any case where they tried to use these functions immediately after making a change elsewhere.
Logged

BorisTheBrave
Level 10
*****


View Profile WWW
« Reply #54 on: January 19, 2009, 05:51:57 AM »

Um, how about:
Code:
TransformMatrix Sprite::getWorldTransform() const
{
return (mParent)?mParent->getWorldTransform()*mLocalTransform:mLocalTransform;
}
Where TransformMatrix is the 2x3 matrix representing rotation/translation, and it has the appropriate overloaded operator*. If you don't have such a matrix class, get one, it'll simplify all your code.
Logged
ஒழுக்கின்மை (Paul Eres)
Level 10
*****


Also known as रिंकू.


View Profile WWW
« Reply #55 on: January 19, 2009, 07:23:10 AM »

Hideous has convinced me to make the next tute (sorry anyone who was expecting this earlier!) so i'll be posting a bit in a couple of days. If you have anything you'd like covered or any ideas feel please post!

A few ideas on what basics to cover next:

- using bitmaps/sprites (preferably animated ones with several frames)
- moving something with the keyboard (e.g. arrow keys)
- music and sound effects
Logged

increpare
Guest
« Reply #56 on: January 19, 2009, 08:41:46 AM »

Hideous has convinced me to make the next tute (sorry anyone who was expecting this earlier!) so i'll be posting a bit in a couple of days. If you have anything you'd like covered or any ideas feel please post!

A few ideas on what basics to cover next:

- using bitmaps/sprites (preferably animated ones with several frames)
- moving something with the keyboard (e.g. arrow keys)
- music and sound effects

Yeah.  I was thinking I'd like to do a simple platformer for my next effort, so something that might help with those lines would be good.

(rinku, have you checked out the BenH's example I posted on the other thread?  It has keyboard input in it...might help in that regards....)
Logged
ஒழுக்கின்மை (Paul Eres)
Level 10
*****


Also known as रिंकू.


View Profile WWW
« Reply #57 on: January 19, 2009, 09:00:58 AM »

Haven't seen that actually -- which other thread do you mean?
Logged

increpare
Guest
« Reply #58 on: January 19, 2009, 09:02:59 AM »

Haven't seen that actually -- which other thread do you mean?
Why, our thread.  More specifically this post.
Logged
ஒழுக்கின்மை (Paul Eres)
Level 10
*****


Also known as रिंकू.


View Profile WWW
« Reply #59 on: January 19, 2009, 09:04:09 AM »

Oh, that one!

Funnily enough, I didn't think it was a tutorial because it was a .zip file. But I guess it is a tutorial in a .zip file.
Logged

Pages: 1 2 [3] 4
Print
Jump to:  

Theme orange-lt created by panic