adobe flash cs5 how to move the container & childrens - actionscript

So how can I craete a container for a tank(without code as3) to move the tank(using as3 like tank.x += tankSpeed) itself and at the same time all his parts(wheels, turrel, other stuff), because i don't want to move all the parts independently in each frame, for example rotating the turrel and at the same time move the container of the tank, I didn't found in adobe flash cs5 how to add shapes(rectangles, circles...) to some main container and give it some object name and then get something like this in the code(as3):
container //get the container itself
container.child1
container.child2
if it possible of course

Create a new MovieClip in CS5, put it on the stage, and give it the instance name tank. Inside that MovieClip draw your tank but put each of the moving parts into MovieClips of their own each with a unique instance name, say wheel_1, wheel_2, turret, other_thing.
Now you can manipulate the parts of your tank independently from code on the main timeline like this:
tank.wheel_1.play();
tank.turret.stop();
tank.wheel_2.gotoAndPlay('reverse');
A simple routine to move the tank would look something like this (untested):
var speed = 10;
this.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
// Execute on each frame
function enterFrameHandler(event:Event):void
{
tank.x += speed;
}

Related

Corona SDK dynamic width objects

I'm trying to implement a game mechanics of "Hooking" objects... Here's picture of what i'm talking about:
But I have a problem with the chain/string of the hook.
I've tried create it step by step when the hook is on the fly, using timer and enterFrame events, but they both generate huge gaps between chain segments.
I've tried creating big image of whole chain and changing width dynamicly, but it only stretches and looking funny :D
Maybe anyone faced the same problem?
I would suggest you to try following.
Create whole chain
place it inside container (display.newContainer)
change width of container.
Container automatically generates masks so instead of stretching you will have just part of your chain hidden under mask.
here is link to container docs http://docs.coronalabs.com/daily/guide/graphics/container.html
This is not a complete answer - I have given you a bit of a broad answer to a broad question but I hope it can help you in creating what you need.
I created a very similar mechanic recently -
I used enterFrame to call a function, lets call it BuildHook, this would check the position of the hook and the position of the starting point and then calculate how many pieces of images would be needed to fill out the space. The graphic I had as my "hook" was partially larger then the chain pieces allowing for it to overlap and only put a new image once enough space between the last piece and hook was created.
This ment that it was the hook moving forward and backwards and then having a static "chain" between it and the starting point. Either consuming "links" as would move backwards ontop of them or created "links" as it moved away from them.
Keep in mind this is pseudo code but should give you an idea how to make it.
local arrayOfPieces = {}
local function BuildHook()
-- Bunch of variables you need to get
startX,startY,
hookX,hookY,
lastPieceX,lastPieceY,
singlePieceWidth
-- The hook pseudo code
if(hookX - lastPieceX >= singlePieceWidth) then
local newPiece = display.newImage('singlePiece.png');
newPiece.x = lastPieceX + singlePieceWidth/2
newPiece.y = lastPieceY
table.insert(arrayOfPieces,newPiece)
end
if(hookX < lastPieceX) then
lastPieceArrayPos = table.getn(arrayOfPieces)
table.remove(arrayOfPieces,lastPieceArrayPos)
lastPiece = arrayOfPieces[lastPieceArrayPos - 1]
end
end

AS2 - Display game results at end of level

I'm currently making a maze game at the minute, and I want to include a death counter and a count-up timer. When the level is over, I want the game to display the time taken and the number of deaths made. How can I make it save the death count, and display it at the end?
On your first frame, declare these two variables which will hold the number of deaths and count up (paste the code on your Frame actions):
var deaths = 0;
var time = 0;
Now, whenever the player dies, use this code to increase the death count:
deaths++;
When you want to start the timer, paste this code on the frame where the game begins:
function countUp(){
time++;
}
setInterval(countUp, 1000);
This will run the function every 1000th milliseconds, which is the same as every second (1000 milliseconds = 1 second). The function itself increases the time variable by 1, but it does not display it on the screen.
Now, on the results screen, you first have to make two Dynamic Text Fields (create a text field, open the Properties Panel [CTRL+F3], and change it from Static text to Dynamic text). Give these two Dynamic text fields the instance names of, death_txt and timer_txt, respectively. Then, paste this code on the frame actions of the results screen:
death_txt.text = deaths;
timer_txt.text = time;
This will make them show up on the screen.
By the looks of it, it doesn't seem like you're familiar with variables, but they're nothing but containers which contain values. You can control them "behind the scenes", meaning that you can calculate, store and change them in Flash without them appearing on the screen. This is useful since you don't want the death count and count up to actually be shown during gameplay, right?
If you need more clarficiation, please don't hesitate to ask.
Hope this helps :)

Adobe flash(cs5) how to replace animations

I have a symbol of a person standing, he have child movieClips like hands, legs, head, body....so then if i press a button or click in the stage how do i need to change the animation instantly?
I suppose:
1) create a new movieClip that has all the same parts but animated as walking(for example) and then make something like:
if(keypressed)
{
person.replaceSymbol(myNewAnimatedSymbol); //method that not exist
}
2) for example if my standing animation longs from 1 to 30, i can make another animation in the same line let's say from 31 to 60 where he is running and then write:
if(keypressed)
{
person.legs.gotoAndPlay(31); //in the 60 frame he go back to 31 by using gotoAndPlay(31)
person.hands.gotoAndPlay(31);
person.body.gotoAndPlay(31); //and so on...
}
Can you give me an advice of which of methods I need to use? or if you have a better idea how to make it...
Hm-m-m. I'd say your second approach is easier to both draw and control, especially if it'll eventually come to reskinning your MC, say your person will get dressed in a cloak that's attached to the body and arms, your "new animated symbol" will likely require a change to accommodate that clothing, while in case of one symbol you can assign its parts another look, like say person.hands.cover=clothing.handpart; person.legs.cover=clothing.legpart etc, and then the animation will contain references to cover being changed, so that correct parts of clothing will appear around all the moving parts.
In fact, you might not need separating your person into different body, hands, legs etc MCs, but instead make it so that your person's legs are a container that can hold either a bare body part (naked leg drawing) or a dressed body part (a boot, pants, etc), and animate the main part by making these containers move according to how a person should walk, stand, run, attack etc etc., so that you will have a single point to dress the entire set of your person's animations.
It depends for example my character has around 100 animations. Putting them in a single timeline and telling them to go from this label to that label (or frame) is a huge mess to manage.
So I have 100 library items with export symbols. I keep on switching between them. This makes it easy to manage.
So, I think the question is how many animations do you have? Can you manage them in a single timelines? If you can , I'd say go with labels or frame jumps.
Both of your methods are correct and your second method would be faster because you're not adding or removing anything from the display list.

corona drag and drop an object on container or reference

I am developing a game and one level is solving a jumbled up word. The letters are images like tiles and I am trying to either click a letter and this will move to the first of the allocated spots to solve the word or to actually drag the tile to the spot. Can anyone help me implement this?
To drag an object see this tutorial:
http://www.coronalabs.com/blog/2011/09/24/tutorial-how-to-drag-objects/
If you just want to tap them and have them move to where you want them, then something like this might work for you:
local function moveTile(event)
-- put your code here to move the tile
-- figure out the X, Y where the tile needs to move to
-- either just set the X, Y on the tile or use a transition.to() call
-- to animate it.
local thisTile = event.target
thisTile.x = destinationX -- you have to figure out what destinationX is.
thisTile.y = destinationY -- figure this out too
return true
end
Then on each tile after you create it, simply add this line to make it tappable:
tile:addEventListener("tap", moveTile)

Optimal way to render multiple scenes with large numbers of objects in Three.js

Imagine that you want to draw two scenes, each with hundreds of spheres, and provide the ability to switch between these scenes. What is an optimal way to do this?
Currently a switch takes about 4 to 5 seconds because I am deleting, creating, and drawing all of the spheres on each switch. Below is an example of the code that runs on a scene switch.
clearObjects();
resetCamera();
for(var i = 0; i < 500; i++) {
var geometry = new THREE.SphereGeometry(radius, 50, 50);
var material = new THREE.MeshLambertMaterial({color: 0xFFCC33});
var sphere = new THREE.Mesh(geometry, material);
sphere.position.set(randX, randY, randZ);
scene.add(sphere);
objects.push(sphere);
}
Once again, why don't you just use one scene, split it in 2 parts, set your camera FOV (field of view) so that you can see just one scene part at a time and then just move your camera position... Doesn't it sound more efficient?
If there are no particular reasons for using 2 scenes, you can always implement your code with just one scene. So try the method I described above or explain your reasons to use 2 scenes.
Edit: You can also use two THREE.Object3D containers to represent your 2 scenes, where you can store all of your certain scene objects and then just show/hide one of the containers at a time. Than way you can manipulate all of the container's contents using yourContainer.children[n].
So generally, that is what you want to do:
var scene1Container = new THREE.Object3D();
var scene2Container = new THREE.Object3D();
scene1Container.add(firstObjectFromScene1);
//.....
scene1Container.add(nObjectFromScene1);
scene2Container.add(firstObjectFromScene2);
//.....
scene2Container.add(nObjectFromScene2);
now you can just show/hide one of the containers at a time using scene1Container.visible = true/false; (And manage scene1Container.traverse to apply visibility change to all of the children of your object).

Resources