I use assetmanager to load tmx,
Some collectable object such as coin, need to be removed when hero touch it. So I destroy like this
object.setCell(x, y, null);
But when I restart the level game, those collectable coin doesn't appear because the cell was null. How can I reset those null cell object? Please help me
Related
I am developing a small game using Flash CC. The question may seem very absurd since I am a novice to coding and Action Script.
Here it goes: Can we write a code to convert a symbol to bitmap?
Actually, the game has multiple objects and I have defined them as buttons. When the user clicks on one of the object, it moves to a new position. I dont want two objects simultaneously to move to a new position.
My logic: If I can make every other object as a bitmap, the user wont be able to click on any other object when one object is moving. Any thoughts???
Yes that is possible.
this code makes a bitmap from your displayObject:
var bitmapData:BitmapData=new BitmapData(symbol.getBounds(this).width,symbol.getBounds(this).height,true);
//The BitmapData Class contains pixels information for a bitmap.I created a bitmap data
//with width and height of the symbol. and set visiblity true.
var bitmap:Bitmap=new Bitmap(bitmapData);
//you know about this !
bitmapData.draw(symbol);
//The draw() method, does what you want.set pixels from a DisplayObject
//and use a matrix in parameters for the rotated,scaled,... form of the DisplayObject.
Now, The bitmap is ready.
I h☺p e this helps !
So I'm new to coding as a whole and though I've messed a little with AS before I'm at an absolute loss. I've been using a pretty helpful website that gives a step-by-step on making a platformer/sidescroller, but one of the key things I want to include in my game is the ability to swap between two characters- i.e., if the player hit space or any other key, you could swap out to the other character (with different abilities and all).
My game only really has one big stage, and it's nothing complicated at all (it's something I'm trying to get done in about a little over 24 hours) which is why I decided not to make the character change for each "level"- because there's only one big one. I want the player to be able to decide when they want to play whichever character they fancy, but I have no idea how to go about it.
Uh, and if it helps clarify anything, I basically tried to follow that tutorial site as closely as I could without copying source code.
Thanks so much for taking the time.
You need to do a thing named "separate graphics from code". The tutorial says "convert your player to a Movie Clip Symbol ... create new Player(), add it to stage", then it teaches about how to control the player. You need to split your Player class into two, one remains as Player and contains code, the other is a skin class, barely a MovieClip without code. In your Player class you need to make a method to operate skins, the interface is up to you, I suggest a string lookup of a skin class, then you can tell your player to change skins both at costruction time and probably at runtime. An example:
public static const SKIN_DEFAULT:String="default";
public static const SKIN_RED:String="red";
public static const SKIN_BLUE:String="blue";
private static var SKINS:Object={
SKIN_DEFAULT:DefaultFace;
SKIN_RED:RedFace;
SKIN_BLUE:BlueFace;
}
Here, SKINS is a lookup object with keys as strings and value as Class references, these are the MovieClip symbol names an example expects to exist. Say you want a gray blob, a red angry face and a blue smiley save to be available, you name them DefaultFace, RedFace, BlueFace and put these names into this lookup object. Then, you need to make your player change skins. It's pretty easy once you get the drill.
public class Player extends Sprite {
// Sprite should do, as Player is now code-only
private var skin:MovieClip; // this will hold our player's skin
public function setSkin(newSkin:String):void {
// call this to change the skin
var newSkin:Class=SKINS[newSkin] as Class;
if (newSkin==null) return; // sanity check
if (skin) if (skin is newSkin) return;
// ^ changing skin for the same? We're that skin already!
if (skin) if (contains(skin)) removeChild(skin); // remove old skin
skin=new newSkin(); // create a new skin object
addChild(skin); // make it attached to the player
} // we're done!
// rest of code here
}
Make sure that your Player will at least put on default skin when created, or else you won't be able to see player move.
In order to trigger skin change, you can create an array of buttons, up to making them out of all possible SKINS (for this, either expose SKINS variable by declaring it public instead of private as it's now, or provide another means to get the list of classes), which will call player.setSkin() with a correct parameter.
I am new to Lua scripting, and game development. So please I am just a noob in Lua.
I have searched the net for solutions to my problems, without any luck.
I use Photoshop, Corona, Dusk, json and Tiled on windows7.
I am creating a "board" like game, i.e. Setlers. I am using a world map, as the background. The background image of the game area is a world map (world.png file). I have no problem here.
I would like to create transparrent clickable objects matching the countrys borders on my gamemap with all parameters and values (I have added in Tiled) stored in the object. So When the player clicks on the country the transparrent object (on top of the map) is the one clicked and an eventlistener acts on the click.
In Tiled I can create all the objects I need, naming them + assigning parameters and other values.
If I add object.alpha value in Tiled, the alpha value is passed on to corona and working there.
How can I read these data from the json/tmx file in Corona and adding them to a lua table?
The way I am thinking to use the Tiled map and its objects, is to create one polyline trace of each country’s border (creating one object per country). Then place each “country traced object” on top of the world.png map, also naming the object with the countrys name like “object.name = TileBritannia” and also the other properties for use in game.
My problem is getting the objects info, like object.name, and an eventlistener reacting to a click on the object.
Is a polyline the right way to create a clickable area on a map, when I use a png file as a background image?
What is the best way to create a country border objects, in one layer or with all countries as individual object layers in Tiled.
Can I create one layer with sub objects and still access them in my code?
How do I get the object name and other properties, set in Tiled.
When I try to use the (local britannia = tiledMap:load("britannia.json")) the "load" is not working, getting a nil value.
I am looking for a code that will extract/get/read the object.name i.e. “objBritannia” or "TileBritannia". from the json/tmx file.
When I try to read the different parameters from the json file, I don't get the result I expect. I get the result = function: 046A73B0, was hoping for an object name of some sort.
Please provide links to or code example.
I have edited the question.
Thanks
For questions 1 and 2: I have not used Tiled, but based on Corona Tiled, you have the right strategy in mind. That page makes me think that you can just use tap event listener to detect tap. If you are having issues with the example on that web page, please update your question to be more specific. If tap event handling doesn't work (maybe you're talking about a different Tiled lib), look a Polygon fill and Point in Polygon detection, because that's basically what you need to do. Try some stuff from there. If it still doesn't work for you, then update your question with specifics otherwise it will be likely get closed (it is a little too broad as it is).
For #3, Lua is a dynamic language that supports adding properties to objects in one line. So upon the example on the Corona Tiled page, all you would have to do is
tiledMap = require("tiled")
local britannia = tiledMap:load("britannia.json")
britannia.name = "Britannnia"
local Zulu = tiledMap:load("zulu.json")
zulu.name = "zulu"
Naturally you will probably have a whole bunch so you will create a function that you call for each tile. It's not clear what map.layer["objBritannia "].nameIs("TileBritannia") is supposed to do so I can't comment.
So I have this assignment due tomorrow and Its to make an audio player in Flash using as3. I don't understand as3 at all. I have the code for the player working becuase I just used the same code we used in class, but I kind of want to make it my own.
I have created an Ipod style player.
First thing, I want the Forward button to play the next song. How would I write the code for that?
Next When a song plays I want a specific image to show up. and when the next song comes on the next image to show
This is the code i have for the songs
function playTrack(e:MouseEvent) :void {
switch(e.target.name) {
case "track1":
trackToLoad = "audio/Don't Stop Believing.mp3";
trackName = "Journey • Don't Stop Believing"
break;
case "track2":
trackToLoad = "audio/Never Never Land.mp3";
trackName = "Metallica • Never Never Land"
break;
...
but instead of having just a stop and play button and 10 buttons that play each song I want to have a skip button to go to the next song..
hope this is enough info for some help
Thanks
Set your tracks up as an array of objects:
var track1:Object = {
track: 'Don\'t stop believing',
artist: 'Journey',
file: 'dont_stop_believing.mp3'
};
var track2 //same as above
var tracks:Array = [track1, track2, ...];
You could really create a Track class, but it sounds like you aren't to that point yet.
Instead of making your playTrack function actually be the mouse event handler, you should separate it out so that it can be used universally no matter how the track begins to play (i.e. clicking on that track's button, clicking on the next button, or after the previous song ends). Write a separate function just to handle the mouse event (i.e. clickTrack()), which will call your playTrack() function.
Setting your tracks up within the array will allow you to keep note of the indices of each track (including the currentTrack) as a number. That way you can iterate through the tracks by just incrementing the currentTrack variable.
This way, you can set your playTrack() function up to take a trackNumber parameter (i.e. playTrack(1). Then just use that parameter to reference the index of the track you want to play within the tracks array. Remember that arrays are on a 0 index meaning that the first element is index [0], the second is [1], etc. So you'll either have to write your playTrack() function in that way, or convert by subtracting 1.
Try storing some kind of Track object in an indexed array. You can keep track of the index, and change it when the user clicks skip or back. The Track object could store the filepath, the track name, and the art that you want to display. When the index changes, grab the correct track from your array and update the player.
Here is an example that actually uses song titles.
I'd like to make a simple game where "discs" fall from the top of the screen and the user must catch them. I have a MovieClip which I want to resize to one of three randomly chosen sizes.
As I see it, there are four things that must be done.
Create and size the MovieClip
Position the MovieClip
Make the MovieClip fall
Determine when it is finished "falling" and see if the user has "caught" it.
My question is: How do I create, size and position the MovieClip? I've given it an identifier of "disc". Now what? Do I make an ENTER_FRAME event and do my creation there? How do I move the disc downwards? Do I use tweens, something else?
I'm primarily asking this as a sanity check.
I would use some kind of factory class that would be responsible for dropping random discs from the top of the stage.
Beside what you correctly mentioned, you will also need to:
define if the speed for falling is constant or not, you may need some acceleration tween. To move the objects downwards, you could use a native tween method, you will need to apply it to every disk that gets dropped.
define where the disk will start falling, it can be random or always from the same place.
you can find out if two objects are colliding using the AS3 hitTestObject method which belongs to the DisplayObject class.
you factory class could have a start() and stop() method. Once start() is fired, an infinite or ENTER_FRAME loop is started and disks start falling. If you want to create disks at a specific rate you could combine your loop with a timer to run code on a defined interval. For instance, every 3 seconds create 10 disks (using main loop) and drop them onto the stage.
Assuming that you have MovieClips named 'disc' & 'userHand' exported into actionscript, I'll summarize it in the foll way:
Generate the no of discs & Randomize their location. Start with something like:
var n:int = 30; //Total no of Discs
for(i:int=0;i<n;i++)
{
var mc:disc = new disc();
mc.x=Math.random()*stage.width(); //to scatter the discs across the stage
mc.y=-mc.height; //initially hide out a disc
addchild(mc);
}
Also add the Movie clip 'userhand' to stage.
Add enterframe handler function.
Fill in the enterframe handler to update (keep increasing) the y position of each disc.
Use hitTestObject() in the enterframe handler to determine hit among each 'disc' & 'userHand'.
Reset position of all the 'disc' clips which fall off the screen to random positions as initially.
You might want to look at programming particles.
http://r3dux.org/2010/01/actionscript-3-0-particle-systems-3-rain-effect/
At a very high level what you would do is.
You need to create a disc class.
You could give this class some variable properties like width, height,x etc.
In an enter frame in your main class you would add an enterframe function that creates new instances of disc passing it random values for each property.
Each instance of disc could also have its own entframe which increases its y position until it reaches the bottom of the screen. The disc would then remove its self from the stage. You could use an easing function passing it a random number to determine the rate at which its falls.
Say if its y position is greater than the stage height, remove the disc. If the user catches it (using a hit test maybe) also remove it.
It really recommend having a look at that link I posted.