Highlighted

Game where player collects objects - hitobjecttest issue

New Here ,
Apr 02, 2019

Copy link to clipboard

Copied

I am creating a game where the user clicks along the bottom of the screen to move a character. I have a function that generates books at random x points along the stage:

function bringTheBooks(booksnumber) {

i = booksnumber - 1

if (i >= 0) {

var fallingBook = new lib.book();

fallingBook.x = random(0, stageWidth);

//fallingBook.y = stageHeight;

bookField.addChild(fallingBook);

fallingBook.gotoAndPlay("Falling");

setTimeout(function () {

bringTheBooks(i);

}, 3000);

} else {

endLevel();

}

}

I am desperately trying to add functionality so that when the character hits one of these books, the book disappears. I have tried to use hittestobject but the system does not recognize my character as an object. I have now resorted to trying to loop through the book array to see if any of them are intersecting with the character's x and y value. This is not what I want because ideally, when a book hits any point on the character, the book should disappear. I could not figure out how to make that work though and now this function below won't work either. It seems like the x any y points of the character and of the books are not to scale, so books get deleted even when they look like they are far from the character. Does anyone have any ideas for how I can incorporate the functionality I want? Is it impossible with Adobe Animate? I have spent so much time trying to make this work and I am worried that there may be no solution

createjs.Ticker.on("tick", pickUpBook);

function pickUpBook() {

for (var j = 0; j < bookField.getNumChildren(); j++) {

var currentchild = bookField.getChildAt(j);

var charx = Math.round(root.character.x) / scaleFactor;

var chary = Math.round(root.character.y) / scaleFactor;

if (currentchild.hitTest(charx, chary)){

bookField.removeChildAt(j);

}

}

}

Views

59

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Game where player collects objects - hitobjecttest issue

New Here ,
Apr 02, 2019

Copy link to clipboard

Copied

I am creating a game where the user clicks along the bottom of the screen to move a character. I have a function that generates books at random x points along the stage:

function bringTheBooks(booksnumber) {

i = booksnumber - 1

if (i >= 0) {

var fallingBook = new lib.book();

fallingBook.x = random(0, stageWidth);

//fallingBook.y = stageHeight;

bookField.addChild(fallingBook);

fallingBook.gotoAndPlay("Falling");

setTimeout(function () {

bringTheBooks(i);

}, 3000);

} else {

endLevel();

}

}

I am desperately trying to add functionality so that when the character hits one of these books, the book disappears. I have tried to use hittestobject but the system does not recognize my character as an object. I have now resorted to trying to loop through the book array to see if any of them are intersecting with the character's x and y value. This is not what I want because ideally, when a book hits any point on the character, the book should disappear. I could not figure out how to make that work though and now this function below won't work either. It seems like the x any y points of the character and of the books are not to scale, so books get deleted even when they look like they are far from the character. Does anyone have any ideas for how I can incorporate the functionality I want? Is it impossible with Adobe Animate? I have spent so much time trying to make this work and I am worried that there may be no solution

createjs.Ticker.on("tick", pickUpBook);

function pickUpBook() {

for (var j = 0; j < bookField.getNumChildren(); j++) {

var currentchild = bookField.getChildAt(j);

var charx = Math.round(root.character.x) / scaleFactor;

var chary = Math.round(root.character.y) / scaleFactor;

if (currentchild.hitTest(charx, chary)){

bookField.removeChildAt(j);

}

}

}

Views

60

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Apr 02, 2019 0
katmayer LATEST
New Here ,
Apr 02, 2019

Copy link to clipboard

Copied

Is there even a way I could have code for the user to click the different book objects and have them disappear? This is another option if the hittestobject is not going to work, but I haven't been able to figure out how to code that backup plan either.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 02, 2019 0