artheads's Recent Forum Activity

  • Why the hell does the array shuffle interfere with only one line but not the entire index (column)?

    Tagged:

  • What a mess there is now with these layers... It used to be much more convenient.

    Is it possible to add copy/paste for layers, so that we don't have to redo the whole system built from multiple layers/sublayers just because we need to remove it from the original layout?

  • Thanks DiegoM, oh... so I can just delete those extra sublayers with indexes -1, ok. But I still don't understand why editing global layers on any layout where they are is not allowed? It seems logical or I missed something?

  • Bump!

  • Hi all! Just opened my current project today and found something weird with my global layers (two extra phantom layers have appeared):

    What is this actually? Never seen this before...

    Another question is - I just renamed another global layer, and now I need to rename it on a-a-all 40 layouts... Don't you think it is also weird stuff?

  • It would be cool if the debug panel could be pinned to the left or right edge of the screen, like in browser dev tools, rather than always being pinned to the bottom. I think many mobile developers would agree. Would you?

  • Yes, known problem with fonts as dop2000 said. Use vertical alignment - Top, it helps in most cases.

  • So, the Separating Axis Theorem (SAT)...

    Hmm... interesting! Many thanks R0J0hound!

  • I don’t understand the question to have a rectangle instead of a square.

    Hi R0J0hound, thanks for your reply and contribution to the community of course!

    I managed to break all ties with the layout size, but I can't realize how to do the same spatial grid but not for circles or squares, but for rectangle sprites instead, which can change their angle during the gameplay? Now my rectangle sprites have like an "invisible field" on its longer sides that pushing out other similar sprites even before collision, but I'd like to keep it within the sprite rectangle. Is my explanation clear enough?

    const SIZE = 144, radius = 144;
    let grid = [];
    let objs = runtime.objects.sprite.getAllInstances();
    
    function calculateDistance(obj1, obj2) {
     return Math.sqrt((obj2.x - obj1.x) ** 2 + (obj2.y - obj1.y) ** 2);
    }
    
    function applyForce(obj1, obj2, dist) {
     let separation = Math.max(0, radius - dist);
     if (separation > 0) {
     let ang = Math.atan2(obj2.y - obj1.y, obj2.x - obj1.x);
     let force = separation / 12.5;
     obj1.offsetPosition(-force * Math.cos(ang), -force * Math.sin(ang));
     obj2.offsetPosition(force * Math.cos(ang), force * Math.sin(ang));
     }
    }
    
    globalThis.spatialGrid = function() {
     objs = runtime.objects.sprite.getAllInstances();
    
     for (let i = 0; i < objs.length; i++) {
     for (let j = i + 1; j < objs.length; j++) {
     let obj1 = objs[i];
     let obj2 = objs[j];
     let dist = calculateDistance(obj1, obj2);
     applyForce(obj1, obj2, dist);
     }
     }
    };
    
  • Hi everyone, I can't reply in the old post made by R0J0hound with a great example

    So, the question is what if I have a rectangle object instead of square, and can we avoid relying on layout size or its angle and work just with the necessary sprite?

    The code from this example:

    	const SIZE=150, radius=150, layoutW=runtime.layout.width, layoutH=runtime.layout.height,
    	 COUNT=Math.ceil(layoutW/SIZE)*Math.ceil(layoutH/SIZE);
    let grid=[];
    for(let i=0; i<COUNT; i++) 
    	grid.push([]); //init
    function hash(x,y){
    	return ((Math.floor(x/SIZE) + Math.floor(y/SIZE)*Math.ceil(layoutW/SIZE))%COUNT+COUNT)%COUNT;
    }
    function add2grid(obj,i){
    	if(grid[i].length==0 || grid[i][grid[i].length-1]!==obj) 
    		grid[i].push(obj);
    }
    globalThis.spatialGrid=function(){
    	for(let i=0; i<COUNT; i++) 
    		grid[i].length=0; //clear
    	let objs = runtime.objects.sprite.getAllInstances();
    	for(let i=0; i<objs.length; i++){
    		let obj = objs[i];
    		add2grid(obj, hash(obj.x-radius/2, obj.y-radius/2));
    		add2grid(obj, hash(obj.x+radius/2, obj.y-radius/2));
    		add2grid(obj, hash(obj.x-radius/2, obj.y+radius/2));
    		add2grid(obj, hash(obj.x+radius/2, obj.y+radius/2));
    	}
    	for(let i=0; i<objs.length; i++){
    		let obj1 = objs[i], h=hash(obj1.x, obj1.y);
    		for(let j=0; j<grid[h].length; j++){
    			let obj2 = grid[h][j];
    			if(obj1===obj2) {
    				grid[h][j]=null;
    				continue;
    			}
    			if(obj2===null) 
    				continue;
    			let dist=Math.sqrt((obj2.x-obj1.x)**2+(obj2.y-obj1.y)**2);
    			dist=Math.max(0, radius-dist)/10;
    			//dist=(radius*(Math.max(0, radius-dist)/radius)**0.5)/5;
    			//dist=radius/(dist/dist/10;
    			if(dist>0){
    				let ang=Math.atan2(obj2.y-obj1.y, obj2.x-obj1.x);
    				obj1.offsetPosition(-dist*Math.cos(ang), -dist*Math.sin(ang));
    				obj2.offsetPosition(dist*Math.cos(ang), dist*Math.sin(ang));
    			}
    		}
    	}
    };
    
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Also, you can put all events of this layout in a group, then deactivate it when leaving the layout, and activate when back.

artheads's avatar

artheads

Member since 1 Aug, 2015

Twitter
artheads has 40 followers

Connect with artheads

Trophy Case

  • 9-Year Club
  • Forum Contributor Made 100 posts in the forums
  • x4
    Popular Game One of your games has over 1,000 players
  • x3
    Famous Game One of your games has over 10,000 players
  • Viral Game One of your games has over 100,000 players
  • Regular Visitor Visited Construct.net 7 days in a row
  • Steady Visitor Visited Construct.net 30 days in a row
  • RTFM Read the fabulous manual
  • Email Verified

Progress

17/44
How to earn trophies