• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

Co-ordinates

przemek

New member
Joined
Sep 18, 2017
Messages
62
Hi, I would like to ask you how do i get co-ordinates from my game. What I want to do is have a menu with buildings and place them where my mouse is. So what I planned to do is move the cursor, press right mouse button, gets co-ords from the mouse cursor and say DrawImage farm cursor co-ords. How should i do that?





Also, i tried to draw a character in a specific pixel (lets say 300 by 300), however when I launched it, I couldnt move the character because on what i suspect is, I took out x, y. So I got another DrawImage character with x and y and what I ended up with is 2 same sprites, one in 300,300 and other at the top right corner which I can move. How do i make a sprite appear on special pixel and being able to move it?

Tried to use example from this: https://www.cerberus-x.com/community/cxDocs/Modules_mojo.graphics.html#DrawImage


Code:
Strict

Import mojo




Class CGame Extends App
'timer
    Field lastTick:Int
    Field secs:Int
    Field mins:Int
    Field hrs:Int
    Field dys:Int
 
  'resources
    Field wood:Float
     Field loopedtimeforwood:Int
    
'character
    Field x:Float
    Field y:Float
     Field character:Image
     Field p1:CGame
    

   
   
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    Method OnCreate:Int()
        SetUpdateRate(0)
        lastTick = Millisecs()
        loopedtimeforwood = 0
        wood = 0
       
        SetDeviceWindow(1280,960,0)
       
   
       
        'character
        character = LoadImage("character.png")
        SetUpdateRate 60
       
       
       
        Return 0
       
    End Method
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
    Method OnUpdate:Int()
        Local tick:Int = Millisecs()
        If tick>=(lastTick+1000)
            lastTick = tick
            secs += 1
            loopedtimeforwood+=1
        Endif
        If secs > 59 Then
            secs = 0
            mins +=1
            If mins > 59 Then
                mins = 0
                hrs +=1
                If hrs > 23 Then
                    hrs = 0
                    dys += 1
                Endif
            Endif
        Endif
       
       If loopedtimeforwood >= 20
               wood+=1
               If KeyDown (KEY_A) Then wood+=1
           loopedtimeforwood =0
        End
       
       
       If KeyDown (KEY_LEFT) Then x = x - 4
       If KeyDown (KEY_RIGHT) Then x = x + 4
       If KeyDown (KEY_UP) Then y = y-4
       If KeyDown (KEY_DOWN) Then y = y +4
       'keydown means keep moving until key is down where keyhit is do a thing until
        Return 0
    End Method
    Method OnRender:Int()
       
        Cls 124, 256, 0
        DrawText("Mins: "+secs, 200, 200)
        DrawText("Min: "+mins, 570, 10)
        DrawText("Hour: "+hrs, 510, 10)
        DrawText("Day: "+dys, 460, 10)''''''''''''''''
        DrawText("Wood: "+wood, 400, 80)
       
       
       
        DrawImage character, 300, 300
        DrawImage character, x, y
        Return 0
       
    End Method
   

   
End Class


Function Main:Int()
    New CGame()

   
       Return 0
End Function
 
The functions you care about are MouseX:Float(), MouseY:Float(), MouseHit:Int( button ), and MouseDown:Int( button ).

MouseX and MouseY tell you where the mouse is (relative to the top left of your window). MouseHit tells you how many times the mouse button - MOUSE_LEFT, MOUSE_RIGHT or MOUSE_MIDDLE - was pressed since the last update. And MouseDown tells you whether a button is being pressed right now.

You can use MouseHit or MouseDown (or both!) depending on what sort of interface you want. MouseHit is enough if you want to click on an object to select it, then click somewhere else to place it. If you want to drag it around the screen with the mouse you'll need MouseDown.

 
So if I would want to put something in x,y I could make some variables that take the current mouse position using Mousex and MouseY
and tell the object place at x = variable name y = variable name?
 
Exactly: if you want to make a sprite move with the mouse, just set its position to the values of XMouse and YMouse on every update.
 
Back
Top Bottom