rbndr [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=69738 Jittery sprites with my camera zoom function <img style="margin-bottom:16px" border=0 src="/media/69738/PICO-8_4.gif" alt="" /> <p>i've tried to make a function that scales and offsets sprites to simulate a camera zoom. The way it works is by pressing z and x will increase or decrease the pixel size, each object has x and y values, and sx and sy which are scaled and offset based on the pixel size value.</p> <p>in this demo the black cats are based on the x and y values, the blue cats are based on the sx and sy values. The scaled blue cats movement is very jittery, especially when accelerating and decelerating, the non scaled black cats are not jittery.</p> <p>So I think the controls are changing the x and y values correctly, and there isn't a problem with the camera being out of sync, it must be a problem with getting the sx and sy values from my x and y ones. Looking at it, it is like they are not moving in unison, instead the movement is rippling through the objects one by one.</p> <p>it is the scale_x and scale_y functions that create the sx and sy, and these functions are called in the 'move' function</p> <p>Any idea what I am doing wrong?</p> <p>thanks</p> <p> <table><tr><td> <a href="/bbs/?pid=150459#p"> <img src="/bbs/thumbs/pico8_camerazoom-0.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=150459#p"> camerazoom</a><br><br> by <a href="/bbs/?uid=69738"> rbndr</a> <br><br><br> <a href="/bbs/?pid=150459#p"> [Click to Play]</a> </td></tr></table> </p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>--function to scale and offset --the x co-ordinate when pixel --size is changed function scale_x (x) local newx=x*pixels local offset=newx-x local x1=x+newx-pixels*28 local zero=camera_x+64-pixels*(camera_x+64) x=(zero+newx) return(x) end --function to scale and offset --the y co-ordinate when pixel --size is changed function scale_y (y) local newy=y*pixels local offset=newy-y local y1=y+newy-pixels*28 local zero=camera_y+64-pixels*(camera_y+64) y=(zero+newy) return(y) end --moves all objects --calls boxhit function that --checks colisions function move(obj) if obj==pl then if btn(0) then obj.dx-=obj.acc --move left amount obj.flp=true sound=true end if btn(1) then obj.dx+=obj.acc --move right amount obj.flp=false sound=true end if btn(2) then obj.dy-=obj.acc --move up amount when jump sound=true end if btn(3) then obj.dy+=obj.acc --move up amount when jump sound=true end end --reduce vertical movement by gravity each update --obj.dy+=obj.gravity --reduce horizontal movement by friction obj.dx*=obj.friction obj.dy*=obj.friction --limit max speed in all directions obj.dy=mid(-obj.max_dy,obj.dy,obj.max_dy) obj.dx=mid(-obj.max_dx,obj.dx,obj.max_dx) --new locations if movement applied obj.newx=obj.x+obj.dx obj.newy=obj.y+obj.dy --check whether new locations collide with other objects --will adjust newx/newy positions to not overlap collided object for v in all(things) do if obj!=v then --check collision of new vertical -- box_hit(obj,v,&quot;y&quot;) obj.y=obj.newy obj.sy=(scale_y(obj.y-obj.h)) end end for v in all(things) do if v!=obj then --check collision of new horizontal -- box_hit(obj,v,&quot;x&quot;) obj.x=obj.newx obj.sx=(scale_x(obj.x-obj.w)) end end end function animate(obj) obj.s+=(abs(obj.dx)/3) if obj.s&gt;4 then obj.s=0 end if obj.dx&gt;0 then obj.flp=false elseif obj.dx&lt;0 then obj.flp=true end end function _init() camera_x=0 camera_y=0 --used as camera zoom pixels=1 --create table for objects things={} --make objects function make_thing(x,y ,w,h,clr,g,f,s) thing={ x = x,-- horizontal position y = y,-- vertical position w = w,-- width h = h,-- height dx = 0,-- horizontal movement dy = 0,-- vertical movement sx = x,--scaled/offset to draw sy = y,--scaled/offset to draw max_dx=2, -- max horizontal speed max_dy=2, -- max vertical speed acc=0.5, -- acceleration boost=6, -- boost when jump colour=clr, gravity=g, friction=f, s=s, flp=true } --add object to things table add(things,thing) return thing end --make player pl=make_thing(64,64,4,4,1,0.3, 0.95,64) --make some npcs for i=1,16 do make_thing(flr(64+cos(i/16)*25), 64+(sin(i/16)*25),4,4,i,0.3,1, 64) end end function _update() --move and animate for v in all(things) do move(v) animate(v) end --update camera camera_x=(pl.x-64) camera_y=(pl.y-64) --zoom in and out if btn(4) then pixels=pixels*1.1 end if btn(5) then pixels=pixels*0.9 end end function _draw() cls(7) camera(camera_x,camera_y) --draw sprites based on --sx and sy for v in all(things) do pal() sspr( flr(v.s)*8, 32, 8, 8, (v.x)-v.w, (v.y)-v.h, (v.w*2), (v.h*2), v.flp) pal(1,12) sspr( flr(v.s)*8, 32, 8, 8, (v.sx), (v.sy), ((v.w*2)*pixels), ((v.h*2)*pixels), v.flp) end --border rect(camera_x,camera_y,camera_x+127,camera_y+127,12) rect(camera_x+1,camera_y+1,camera_x+126,camera_y+126,13) end </pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> https://www.lexaloffle.com/bbs/?tid=142867 https://www.lexaloffle.com/bbs/?tid=142867 Wed, 26 Jun 2024 17:37:38 UTC low effort Celeste reskin <p> <table><tr><td> <a href="/bbs/?pid=145146#p"> <img src="/bbs/thumbs/pico8_rbndr-1.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=145146#p"> rbndr</a><br><br> by <a href="/bbs/?uid=69738"> rbndr</a> <br><br><br> <a href="/bbs/?pid=145146#p"> [Click to Play]</a> </td></tr></table> </p> <p>because there can never be enough Celeste mods, just changed the colour palette a bit and put in a self insert main character</p> <img style="margin-bottom:16px" border=0 src="/media/69738/robindra_0.png" alt="" /> <p>edit: fixed Maddy's name</p> https://www.lexaloffle.com/bbs/?tid=141282 https://www.lexaloffle.com/bbs/?tid=141282 Sat, 30 Mar 2024 17:53:27 UTC Help with non-map based collisions (getting stuck in corners) resolved <p>edit: latest version all objects check all objects and transfer momentum <table><tr><td> <a href="/bbs/?pid=145784#p"> <img src="/bbs/thumbs/pico8_nonmapbasedcollisions-2.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=145784#p"> nonmapbasedcollisions</a><br><br> by <a href="/bbs/?uid=69738"> rbndr</a> <br><br><br> <a href="/bbs/?pid=145784#p"> [Click to Play]</a> </td></tr></table> </p> <p>edit: forgot cart <table><tr><td> <a href="/bbs/?pid=141692#p"> <img src="/bbs/thumbs/pico8_nonmapbasedcollisions-0.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=141692#p"> nonmapbasedcollisions</a><br><br> by <a href="/bbs/?uid=69738"> rbndr</a> <br><br><br> <a href="/bbs/?pid=141692#p"> [Click to Play]</a> </td></tr></table> <br /> edit: solved! <table><tr><td> <a href="/bbs/?pid=141702#p"> <img src="/bbs/thumbs/pico8_nonmapbasedcollisions-1.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=141702#p"> nonmapbasedcollisions</a><br><br> by <a href="/bbs/?uid=69738"> rbndr</a> <br><br><br> <a href="/bbs/?pid=141702#p"> [Click to Play]</a> </td></tr></table> </p> <p>Can anyone advise me on where I am going wrong with my collission detection. I want to be able to use table objects instead of map tiles and flags as I want to be able to continuously scroll for wider than the map allows.</p> <p>I have pieced the following together from various sources (omitted the init and draw parts of the code, they just set up the various objects, but are in the carts code). It is using the method of checking whether the distance between the midpoints of two objects are smaller than the sum of the halves of the objects for both dimensions.</p> <p>When something affects the players movement, either buttons or gravity, the new Y and X positions are run through a collision detection which loops through every object, with y then x positions being checked within each loop, if a movement results in a collision the new X or Y position is adjusted to the max position that doesn't overlap and momentum is stopped. If there is no collision the new X and Y positions become the actual X and Y positions, if there is a collision the new X and Y positions are adjusted before becoming the actual X or Y positions.</p> <p>It almost works except for on corners where the player can get stuck and it judders. I've set up the cart so that it is easy to recreate the problem by falling/jumping along the vertical side of the squares while pressing left or right.</p> <p>I guess this is where within a loop both X and Y are adjusted putting them back to a position where it will keep happening while those directions are maintained. I assume I have to give priority to one axis but I can't figure out how to do this. I was wondering what the best approach is for this.</p> <p>Also is this approach on collisions generally ok or is there an easier or more efficient way, will it use up too much processing to do an entire map this way? I have tried to figure this out but most of the collision guides seem to be either map tiles and flags, or simple one pixel by pixel movement, or comparing only two objects at a time.</p> <p>thanks</p> <p>here</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre> --move objects function _update() move(pl) end --move and collission functions function move(obj) if (btn(0)) then obj.dx-=obj.acc --move left amount end if (btn(1)) then obj.dx+=obj.acc --move right amount end if (btnp(5)) then obj.dy-=obj.boost --move up amount when jump end --reduce vertical movement by gravity each update obj.dy+=gravity --reduce horizontal movement by friction obj.dx*=friction --limit max speed in all directions obj.dy=mid( -obj.max_dy, obj.dy, obj.max_dy) obj.dx=mid( -obj.max_dx, obj.dx, obj.max_dx) --new locations if movement applied obj.newx=obj.x+obj.dx obj.newy=obj.y+obj.dy --check whether new locations collide with other objects --will adjust newx/newy positions to not overlap collided object for v in all(things) do if v!=pl then --check collision of new vertical box_hit(obj,v,&quot;y&quot;) --check collision of new horizontal box_hit(obj,v,&quot;x&quot;) --apply new positions (adjusted to stop before collide) end end obj.y=obj.newy obj.x=obj.newx obj.y=mid(0,obj.y,120) obj.x=mid(0,obj.x,120) end function box_hit(obj,obj2,axis) --compares one object x/y/w/h to another --axis is which dimension of movement being checked --hitbox different depending on direction if axis==&quot;y&quot; then y1=obj.newy x1=obj.x elseif axis==&quot;x&quot; then y1=obj.y x1=obj.newx end w1=obj.w h1=obj.h x2=obj2.x y2=obj2.y w2=obj2.w h2=obj2.h --collision check method --if distance between midpoints greater than --the sum of the two box halves --distance mid points local xd=abs((x1+(w1/2)) -(x2+(w2/2))) --sum of box widths/2 local xs=w1*0.5+w2*0.5 --distance mid points local yd=abs((y1+(h1/2)) -(y2+(h2/2))) --distance mid points local ys=h1/2+h2/2 if xd&lt;xs and yd&lt;ys then --is a collission if axis==&quot;y&quot; then --kill vertical momentum obj.dy=0 if y1&lt;y2 then --if collide from above limit movement to last non collide point obj.newy=flr(y1-(ys-yd)) else --if collide from below limit to lowest point of 2nd object obj.newy=ceil(y2+h2) end else --kill horizontal momentum obj.dx=0 if x1&lt;x2 then --if colliding from left obj.newx=flr(x2-obj.w) else --if colliding from right obj.newx=ceil(x2+w2) end end end </pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> https://www.lexaloffle.com/bbs/?tid=140269 https://www.lexaloffle.com/bbs/?tid=140269 Tue, 20 Feb 2024 19:36:46 UTC agametopassthetime <p>this is my first attempt at doing anything in pico 8, or any game. there isn't much game play yet though.</p> <p>updated idle animation in v2</p> <p> <table><tr><td> <a href="/bbs/?pid=136700#p"> <img src="/bbs/thumbs/pico8_agametopassthetime-2.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=136700#p"> a game to pass the time</a><br><br> by <a href="/bbs/?uid=69738"> rbndr</a> <br><br><br> <a href="/bbs/?pid=136700#p"> [Click to Play]</a> </td></tr></table> </p> https://www.lexaloffle.com/bbs/?tid=54847 https://www.lexaloffle.com/bbs/?tid=54847 Tue, 31 Oct 2023 20:25:54 UTC