This demo shows how to create physical bodies, apply forces to them, set transformations like scale, color
It uses collision detection via the PhysicsJS Engine and Howler.js for sound






// insert your global variables here object world object renderer number width number height number count object pingo object bend object cast object fly number step=0 // this method is called on scene start // if you have multiples files per scene, only one of this method is allowed method void OnInit () { log("launching new scene") count=0 width=1000 app.setLogicalWidth(width) height=app.getLogicalHeight() renderer=app.createRenderer() world=app.createWorld() world.addRenderer(renderer) world.setBounds(0, 0, width, height) world.addBehavior("body-impulse-response") world.addBehavior("constant-acceleration") world.addBehavior("collision-detection") object back=renderer.createSprite("background","icecubes-demo/banquise(1)_1600x1000.png",width/2,height/2,1600,1000) for i = 0 to 6 for j = 1 to 3 object cube=world.createBody("rectangle", "box","dynamic", "icecubes-demo/glacon_200x200.png", 650+j*62,height-(15+i*51),0,0,60,60) cube.setBounciness(0.75) cube.setSlideness(0.75) cube.setMass(2) next next bend=renderer.createAnimation(["icecubes-demo/Sprite_pingouin_ramasse.png_1.png","icecubes-demo/Sprite_pingouin_ramasse.png_3.png","icecubes-demo/Sprite_pingouin_ramasse.png_4.png","icecubes-demo/Sprite_pingouin_ramasse.png_2.png","icecubes-demo/Sprite_pingouin_ramasse.png_0.png"]) cast=renderer.createAnimation(["icecubes-demo/Sprite_pingouin_lancement.png_0.png","icecubes-demo/Sprite_pingouin_lancement.png_1.png","icecubes-demo/Sprite_pingouin_lancement.png_2.png","icecubes-demo/Sprite_pingouin_lancement.png_3.png"]) fly=renderer.createAnimation(["icecubes-demo/Sprite_pingouin_batement.png_0.png","icecubes-demo/Sprite_pingouin_batement.png_1.png","icecubes-demo/Sprite_pingouin_batement.png_2.png","icecubes-demo/Sprite_pingouin_batement.png_3.png"]) pingo=world.createAnimatedBody("rectangle", "pingo", "dynamic", bend, 150,height-61,0,0,70,120) pingo.setBounciness(0.75) pingo.setSlideness(0.6) pingo.setMass(3) } // this method is called each frame // if you have multiples files per scene, only one of this method is allowed method void OnUpdate () { count=count+1 if count>1000 app.loadScene("Ice") endif if step=0 and count>50 log("animate step 0") pingo.setAnimationLoop(false) pingo.setAnimationSpeed(0.08) pingo.playAnimation() step=1 count=0 endif if step=1 and count>50 pingo.setAnimation(cast,70,120) pingo.playAnimation() step=2 endif if step=2 if pingo.getCurrentFrame()=2 object ball=world.createBody("circle", "bullet", "dynamic", "icecubes-demo/boule_de_neige_42x42.png", 140,height-46,4,-0.25-rnd(0.5),30,30) ball.setMass(4) step=3 endif endif } // this method is called each time a collision is detected, for bodies you registered collision detection behavior // if you have multiples files per scene, only one of this method is allowed method void OnCollision(list collisions) { foreach object c in collisions if (c.bodyA.label="pingo" and (c.bodyB.label="box" or c.bodyB.label="ball")) or (c.bodyB.label="pingo" and (c.bodyA.label="box" or c.bodyA.label="ball")) pingo.setAnimation(fly,70,120) pingo.setAnimationSpeed(0.16) pingo.setAnimationLoop(true) pingo.playAnimation() endif next }
Sprite Basic Compiler, a Pix Arts Venture    Privacy Policy    Contact    Change Log

THANKS

Goodboy Digital, Well Caffeinated, Goldfire Sudios, Fluidbyte, Rex Van Der Spuy, Anthony, Thomas