artheads's Forum Posts

  • 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));
    			}
    		}
    	}
    };
    
  • Also, you can put all events of this layout in a group, then deactivate it when leaving the layout, and activate when back.

  • should not exceed 4096 pixels.

    Yeah, I understand this. Thank you, bro!

  • Not sure, but I think this is not possible, because even your loading screen its images and scripts or events needs to be loaded at first.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks dop2000!

    the full image will be pretty big (2048x3072px).

    As I understood he says: "The size of the object in the layout doesn't matter" and then later he probably means sprite: "cannot be over 4096 pixels". Don't you think?

    So don't add more than 6-8 tiles to the tilemap.

    Do you mean add 6-8 to the tileset or to the tilemap object on the layout?