# Recent posts by LearningAS3 on Kongregate

 Thanks for that. You are awesome. Its taking some time for my fuzzy brain to register what is going on in that code… I will check on that later… Done. Good luck. :) Like the topic says, the following code is based on top down grid style collision detection and movement… So I have this ball which is moving around tiles… let me just show you all the code first then I will mention the problem:- ``` if (isReady && isMovin) { //trace("speed is " + speed); speedX = Math.cos(angle) * speed * flagX; speedY = Math.sin(angle) * speed * flagY; x_pos = this.x + speedX; y_pos = this.y + speedY; left = Math.floor((x_pos - 9) / tile_size); bottom = Math.floor((y_pos + 9) / tile_size); top = Math.floor((y_pos - 9) / tile_size); right = Math.floor((x_pos + 9) / tile_size); top_left = level[top][left]; bottom_left = level[bottom][left]; top_right = level[top][right]; bottom_right = level[bottom][right]; //no wall encountered carry on if (top_left != 1 && bottom_left != 1 && top_right != 1 && bottom_right != 1) { this.x += speedX; this.y += speedY; } else //code for checking collision with walls { if (top_left == 1 && bottom_left == 1 && speedX < 0) { this.x = (left + 1) * tile_size + 10; //this.y += speedY; speed -= 0.2; flagX = -flagX; } else if (top_right == 1 && bottom_right == 1 && speedX > 0) { this.x = (right - 1) * tile_size + 8; //this.y += speedY; speed -= 0.2; flagX = -flagX; } else { this.x += speedX; } if (top_right == 1 && top_left == 1 && speedY < 0) { this.y = (top + 1) * tile_size + 9; //this.x += speedX; speed -= 0.2; flagY = -flagY; } else if (bottom_left == 1 && bottom_right == 1 && speedY > 0) { this.y = (bottom - 1) * tile_size + 10; //this.x += speedX; speed -= 0.2; flagY = -flagY; } else { this.y += speedY; } } speed -= fric; if (speed <= 0) isMovin = false; } ``` As you all can see I am only testing the top(similar for bottom, right and left) collision only if both the variables are blocked like top_right and top_left both are equal to one then only I will change the direction. The problem comes when only one of the variable is one (that is maybe top_right is 1 and top_left is not) then the ball goes straight or movement becomes jittery cause I havent added the code for checking with single variable. My issue is that for any given variable for eg if top_right is one then the ball can be colliding either on bottom of that tile or on the left hand side of that tile, I am not able to diagnose that properly… Here is pic of that issue:- So the ball can be moving in direction 1 and it hits left hand side of tile and direction 2 hits bottom of the tile… how to diagnose which direction it hits. Any help will be appreciated. Adobe? Yea. You can just check for y in in original constructor itself. It will only require an if statement :) Any difference between this `(possiblyy == null) ? result = pixelAtIndex(indexorx) : result = pixelAtCoords(indexorx, possiblyy);` and this `result = (possiblyy == null) ? pixelAtIndex(indexorx) : pixelAtCoords(indexorx, possiblyy);` or `result = possiblyy ? pixelAtCoords(indexorx, possiblyy) : pixelAtIndex(indexorx);` @skyboy I sure hope you didnt reach 6k post just by telling people to use “EDIT POST” thingi… :p Actually I thought that all post should entertain a different purpose (I mean what content they have) rather I should have thought about one person one post thing otherwise spam scenario. :( I will bear this in mind though. Also I know about function calls overhead because I was stupid enough to make enterframe listener on each of the objects and bam wasnt even getting 12fps. :) :D learnt my lesson that time itself. Oh jeez I can code on timeline… damn why the heck I didnt knew this before. Err. Is there a button or something to access the code that can be put on timeline? Edit:- nvm I found it. Awesome stuff this. I always like constructive fights. Anyways I wanted to share how I work. I usually take on a function or a class at a time. Finish it completely, stress test if its works as it should. Then go about optimizing it to its fullest extend. Stress test again. Repeat if some bugs otherwise once a function or class is made it can be later used in code anywhere with a simple line. :) I dont usually even look at the code of class which is already finished. Maybe one last time after everything is coded or if something has to be changed behavior-wise. Wow. Something new to learn. Thanks for the replies. Oh yeah now I think of it function usually produce overhead, silly of me to think function can be faster than a conditional. Awesome. More time to kill… Oh lol. Didnt mean to call them loops. Just too many conditionals… Well they say save now to reap later (Or something), I am just trying to code efficiently and hopefully in long run this will benefit me. Aren’t static function calls faster than normal function calls? Oh naice… :) Currently there are few cases which needs variables to be set at max of two numbers or min of two numbers. I didnt want to go through if else loops to set the variables. So I set them up with ?: for eg. `maxx = this.x > player.x?this.x:player.x;` This works fine. But just now I thought I could also use Math.max or Math.min for the same. But I dunno which function is faster. Or is there any difference at all. So I was going through this forum, some of the posts are extremely informative. It would help if all of the community participants can point out their favorite ones. Maybe you have bookmarked some special ones. Please share them here. My personal fave so far is cool programmable effects and tip of the day It took me more than 2 hours to read through to page 7 and I see there are 486 page in all. Ok I just ran some test, I have an input text field on stage and nothing else… Arial Black 114 Glyphs output file size (swf) 12.8KB Webdings 95 Glyphs output file size (swf) 23.3 KB Franklin Gothic Medium 114 Glyphs output file size (swf) 13.4 KB And yes I deleted the other fonts before embedding the next one. @Draco doesnt it matter on the size of fonts and details in it?? So for every font, no matter whatever details it have, if I enabled all the options like “upper case, lower case, numerals, and all 52 punctuation glyphs”, it will only occupy ~11KB? Oh wow, didnt think about adding hats. Thanks for the tip simplegoogly. Thanks everyone for reading. I have got 3 collabs now. I am hoping to see some good returns from them. Will post again as soon as these are over for more collabs. Off to building my portfolio a little bulkier. :) Haha. Well I have a good mentor. Anyways as for the problem above. What I did was to check the “size report” in front of each symbol you will see three columns:- shape bytes, text bytes and actionscript bytes. I just looked into those movieclips which had some bytes in “text bytes” field and found my “not embedded” font in 3rd movieclip. There are only 6 movieclips using fonts… hope this helps someone…. Y no adobe informs us of the movieclip which needs to have font embedded. Spend about 1000 bucks and the thing doesnt even inform about this small thing. :( Just gets one wondering what other kind of frustrations one will get in future. Thanks for the reply DrYoshiyahu. (I like that name, are you a doctor in real life?) Thing is I already have selected two fonts “Slyfaen” and “Comic” and dont want to embed another one. It occupies space. :( Ok I just generated the file size report and it seems I am getting Times New Roman font which is not embedded. I dont want to embed this, I want to change the font to already embedded one. how do I find the movieclip which contains this text field…. So my partner was working on the builds and he created (or changed) some movieclip and added fonts (or changed). He doesnt remember which. And now I am getting “Fonts should be embedded for any text that may be edited at runtime, other than text with the “Use Device Fonts” setting. Use the Text > Font Embedding command to embed fonts." everytime in the output window. Is there any quick and painless way of searching which movieclip it is coming from? Or checking through each and every movieclip is the only option?