I using this jsp library for graph generating. And I want write function, that show me onli error messages at graph time (actual graph min <-> actual graph max)..
Functions is:
i = 4700;
while (i < 4800) {
if(i<ui.values[0]){
$("."+i).hide();
}
else if(i>ui.values[1]){
$("."+i).hide();
}
else {
$("."+i).show();
}
i++;
}
But I dont know, where can I take globalGraph maximum value and global graph min value.
So, anybody with expirience in this jsp library? :)
Okey, solved.
In Rickshaw.Graph.RangeSlider.js -> slide: function( event, ui ):
i = ui.values[0]-100;
while (i < (ui.values[1] + 100)) {
if(i<ui.values[0]){
$("."+i).hide();
}
else if(i>ui.values[1]){
$("."+i).hide();
}
else {
$("."+i).show();
}
i++;
}
Related
I'm not entirely sure whats going on here. When you shoot all three bullets and the last one leaves the screen the "asteroids" array also resets.
EDIT:
Is it because the bullets array ends up being spliced to an undefined when they all leave the screen? Or will it return the base empty array? Even then, it doesn't explain why the asteroids array is voided as well. I also found that the asteroids don't even start falling unless I've shot at least once.
Code on p5web editor
What is it causing this to happen? This is the first time I've coded something this large, code amount wise, but I made sure to use obvious variable names for the most part.
The problem is in your asteroids class:
check(bullets) {
for (let i = 0; i < bullets.length; i++) {
if (dist(bullets[i].x, bullets[i].y, this.pos.x, this.pos.y) < this.r) {
return false;
} else {
return true;
}
}
}
If there are no bullets to check, this function returns undefined implicitly, which is taken as falsey by the calling code, which promptly destroys the asteroid as if it had collided with a bullet.
Also, if there are bullets to check and the first one happens to not collide, the loop breaks prematurely with else { return true; }, possibly missing collisions.
Change it to:
check(bullets) {
for (let i = 0; i < bullets.length; i++) {
if (dist(bullets[i].x, bullets[i].y, this.pos.x, this.pos.y) < this.r) {
return false;
}
}
return true; // no collisions (or bullets.length === 0)
}
Having said this, the function name check is pretty unclear. I'd rename it as collidesWith(bullets) and invert the boolean--it makes more sense to say "true, yes, we did collide with a bullet" than "false, yes, we did collide with a bullet". We can also make use of the for ... of loop construct. This gives us:
collidesWith(bullets) {
for (const bullet of bullets) {
if (dist(bullet.x, bullet.y, this.pos.x, this.pos.y) < this.r) {
return true;
}
}
return false;
}
You could shorten this further to:
collidesWith(bullets) {
return bullets.some(e => dist(e.x, e.y, this.pos.x, this.pos.y) < this.r);
}
Similarly, I'd change bullet.check() to bullet.outOfBounds() or similar.
Another tip: iterate in reverse over any arrays you plan to slice the current element from:
for (let j = asteroids.length - 1; j >= 0; j--) {
// code that could call `.splice(j, 1)`
}
Otherwise, after splicing, your loop will skip an element and you might miss a collision.
A minor design point, but player.controls() seems strange--why should the player be responsible for listening for keypresses? I'd listen in the keyPressed() function and send the changes to update the player position from there. I'd also break up draw into smaller functions. But these are minor design decisions so the above is enough to get you rolling.
Here's a first revision for the draw function, adjusted to match the modified booleans:
function draw() {
background(0);
scene();
if (tick <= 0) {
if (asteroids.length < asteroidsLimit) {
asteroids.push(new Asteroid());
}
tick = 60;
}
for (let i = asteroids.length - 1; i >= 0; i--) {
if (asteroids[i].collidesWith(bullets)) {
asteroids.splice(i, 1);
}
else {
asteroids[i].update();
asteroids[i].display();
}
}
for (let i = bullets.length - 1; i >= 0; i--) {
if (bullets[i].outOfBounds()) {
bullets.splice(i, 1);
}
else {
bullets[i].update();
bullets[i].display();
}
}
image(ship, player.x, player.y);
player.controls();
tick--;
}
I need to change Array to Vector as it is being depracted in cocos2dx.
Earlier it was running but after deprecation its giving error.
As I am quite new to cocos2dx I am not able to resolve this issue.
Here is my code:
int BaseScene::generateRandom()
{
//int rn = arc4random()%6+1;
int rn = rand() % 6 + 1;
Array * balls = (Array*)this->getChildren();
Array * ballsTypeLeft = Array::create();
// if(balls->count() <= 7)
{
for (int j=0; j<balls->count(); j++)
{
Node * a = (Node*)balls->objectAtIndex(j);
if(a->getTag() >= Tag_Ball_Start)
{
Ball * currentBall = (Ball*)balls->objectAtIndex(j);
bool alreadyHas = false;
for(int k=0;k<ballsTypeLeft->count();k++)
{
if(strcmp(((String*)ballsTypeLeft->objectAtIndex(k))->getCString(), (String::createWithFormat("%d",currentBall->type))->getCString()) == 0)
{
alreadyHas = true;
}
}
if(alreadyHas)
{
}
else
{
ballsTypeLeft->addObject(String::createWithFormat("%d",currentBall->type));
}
}
}
}
// CCLog("%d",ballsTypeLeft->count());
if(ballsTypeLeft->count() <=2)
{
// int tmp = arc4random()%ballsTypeLeft->count();
int tmp = rand() % ballsTypeLeft->count();
return ((String*)ballsTypeLeft->objectAtIndex(tmp))->intValue();
}
return rn;
}
How can I make this method working?
Please convert this method using Vector.
Thanks
To change cocos2d::Array to cocos2d::Vector, you must first understand it. cocos2d::Vector is implemented to mimick std::vector. std::vector is part of the STL in c++. cocos2d::Vector is built specifically to handle cocos2d::Ref. Whenever you add a Ref type to Vector it automatically retained and then released on cleanup.
Now to change Array to Vector in your code:
Store children this way:
Vector <Node*> balls = this->getChildren();
Access ball at index i this way:
Ball* ball = (Ball*)balls.at (i);
Add elements to vector this way:
balls.pushBack (myNewBall);
EDIT -
From what I understand, you want to get a random ball from the scene/layer. You can perform this by simply returning the Ball object:
Ball* BaseScene::generateRandom()
{
Vector <Node*> nodeList = this->getChildren();
Vector <Ball*> ballList;
for (int i = 0; i<nodeList.size(); i++)
{
if (ball->getTag() >= Tag_Ball_Start)
{
Ball * ball = (Ball*)nodeList.at(i);
ballList.pushBack(ball);
}
}
if (ballList.size() > 0)
{
return ballList[rand() % ballList.size()];
}
return nullptr;
}
If there is no ball it will return NULL which you can check when you call the function. The code you have linked below seems to make use of Arrays outside the function. You need to make the changes to accommodate that. I suggest studying the documentation for Vector.
I have a 3 column display to mimick a kanban board. Each column does an ng-repeat on one $scope.list. I then filter each column to include the itmes I want. However now I want to be able drag an item from one column to another, and when dropping an item, perform a $http call to my rest api which will update that item.
I've looked at some tools like this - http://codef0rmer.github.io/angular-dragdrop/#/
But as far as I can tell this isn't any help to me as my data is all within one list.
The list that contains all the items is $scope.board and this it's JSON output.
{
"_id":"553b9fc4fee8d25ceeba6c92",
"boardAuthor":"553b9e64fee8d25ceeba6c91",
"title":"Board title",
"description":"Whatever",
"__v":0,
"boardTickits":[
{},
]
}
I thought one approach could be to split $scope.board into separate arrays but I can't seem to access the nested array.
for(i = 0; i < $scope.board.boardTickits.length; i++) {
if($scope.board.boardTickits.category == 1) {
$scope.todoCol = $scope.board.boardTickits[i];
} else if ($scope.board.boardTickits.category == 2) {
$scope.doingCol = $scope.board.boardTickits[i];
} else if($scope.board.boardTickits.category == 3) {
$scope.doneCol = $scope.board.boardTickits[i];
}
}
I get an error trying to get the length of the nested array.
If anybody provide some insight on accessing nested arrays that would be great, cheers!
Because you are doing .length of undefined object $scope.board.boardTickits. You need to change you for loop condition form $scope.board.boardTickits.length to $scope.board.length
for(i = 0; i < $scope.board.length - 1; i++) {
if($scope.board.boardTickits.category == 1) {
$scope.todoCol = $scope.board.boardTickits[i];
} else if ($scope.board.boardTickits.category == 2) {
$scope.doingCol = $scope.board.boardTickits[i];
} else if($scope.board.boardTickits.category == 3) {
$scope.doneCol = $scope.board.boardTickits[i];
}
}
So here im checking for when a bullet hits an enemy ship in my game. Im trying to check the type of enemy in the array by object name to do specific things for that enemy, code is below.
for (var i = bullets.length - 1; i >= 0; i--) {
for (var j = enemies.length - 1; j >= 0; j--) {
if (_bullets[i].hitTestObject(enemies[j])) {
if (enemies[j] == EnemyYellow) {
trace("do something");
}
stage.removeChild(enemies[j]);
stage.removeChild(bullets[i]);
bullets.splice(i, 1);
enemies.splice(j, 1);
return;
}
}
}
This is something like I thought would work, but I would appreciate if anyone could help me out as im not sure how to do it.
if (enemies[j] == EnemyYellow) {
trace("do something");
}
You can use the keyword is
if (enemies[j] is EnemyYellow) {
trace("do something");
}
You can also add a method getType to the Enemy class. This solution is not better for this particular case but may be useful in some other cases. For example, you can have enemies of the same class but returning different types.
if (enemies[j].getType() == EnemyType.ENEMY_YELLOW) // do something
I am trying to test the collisions between a bullet and an array of enemies in Actionscript 2. However it is not sensing a collision. This is the code in the bullet.
onClipEvent(load)
{
facing = _root.player.facing;
speed = 1;
i = 0;
}
onClipEvent(enterFrame)
{
if (this._name != "bullet")
{
this._x += facing * speed;
while (i < _root.enemyID)
{
if (Math.abs(this._x - _root.enemies[i]._x)<10)
{
trace("hit enemy");
}
i++;
}
}
}
The variable i looks like it is being set to 0 only on load. So it will be checking all the enemies on the first frame, but since i will now always be greater than enemyID, it will never go into the loop again.
Try setting i = 0; just before the while loop.