Recently I purchased gamemaker and followed Shaun Spalding's menu tutorial to get set up, but I've come across something that I want to change with the code. In the tutorial the options from the array are positioned so that they are one above the other, however for my game I want them to be right next to each other so that option 1 can be positioned on the left side of the screen, and option 2 on the right side of the screen on the same 'line' (but still able to switch between selecting either).
This is what it looks like currently.
As you can see, they are above each other, when really I want them side by side.
This is the code I have:
'Create' Event:
instruction[0] = "Back";
instruction[1] = "Start Game";
space = 100;
ipos = 0;
'Step' Event:
var move = 0;
move -= max(keyboard_check_pressed(vk_left),keyboard_check_pressed(ord("A")),0);
move += max(keyboard_check_pressed(vk_right),keyboard_check_pressed(ord("D")),0);
if (move != 0)
{
ipos += move;
if (ipos < 0) ipos = array_length_1d(instruction) - 1;
if (ipos > array_length_1d(instruction) - 1) ipos = 0;
}
var push;
push = max(keyboard_check_released(vk_enter),keyboard_check_released(vk_shift),keyboard_check_released(vk_space),0);
if (push == 1) scr_instructions();
'Draw' Event:
draw_set_halign(fa_left);
draw_set_valign(fa_middle);
draw_set_font(fnt_options);
draw_set_color(c_white);
var m;
for (m = 0; m < array_length_1d(instruction); m += 1)
{
draw_text(x + space, y + (m * space),string(instruction[m]))
}
draw_sprite(sprite_index, -1, x + 16, y + ipos * space - 21);
Anyone know what I need to change to get this to work?
Your draw_text seems to increase the y coordinate for each iteration in the loop.
Try to increase x using m instead.
Example:
draw_text(x + (m * space), y + space,string(instruction[m]))
You will likely have to adapt the spacing to get desired look.
Easiest is probably to hard code the coordinates instead of using a loop.
Do the same with draw_sprite.
draw_sprite(sprite_index, -1, x + 16 + ipos * space, y - 21);
I am working on a homework project to rotate a simple 2D array holding RGB values for a PGM file.
I've read many posts in these forums about how to do this in C, and I've almost got it working. My output file has the correct dimensions and is rotated, but there is a thick black border around the top and sides. I just can't figure out what I'm doing wrong.
Any help would be greatly appreciated!
I modified the code presented here to get started, and this is the rotate90 function I'm working on now:
PGMImage* rotate90(PGMImage *old_img)
{
int x, y;
PGMImage *new_img = malloc(sizeof(PGMImage));
new_img->maxVal = old_img->maxVal;
new_img->width = old_img->height;
new_img->height = old_img->width;
for (x = 0; x < old_img->width; x++)
{
for (y = 0; y < old_img->height; y++)
{
new_img->data[old_img->height - 1 - y][x].r = old_img->data[x][y].r;
new_img->data[old_img->height - 1 - y][x].g = old_img->data[x][y].g;
new_img->data[old_img->height - 1 - y][x].b = old_img->data[x][y].b;
}
}
return new_img;
}
void main()
{
PGMImage* img = malloc(sizeof(PGMImage));
getPGMfile("columns.pgm", img);
save("columns_new.ppm", rotate90(img));
}
The save() and getPGMfile() functions work perfectly on their own.
It's only when I pass the result of my rotate90() function to save() that I get the funky results.
How about trying memcpy(new_img, old_img, sizeof(PGMImage) after the malloc statement. Maybe some other attributes besides width and height are not initialized. And also, if the data variable is a pointer, did you malloc a piece of memory for data for the new_img object?
I'm wondering if it is possible to reset / reload / reconstruct an array order?
I'm making this "Space Invaders" game and the enemy's need to restart to it's position when the game is being restarted. When I shoot down the enemy's and reset my game, the enemy's I've killed keep being gone.
So here's some of the code responsible:
var spiderArray:Array = new Array(enemyField.enemy1,enemyField.enemy2,
enemyField.enemy3,enemyField.enemy4,
enemyField.enemy5,enemyField.enemy6,
enemyField.enemy7,enemyField.enemy8,
enemyField.enemy9,enemyField.enemy10,
enemyField.enemy11,enemyField.enemy12,
enemyField.enemy13,enemyField.enemy14,
enemyField.enemy15,enemyField.enemy16,
enemyField.enemy17,enemyField.enemy18,
enemyField.enemy19,enemyField.enemy20,
enemyField.enemy21,enemyField.enemy22,
enemyField.enemy23,enemyField.enemy24,
enemyField.enemy25,enemyField.enemy26,
enemyField.enemy27,enemyField.enemy28,
enemyField.enemy29,enemyField.enemy30,
enemyField.enemy31,enemyField.enemy32,
enemyField.enemy33,enemyField.enemy34,
enemyField.enemy35,enemyField.enemy36,
enemyField.enemy37,enemyField.enemy38,
enemyField.enemy39,enemyField.enemy40,
enemyField.enemy41,enemyField.enemy42,
enemyField.enemy43,enemyField.enemy44,
enemyField.enemy45,enemyField.enemy46,
enemyField.enemy47,enemyField.enemy48,
enemyField.enemy49,enemyField.enemy50,
enemyField.enemy51,enemyField.enemy52,
enemyField.enemy53,enemyField.enemy54,
enemyField.enemy55,enemyField.enemy56,
enemyField.enemy57,enemyField.enemy58,
enemyField.enemy59,enemyField.enemy60,
enemyField.enemy61,enemyField.enemy62,
enemyField.enemy63,enemyField.enemy64,
enemyField.enemy65,enemyField.enemy66);
Now the place where the enemy's are being killed:
function enemyHitTest():void {
//for each of the three spiders
for(var i:int = 0; i < spiderArray.length; i++) {
//the each of the six bullets
for(var j:int = 0; j < 6; j++) {
//don't consider bullets that aren't in play:
if(bulletArray[j].y > SpelerMC.y) continue;
if(spiderArray[i].hitTestObject(bulletArray[j])) {
score += 10;
scoreTxt.text = score.toString();
trace("Invader " + i + " neergeschoten!");
spiderArray[i].parent.removeChild(spiderArray[i]);
bulletArray[j].x = j * 70 + 100;
bulletArray[j].y = 595;
}
}
}
Now I think I need to put some sort of theArray.pop(); or something, but don't know how to use it, but I need to place it in this function:
function startGame() {
trace("Start het spel opnieuw...");
gameTimer.addEventListener(TimerEvent.TIMER, onTick);
gameTimer.start();
enemyField.x = 400;
enemyField.y = 160;
SpelerMC.x = 83;
SpelerMC.y = 531;
}
Please help me! Have been searching for 5 hours already. Thanks in advance!
to remove element number i use array.splice(i, 1); ( http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Array.html#splice().com/en_US/FlashPlatform/reference/actionscript/3/Array.html#splice%28%29) but keep in mind that array.length will decrease
to reset the array just invoke spidersArray = new Array(enemyField.enemy1, etc) again
UPDATE
in in the enemyHitTest function i changed the removing condition to if(enemyArray[i].visible && enemyArray[i].hitTestObject(laserArray[j])) and enemyArray[i].parent.removeChild(enemyArray[i]); to enemyArray[i].visible = false;
and added
function respawnEnemies():void{
for(var i:int = 0; i < enemyArray.length; i++) {
enemyArray[i].visible = true;
}
}
to call it from startGame
full code here
upd 2
so the problem was not in resetting the array but in the fact that your enemyField and its' enemies were added to stage manually and removed programmatically so there was no code to call to bring them back
if all your instances should be preserved - e.g. you generate all actors at the beginning and later all of them are reused (at the new game) you can set an array of them and on each start game make a copy and remove "dead" enemies from the copied array
also better option is to use a vector e.g.
var enemies:Vector.<Enemy> = Vector.<Enemy>([]);//in brackets references to the instances of Enemy class
var inGame:Vector.<Enemy> = enemies.concat();
also 5hrs of research? please be patient and try harder,
best regards
So im recreating my ear training program with more effective coding so i can add on to it.
original i did.
//88 C8
var mp3Req88:URLRequest = new URLRequest("88.mp3");
var mp3_88:Sound = new Sound();
mp3_88.load(mp3Req88);
I basically got 88 sound files (each note of the piano) doing this code 88 times for each sound. with mathamatical equations made my ear training program.
Is there a simpler way to import these sounds in a loop of some sort so i dont have to do this 88x for the piano and however many times for the other instruments i will be including?
thus var i have tried things along the lines of below with failure
var i:int;
for (i = 0; i < 5; i++)
{
var pianoMP3Req+i:URLRequest=new URLRequest("piano/"i+"mp3");
var pianoMP3_+i:Sound=new Sound();
pianoMP3_+i.load(pianoMP3Req+i);
}
I am not sure if your strings concatenate correctly (if they correctly produce the valid filename.)
Try like this:
var i:int;
for (i = 0; i < 5; i++) {
var request = pianoMP3 + "" + i;
request:URLRequest=new URLRequest("piano/" + i + ".mp3");
var temp = pianoMP3 + "" + i;
temp:Sound=new Sound();
temp.load(request);
}
for both the request and the mp3. I don't have an environment to test it at the monent.
I had a hard time trying to word my question properly, so i'm sorry if it seems confusing. Also i'm using the flixel library in flash builder. It may not be that important butcause probably anyone that knows a little more than me or even a little AS3 could probably see what i'm doing wrong.
Anyway, what i'm trying to do is basically create 10 instances of this square object I made. all I have to do is pass it an x an y coordinate to place it and it works. so ive tested if i just do:
var testsquare:Bgsq;
testsquare = new Bgsq(0,0);
add(testsquare);
it works fine and adds a square at 0,0 just like i told it to, but i want to add 10 of them then move the next one that's created 25 px to the right (because each square is 25px)
my problem is that I only ever see 1 square, like it's only making 1 instance of it still.
anyone possibly have an idea what I could be doing wrong?
var counter:int = 0;
var bgsqa:Array = new Array;
for (var ibgs:int = 0; ibgs < 10; ibgs++)
{
bgsqa[counter] = new Bgsq(0,0);
bgsqa[counter].x += 25;
add(bgsqa[counter]);
counter++;
}
There's a lot you're doing wrong here.
First off, you're using a pseudo-iterator (counter) to access array elements through a loop instead of, well, using the iterator (ibgs).
Second, I don't see anything in the array (bgsqa) you're iterating through. It's no wonder you're having problems. Here's what you should do.
var bgsqa:Array = [];
for(var i:int=0;i<10;i++)
{
var bgsq:Bgsq = new Bgsq(i * 25, 0);
add(bgsq);
bgsqa.push(bgsq);
}
That should probably do it if your post is accurate.
for (var ibgs:int = 0; ibgs < 10; ibgs++)
{
bgsqa[counter] = new Bgsq(0,0);
bgsqa[counter].x = counter * 25;
add(bgsqa[counter]);
counter++;
}
They start at 0, so applying += is simply adding 25 to 0. This should do the trick.